//
// c2i_ASN1_INTEGER from 0x861884 to 0x861c34 (944 bytes)
//
// 2 xrefs:
// > sub_7C46C4 @ 0x7c4c2c
// > ??> @ 0x5e9dc
//
// 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
//
signed int *__fastcall c2i_ASN1_INTEGER(signed int **a1, char **a2, unsigned int a3)
{
bool v3; // zf
char *v6; // r2
char v8; // r3
unsigned int v9; // r1
int v10; // r3
char *v11; // r3
unsigned int v12; // r2
int v14; // r5
int v15; // r5
signed int *v16; // r4
char *v18; // r1
char v19; // r3
_BYTE *v20; // r0
int v21; // r5
int v22; // r3
int v23; // r2
char *v24; // r2
unsigned int v25; // r3
unsigned int v27; // r3
int v28; // r12
_BYTE *v29; // r0
char *v30; // r1
char v31; // r2
int v32; // t1
char *v33; // r1
char v34; // t1
signed int *v35; // r0
char *v36; // r2
_BYTE *v37; // r0
v3 = a3 == 0;
v6 = *a2;
if ( v3 )
{
ERR_put_error(13, 226, 222, (int)"crypto/asn1/a_int.c", 152);
return nullptr;
}
v8 = *v6;
if ( a3 == 1 )
goto LABEL_33;
v9 = (unsigned __int8)(v8 - 1);
v10 = v8 & 0x80;
if ( v9 <= 0xFD )
{
if ( v10 )
{
v14 = 0;
goto LABEL_12;
}
LABEL_15:
v15 = a3 - v10;
goto LABEL_16;
}
if ( v10 == (v6[1] & 0x80) )
{
ERR_put_error(13, 226, 221, (int)"crypto/asn1/a_int.c", 174);
return nullptr;
}
if ( !v10 )
{
v10 = 1;
goto LABEL_15;
}
v11 = v6;
v12 = 1;
do
{
if ( *++v11 )
break;
++v12;
}
while ( a3 > v12 );
if ( a3 == v12 )
{
LABEL_33:
v15 = a3;
goto LABEL_16;
}
v14 = 1;
LABEL_12:
v15 = a3 - v14;
LABEL_16:
if ( a1 && (v16 = *a1) != nullptr )
{
if ( !ASN1_STRING_set(*a1, nullptr, v15) )
{
ERR_put_error(13, 194, 65, (int)"crypto/asn1/a_int.c", 337);
LABEL_20:
if ( *a1 == v16 )
return nullptr;
LABEL_21:
ASN1_INTEGER_free((int)v16);
return nullptr;
}
}
else
{
v35 = (signed int *)ASN1_INTEGER_new();
v16 = v35;
if ( !v35 )
return nullptr;
v35[1] = 2;
if ( !ASN1_STRING_set(v35, nullptr, v15) )
{
ERR_put_error(13, 194, 65, (int)"crypto/asn1/a_int.c", 337);
if ( !a1 )
goto LABEL_21;
goto LABEL_20;
}
}
v18 = *a2;
v19 = **a2;
v20 = (_BYTE *)v16[2];
v21 = v19 & 0x80;
if ( a3 == 1 )
{
if ( v20 )
{
if ( (v19 & 0x80) == 0 )
{
*v20 = v19;
v18 = *a2;
goto LABEL_30;
}
*v20 = -v19;
v18 = *a2;
goto LABEL_55;
}
LABEL_64:
if ( !v21 )
goto LABEL_30;
goto LABEL_55;
}
if ( (unsigned __int8)(v19 - 1) <= 0xFDu )
{
if ( v19 < 0 )
{
v22 = 0;
goto LABEL_44;
}
v23 = 0;
LABEL_28:
if ( v20 )
{
memcpy(v20, &v18[v23], a3 - v23);
v18 = *a2;
}
goto LABEL_30;
}
if ( v21 == (v18[1] & 0x80) )
{
ERR_put_error(13, 226, 221, (int)"crypto/asn1/a_int.c", 174);
v18 = *a2;
goto LABEL_64;
}
if ( (v19 & 0x80) == 0 )
{
v23 = 1;
goto LABEL_28;
}
v24 = *a2;
v25 = 1;
do
{
if ( *++v24 )
break;
++v25;
}
while ( a3 > v25 );
if ( a3 != v25 )
{
v22 = 1;
LABEL_44:
v27 = a3 - v22;
if ( v20 )
{
v28 = (unsigned __int8)v18[a3 - 1];
v29 = &v20[v27];
v30 = &v18[a3 - 1];
if ( v28 )
{
*(v29 - 1) = -(char)v28;
v36 = v30 - 1;
v37 = v29 - 1;
}
else
{
while ( 1 )
{
*--v29 = v28;
v32 = (unsigned __int8)*--v30;
v31 = v32;
--v27;
if ( v32 )
break;
if ( !v27 )
{
*(v29 - 1) = 0;
LABEL_71:
OPENSSL_die("assertion failed: i != 0", "crypto/asn1/a_int.c", 212);
}
}
*(v29 - 1) = -v31;
v37 = v29 - 1;
v36 = v30 - 1;
if ( !v27 )
goto LABEL_71;
}
if ( v27 != 1 )
{
v33 = &v30[-v27];
do
{
v34 = *v36--;
*--v37 = ~v34;
}
while ( v36 != v33 );
}
v18 = *a2;
}
goto LABEL_55;
}
if ( v20 )
{
*v20 = 1;
memset(v20 + 1, 0, a3 - 1);
v18 = *a2;
}
LABEL_55:
v16[1] |= 0x100u;
LABEL_30:
*a2 = &v18[a3];
if ( a1 )
*a1 = v16;
return v16;
}