//
// ASN1_item_ex_i2d from 0x7c7aec to 0x7c7f1c (1072 bytes)
//
// 17 xrefs:
// > ASN1_item_ndef_i2d @ 0x7c7f58
// > ASN1_item_ndef_i2d @ 0x7c7f78
// > ASN1_item_ndef_i2d @ 0x7c7fbc
// > sub_7C7FD0 @ 0x7c80c4
// > sub_7C7FD0 @ 0x7c8104
// > sub_7C7FD0 @ 0x7c8164
// > sub_7C7FD0 @ 0x7c8234
// > sub_7C7FD0 @ 0x7c82d4
// > sub_7C7FD0 @ 0x7c8414
// > ASN1_item_i2d @ 0x7c8594
// > ASN1_item_i2d @ 0x7c85b4
// > ASN1_item_i2d @ 0x7c85f8
// > sub_849870 @ 0x849bd8
// > sub_849870 @ 0x849c6c
// > sub_849CC8 @ 0x849dd0
// > sub_849CC8 @ 0x849e0c
// > ??> @ 0x5eacc
//
// 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 ASN1_item_ex_i2d(size_t **a1, int *a2, unsigned __int8 *a3, int a4, int a5)
{
int v6; // r2
int v10; // r3
int (__fastcall *v11)(int, size_t **, unsigned __int8 *, _DWORD); // r6
int result; // r0
int choice_selector; // r0
int v14; // r3
int v15; // r0
int v16; // r5
int v17; // r7
int v18; // r0
bool v19; // cc
int v20; // r0
int v21; // r3
int v22; // r0
int field_ptr; // r0
int v24; // r1
int v25; // r0
bool v26; // zf
int v27; // r7
int v28; // r5
int v29; // r9
int v30; // r0
int v31; // r0
int v32; // [sp+Ch] [bp-18h]
int v33; // [sp+10h] [bp-14h]
int v34; // [sp+1Ch] [bp-8h] BYREF
v6 = *a3;
v10 = *((_DWORD *)a3 + 4);
if ( !v6 )
{
if ( !v10 || *(_DWORD *)(v10 + 16) )
{
LABEL_8:
if ( *((_DWORD *)a3 + 2) )
return sub_7C7FD0(a1);
else
return sub_7C76B4(a1, a2, a3, a4, a5);
}
goto LABEL_14;
}
if ( !*a1 )
return 0;
if ( !v10 || (v11 = *(int (__fastcall **)(int, size_t **, unsigned __int8 *, _DWORD))(v10 + 16)) == nullptr )
{
LABEL_14:
switch ( v6 )
{
case 0:
goto LABEL_8;
case 1:
v11 = nullptr;
v33 = 1;
goto LABEL_21;
case 2:
choice_selector = asn1_get_choice_selector(a1, a3);
if ( choice_selector < 0 || choice_selector >= *((_DWORD *)a3 + 3) )
return 0;
LABEL_44:
field_ptr = asn1_get_field_ptr(a1, *((_DWORD *)a3 + 2) + 20 * choice_selector);
return sub_7C7FD0(field_ptr);
case 4:
return (*(int (__fastcall **)(size_t **, int *, unsigned __int8 *, int, int))(v10 + 20))(a1, a2, a3, a4, a5);
case 5:
return sub_7C76B4(a1, a2, a3, -1, a5);
case 6:
v11 = nullptr;
LABEL_17:
if ( (a5 & 0x800) != 0 )
v14 = 2;
else
v14 = 1;
v33 = v14;
LABEL_21:
v15 = asn1_enc_restore(&v34, a2, a1, a3);
v32 = v15;
if ( v15 < 0 )
return 0;
if ( v15 )
return v34;
v34 = 0;
if ( a4 == -1 )
{
a4 = 16;
LOBYTE(a5) = a5 & 0x3F;
}
if ( v11 && !v11(6, a1, a3, 0) )
return 0;
v16 = *((_DWORD *)a3 + 2);
if ( *((int *)a3 + 3) <= 0 )
{
v24 = v34;
}
else
{
v17 = v32;
do
{
v22 = asn1_do_adb(a1, v16, 1);
++v17;
v16 += 20;
if ( !v22 )
return 0;
v18 = asn1_get_field_ptr(a1, v22);
result = sub_7C7FD0(v18);
if ( result == -1 )
return result;
v19 = result <= 0x7FFFFFFF - v34;
v20 = result + v34;
if ( !v19 )
return -1;
v21 = *((_DWORD *)a3 + 3);
v34 = v20;
}
while ( v21 > v17 );
v24 = v20;
}
v25 = ASN1_object_size(v33, v24, a4);
v26 = v25 == -1;
if ( v25 != -1 )
v26 = a2 == nullptr;
v27 = v25;
if ( v26 )
return v27;
ASN1_put_object((_BYTE **)a2, v33, v34, a4, a5);
v28 = *((_DWORD *)a3 + 2);
if ( *((int *)a3 + 3) <= 0 )
goto LABEL_56;
v29 = v32;
break;
default:
return 0;
}
while ( 1 )
{
v31 = asn1_do_adb(a1, v28, 1);
++v29;
v28 += 20;
if ( !v31 )
break;
v30 = asn1_get_field_ptr(a1, v31);
sub_7C7FD0(v30);
if ( *((_DWORD *)a3 + 3) <= v29 )
{
LABEL_56:
if ( v33 == 2 )
ASN1_put_eoc(a2);
if ( !v11 || v11(7, a1, a3, 0) )
return v27;
return 0;
}
}
return 0;
}
switch ( v6 )
{
case 1:
v33 = 1;
goto LABEL_21;
case 2:
if ( !v11(6, a1, a3, 0) )
return 0;
choice_selector = asn1_get_choice_selector(a1, a3);
if ( choice_selector >= 0 && choice_selector < *((_DWORD *)a3 + 3) )
goto LABEL_44;
v11(7, a1, a3, 0);
result = 0;
break;
case 4:
return (*(int (__fastcall **)(size_t **, int *, unsigned __int8 *, int, int))(v10 + 20))(a1, a2, a3, a4, a5);
case 5:
return sub_7C76B4(a1, a2, a3, -1, a5);
case 6:
goto LABEL_17;
default:
return 0;
}
return result;
}