//
// ASN1_item_ex_free from 0xd6f2ec to 0xd6f5e8 (764 bytes)
//
// 7 xrefs:
// > sub_D6B828 @ 0xd6b914
// > sub_D6C730 @ 0xd6ceb0
// > ASN1_item_ex_d2i @ 0xd6d004
// > ASN1_item_ex_d2i @ 0xd6d844
// > sub_D6F800 @ 0xd6fa94
// > ASN1_item_ex_new @ 0xd6fed0
// > ??> @ 0xc3ca8
//
// 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
//
__int64 __fastcall ASN1_item_ex_free(__int64 result, unsigned __int8 *a2)
{
__int64 v2; // x2
_QWORD *v3; // x19
void (__fastcall *v5)(__int64, _QWORD *, unsigned __int8 *, _QWORD); // x24
int v6; // w0
_QWORD *v7; // x0
__int64 *v8; // x2
__int64 (__fastcall *v9)(_QWORD *, unsigned __int8 *); // x2
__int64 v10; // x0
__int64 v11; // x21
__int64 v12; // x23
__int64 v13; // x0
__int64 *v14; // x22
_QWORD *field_ptr; // x0
int choice_selector; // w0
__int64 *v18; // x20
_QWORD *v19; // x0
__int64 v20; // x0
__int64 *v21; // x21
_QWORD *v22; // x0
v2 = *((_QWORD *)a2 + 4);
if ( !result )
return result;
v3 = (_QWORD *)result;
result = *a2;
if ( *a2 )
{
if ( !*v3 )
return result;
if ( v2 )
goto LABEL_4;
result = (unsigned int)(result - 1);
switch ( (int)result )
{
case 0:
case 5:
v5 = nullptr;
LABEL_37:
result = asn1_do_lock(v3, 0xFFFFFFFFLL, a2);
if ( !(_DWORD)result )
{
asn1_enc_free(v3, a2);
v20 = *((_QWORD *)a2 + 3);
v11 = *((_QWORD *)a2 + 2) + 40 * v20;
if ( v20 > 0 )
{
LABEL_25:
v12 = 1;
do
{
v11 -= 40;
v13 = asn1_do_adb(v3, v11, 0);
v14 = (__int64 *)v13;
if ( v13 )
{
field_ptr = (_QWORD *)asn1_get_field_ptr(v3, v13);
asn1_template_free(field_ptr, v14);
}
}
while ( v12++ < *((_QWORD *)a2 + 3) );
if ( v5 )
LABEL_30:
v5(3, v3, a2, 0);
}
result = CRYPTO_free(*v3, "crypto/asn1/tasn_fre.c", 119);
*v3 = 0;
}
break;
case 1:
LABEL_32:
choice_selector = asn1_get_choice_selector(v3, a2);
if ( (choice_selector & 0x80000000) == 0 && choice_selector < *((_QWORD *)a2 + 3) )
{
v18 = (__int64 *)(*((_QWORD *)a2 + 2) + 40LL * choice_selector);
v19 = (_QWORD *)asn1_get_field_ptr(v3, v18);
asn1_template_free(v19, v18);
}
LABEL_11:
result = CRYPTO_free(*v3, "crypto/asn1/tasn_fre.c", 79);
*v3 = 0;
break;
case 4:
LABEL_16:
v7 = v3;
return asn1_primitive_free(v7, (__int64)a2, 0);
default:
return result;
}
}
else
{
if ( v2 )
{
LABEL_4:
v5 = *(void (__fastcall **)(__int64, _QWORD *, unsigned __int8 *, _QWORD))(v2 + 24);
if ( v5 )
{
switch ( *a2 )
{
case 0u:
goto LABEL_18;
case 1u:
case 6u:
result = asn1_do_lock(v3, 0xFFFFFFFFLL, a2);
if ( (_DWORD)result )
return result;
result = ((__int64 (__fastcall *)(__int64, _QWORD *, unsigned __int8 *, _QWORD))v5)(2, v3, a2, 0);
if ( (_DWORD)result == 2 )
return result;
asn1_enc_free(v3, a2);
v10 = *((_QWORD *)a2 + 3);
v11 = *((_QWORD *)a2 + 2) + 40 * v10;
if ( v10 > 0 )
goto LABEL_25;
goto LABEL_30;
case 2u:
result = ((__int64 (__fastcall *)(__int64, _QWORD *, unsigned __int8 *, _QWORD))v5)(2, v3, a2, 0);
if ( (_DWORD)result == 2 )
return result;
v6 = asn1_get_choice_selector(v3, a2);
if ( (v6 & 0x80000000) == 0 && v6 < *((_QWORD *)a2 + 3) )
{
v21 = (__int64 *)(*((_QWORD *)a2 + 2) + 40LL * v6);
v22 = (_QWORD *)asn1_get_field_ptr(v3, v21);
asn1_template_free(v22, v21);
}
v5(3, v3, a2, 0);
goto LABEL_11;
case 4u:
goto LABEL_20;
case 5u:
goto LABEL_16;
default:
return result;
}
}
switch ( *a2 )
{
case 0u:
goto LABEL_18;
case 1u:
case 6u:
goto LABEL_37;
case 2u:
goto LABEL_32;
case 4u:
LABEL_20:
v9 = *(__int64 (__fastcall **)(_QWORD *, unsigned __int8 *))(v2 + 16);
if ( v9 )
result = v9(v3, a2);
break;
case 5u:
goto LABEL_16;
default:
return result;
}
return result;
}
LABEL_18:
v8 = *((__int64 **)a2 + 2);
v7 = v3;
if ( v8 )
return asn1_template_free(v3, v8);
else
return asn1_primitive_free(v7, (__int64)a2, 0);
}
return result;
}