//
// i2c_ASN1_INTEGER from 0x8616b0 to 0x861884 (468 bytes)
//
// 3 xrefs:
// > sub_7C76B4 @ 0x7c794c
// > sub_7C76B4 @ 0x7c79ac
// > ??> @ 0x5eabc
//
// This function is hookable on this platform!
//
// Using BromaIDA 8.0.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit ba9f177b at Thu Jul 16 22:52:06 2026 from https://github.com/geode-sdk/bindings
//
int __fastcall i2c_ASN1_INTEGER(size_t *a1, char **a2)
{
unsigned __int8 *v2; // r12
size_t v3; // r2
bool v4; // zf
int v6; // r3
size_t v7; // lr
unsigned int v8; // r1
int result; // r0
bool v10; // zf
char *v11; // r0
int v12; // r5
unsigned __int8 *v13; // r12
char v14; // r1
char *v15; // r0
unsigned __int8 *v16; // r3
char v17; // lr
int v18; // t1
bool v19; // zf
char *v20; // r0
unsigned __int8 *v21; // r1
char v22; // t1
char v24; // r1
char *v25; // r0
unsigned __int8 *v26; // r1
v2 = (unsigned __int8 *)a1[2];
v3 = *a1;
v4 = v2 == nullptr;
if ( v2 )
v4 = v3 == 0;
v6 = v4;
v7 = a1[1];
if ( v4 )
{
if ( a2 )
{
result = 1;
v12 = 1;
**a2 = 0;
goto LABEL_33;
}
return 1;
}
v8 = *v2;
result = *a1;
v10 = v8 == 0;
if ( !*v2 )
v10 = v3 == 1;
if ( v10 )
goto LABEL_11;
v6 = v7 & 0x100;
if ( v8 <= 0x7F || v6 != 0 )
{
if ( !v6 )
goto LABEL_11;
if ( v8 > 0x80 )
goto LABEL_45;
if ( v8 != 128 || v3 == 1 )
goto LABEL_11;
if ( v2[1] )
{
LABEL_45:
v24 = -1;
goto LABEL_28;
}
v26 = v2 + 2;
while ( v26 != &v2[v3] )
{
if ( *v26++ )
goto LABEL_45;
}
LABEL_11:
if ( !a2 )
return result;
v11 = *a2;
v12 = v3;
if ( !v6 )
goto LABEL_30;
goto LABEL_13;
}
v6 = 0;
v24 = 0;
LABEL_28:
v12 = v3 + 1;
if ( a2 )
{
v25 = *a2;
*v25 = v24;
v11 = v25 + 1;
if ( !v6 )
{
LABEL_30:
memcpy(v11, v2, v3);
result = v12;
LABEL_33:
*a2 += v12;
return result;
}
LABEL_13:
v13 = &v2[v3];
v14 = *(v13 - 1);
v15 = &v11[v3];
if ( !v14 )
{
if ( v3 == 1 )
{
LABEL_44:
*(v15 - 1) = 0;
result = v12;
goto LABEL_33;
}
v16 = v13 - 1;
v17 = *(v13 - 1);
while ( 1 )
{
*--v15 = v17;
v13 = v16;
v18 = *--v16;
v14 = v18;
--v3;
if ( v18 )
break;
if ( v3 == 1 )
goto LABEL_44;
}
}
v19 = v3 == 1;
*(v15 - 1) = -v14;
if ( v3 != 1 )
v3 = (size_t)&v13[-v3];
v20 = v15 - 1;
v21 = v13 - 1;
if ( !v19 )
{
do
{
v22 = *--v21;
*--v20 = ~v22;
}
while ( v21 != (unsigned __int8 *)v3 );
}
result = v12;
goto LABEL_33;
}
return v3 + 1;
}