//
// asn1_template_free from 0xd6e95c to 0xd6efd0 (1652 bytes)
//
// 32 xrefs:
// > sub_D6B828 @ 0xd6bd04
// > sub_D6B828 @ 0xd6bf44
// > sub_D6B828 @ 0xd6c02c
// > sub_D6B828 @ 0xd6c124
// > sub_D6B828 @ 0xd6c1fc
// > sub_D6C730 @ 0xd6c9a0
// > sub_D6C730 @ 0xd6cb34
// > sub_D6C730 @ 0xd6cc9c
// > sub_D6C730 @ 0xd6ccf0
// > sub_D6C730 @ 0xd6cdbc
// > ASN1_item_ex_d2i @ 0xd6d224
// > ASN1_item_ex_d2i @ 0xd6d3dc
// > ASN1_item_ex_d2i @ 0xd6d544
// > ASN1_item_ex_d2i @ 0xd6d598
// > ASN1_item_ex_d2i @ 0xd6d664
// > asn1_template_free @ 0xd6eab8
// > asn1_template_free @ 0xd6eb64
// > asn1_template_free @ 0xd6ecb8
// > asn1_template_free @ 0xd6ed38
// > asn1_template_free @ 0xd6eda0
// > asn1_template_free @ 0xd6eeb8
// > asn1_template_free @ 0xd6ef44
// > asn1_template_free @ 0xd6efc8
// > ASN1_item_free @ 0xd6f038
// > ASN1_item_free @ 0xd6f1a8
// > ASN1_item_free @ 0xd6f250
// > ASN1_item_free @ 0xd6f2e4
// > ASN1_item_ex_free @ 0xd6f430
// > ASN1_item_ex_free @ 0xd6f4d0
// > ASN1_item_ex_free @ 0xd6f554
// > ASN1_item_ex_free @ 0xd6f5e0
// > ??> @ 0x52c38
//
// 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_template_free(_QWORD *a1, __int64 *a2)
{
__int64 result; // x0
unsigned int v5; // s8
_QWORD *v6; // x22
int v7; // w20
bool v8; // cc
_QWORD *v9; // x0
__int64 v10; // x0
unsigned __int8 *v11; // x19
__int64 v12; // x3
unsigned int v13; // w4
__int64 v14; // x0
unsigned int (__fastcall *v15)(__int64, __int64 *, unsigned __int8 *, _QWORD); // x27
__int64 v16; // x21
__int64 v17; // x0
__int64 v18; // x25
__int64 field_ptr; // x0
__int64 v20; // x26
__int64 v21; // x1
void (__fastcall *v22)(__int64 *, unsigned __int8 *); // x2
int choice_selector; // w0
__int64 v24; // x3
unsigned __int8 *v25; // x19
__int64 v26; // x1
void (__fastcall *v27)(__int64, _QWORD *, unsigned __int8 *, _QWORD); // x23
__int64 v28; // x21
__int64 v29; // x0
_QWORD *v30; // x0
__int64 v31; // x1
__int64 (__fastcall *v32)(_QWORD *, unsigned __int8 *); // x2
int v33; // w0
__int64 v34; // x0
__int64 v35; // x20
__int64 v36; // x22
__int64 v37; // x0
__int64 v38; // x21
__int64 v39; // x0
int v40; // w0
__int64 v41; // x19
__int64 v42; // x0
__int64 v43; // x0
__int64 v44; // x20
__int64 v45; // x0
_QWORD *v46; // [xsp+80h] [xbp+80h] BYREF
__int64 v47; // [xsp+88h] [xbp+88h] BYREF
result = *a2;
v5 = *(_DWORD *)a2 & 0x1000;
if ( v5 )
{
v46 = a1;
if ( (result & 6) != 0 )
{
v6 = a1;
a1 = &v46;
goto LABEL_6;
}
v25 = (unsigned __int8 *)a2[4];
a1 = &v46;
v26 = *((_QWORD *)v25 + 4);
}
else
{
if ( (result & 6) != 0 )
{
v6 = (_QWORD *)*a1;
LABEL_6:
v7 = 0;
v8 = (int)OPENSSL_sk_num(v6) > 0;
v9 = v6;
if ( !v8 )
{
LABEL_20:
result = OPENSSL_sk_free(v9);
*a1 = 0;
return result;
}
while ( 1 )
{
v10 = OPENSSL_sk_value(v9, (unsigned int)v7);
v11 = (unsigned __int8 *)a2[4];
v47 = v10;
v12 = v10;
v13 = *v11;
v14 = *((_QWORD *)v11 + 4);
if ( v12 || !*v11 )
{
if ( v14 )
{
v15 = *(unsigned int (__fastcall **)(__int64, __int64 *, unsigned __int8 *, _QWORD))(v14 + 24);
if ( v15 )
{
switch ( *v11 )
{
case 0u:
v21 = *((_QWORD *)v11 + 2);
if ( !v21 )
goto LABEL_22;
asn1_template_free(&v47, v21);
++v7;
break;
case 1u:
case 6u:
if ( !(unsigned int)asn1_do_lock(&v47, 0xFFFFFFFFLL, v11) && v15(2, &v47, v11, 0) != 2 )
{
asn1_enc_free(&v47, v11);
v24 = *((_QWORD *)v11 + 3);
v16 = *((_QWORD *)v11 + 2) + 40 * v24;
if ( v24 > 0 )
{
v20 = 1;
do
{
v16 -= 40;
v17 = asn1_do_adb(&v47, v16, 0);
v18 = v17;
if ( v17 )
{
field_ptr = asn1_get_field_ptr(&v47, v17);
asn1_template_free(field_ptr, v18);
}
v8 = v20++ < *((_QWORD *)v11 + 3);
}
while ( v8 );
}
v15(3, &v47, v11, 0);
if ( !v5 )
CRYPTO_free(v47, "crypto/asn1/tasn_fre.c", 119);
}
goto LABEL_18;
case 2u:
if ( v15(2, &v47, v11, 0) == 2 )
goto LABEL_18;
choice_selector = asn1_get_choice_selector(&v47, v11);
if ( (choice_selector & 0x80000000) == 0 && choice_selector < *((_QWORD *)v11 + 3) )
{
v28 = *((_QWORD *)v11 + 2) + 40LL * choice_selector;
v29 = asn1_get_field_ptr(&v47, v28);
asn1_template_free(v29, v28);
}
v15(3, &v47, v11, 0);
if ( v5 )
goto LABEL_18;
++v7;
CRYPTO_free(v47, "crypto/asn1/tasn_fre.c", 79);
goto LABEL_19;
case 4u:
v22 = *(void (__fastcall **)(__int64 *, unsigned __int8 *))(v14 + 16);
if ( !v22 )
goto LABEL_18;
++v7;
v22(&v47, v11);
goto LABEL_19;
case 5u:
LABEL_22:
++v7;
asn1_primitive_free(&v47, (__int64)v11, v5);
break;
default:
goto LABEL_18;
}
goto LABEL_19;
}
if ( v13 <= 6 )
__asm { BR X1 }
}
else if ( v13 <= 6 )
{
__asm { BR X0 }
}
}
LABEL_18:
++v7;
LABEL_19:
v8 = v7 < (int)OPENSSL_sk_num(v6);
v9 = v6;
if ( !v8 )
goto LABEL_20;
}
}
v25 = (unsigned __int8 *)a2[4];
v26 = *((_QWORD *)v25 + 4);
if ( !a1 )
return result;
}
result = *v25;
if ( *v25 )
{
if ( !*a1 )
return result;
if ( v26 )
goto LABEL_45;
result = (unsigned int)(result - 1);
switch ( (int)result )
{
case 0:
case 5:
v27 = nullptr;
LABEL_79:
result = asn1_do_lock(a1, 0xFFFFFFFFLL, v25);
if ( !(_DWORD)result )
{
asn1_enc_free(a1, v25);
v43 = *((_QWORD *)v25 + 3);
v35 = *((_QWORD *)v25 + 2) + 40 * v43;
if ( v43 > 0 )
{
LABEL_67:
v36 = 1;
do
{
v35 -= 40;
v37 = asn1_do_adb(a1, v35, 0);
v38 = v37;
if ( v37 )
{
v39 = asn1_get_field_ptr(a1, v37);
asn1_template_free(v39, v38);
}
v8 = v36++ < *((_QWORD *)v25 + 3);
}
while ( v8 );
if ( v27 )
LABEL_72:
v27(3, a1, v25, 0);
}
result = v5;
if ( !v5 )
{
result = CRYPTO_free(*a1, "crypto/asn1/tasn_fre.c", 119);
*a1 = 0;
}
}
break;
case 1:
LABEL_75:
v40 = asn1_get_choice_selector(a1, v25);
if ( (v40 & 0x80000000) == 0 && v40 < *((_QWORD *)v25 + 3) )
{
v41 = *((_QWORD *)v25 + 2) + 40LL * v40;
v42 = asn1_get_field_ptr(a1, v41);
asn1_template_free(v42, v41);
}
LABEL_62:
result = v5;
if ( !v5 )
{
result = CRYPTO_free(*a1, "crypto/asn1/tasn_fre.c", 79);
*a1 = 0;
}
break;
case 4:
LABEL_51:
v30 = a1;
return asn1_primitive_free(v30, (__int64)v25, v5);
default:
return result;
}
}
else
{
if ( v26 )
{
LABEL_45:
v27 = *(void (__fastcall **)(__int64, _QWORD *, unsigned __int8 *, _QWORD))(v26 + 24);
if ( v27 )
{
switch ( *v25 )
{
case 0u:
goto LABEL_53;
case 1u:
case 6u:
result = asn1_do_lock(a1, 0xFFFFFFFFLL, v25);
if ( (_DWORD)result )
return result;
result = ((__int64 (__fastcall *)(__int64, _QWORD *, unsigned __int8 *, _QWORD))v27)(2, a1, v25, 0);
if ( (_DWORD)result == 2 )
return result;
asn1_enc_free(a1, v25);
v34 = *((_QWORD *)v25 + 3);
v35 = *((_QWORD *)v25 + 2) + 40 * v34;
if ( v34 > 0 )
goto LABEL_67;
goto LABEL_72;
case 2u:
result = ((__int64 (__fastcall *)(__int64, _QWORD *, unsigned __int8 *, _QWORD))v27)(2, a1, v25, 0);
if ( (_DWORD)result == 2 )
return result;
v33 = asn1_get_choice_selector(a1, v25);
if ( (v33 & 0x80000000) == 0 && v33 < *((_QWORD *)v25 + 3) )
{
v44 = *((_QWORD *)v25 + 2) + 40LL * v33;
v45 = asn1_get_field_ptr(a1, v44);
asn1_template_free(v45, v44);
}
v27(3, a1, v25, 0);
goto LABEL_62;
case 4u:
goto LABEL_55;
case 5u:
goto LABEL_51;
default:
return result;
}
}
switch ( *v25 )
{
case 0u:
goto LABEL_53;
case 1u:
case 6u:
goto LABEL_79;
case 2u:
goto LABEL_75;
case 4u:
LABEL_55:
v32 = *(__int64 (__fastcall **)(_QWORD *, unsigned __int8 *))(v26 + 16);
if ( v32 )
result = v32(a1, v25);
break;
case 5u:
goto LABEL_51;
default:
return result;
}
return result;
}
LABEL_53:
v31 = *((_QWORD *)v25 + 2);
v30 = a1;
if ( v31 )
return asn1_template_free(a1, v31);
else
return asn1_primitive_free(v30, (__int64)v25, v5);
}
return result;
}