//
// CRYPTO_secure_free from 0xdb6aa0 to 0xdb7098 (1528 bytes)
//
// 9 xrefs:
// > BN_free @ 0xd7abb8
// > BN_clear_free @ 0xd7ac78
// > bn_expand2 @ 0xd7ae68
// > BUF_MEM_free @ 0xd7f8f4
// > BUF_MEM_grow @ 0xd7fa18
// > BUF_MEM_grow_clean @ 0xd7fb74
// > sub_D9B3AC @ 0xd9b3d0
// > sub_D9BBDC @ 0xd9bca8
// > ??> @ 0x9ffa8
//
// 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
//
void __fastcall CRYPTO_secure_free(unsigned __int64 a1, __int64 a2, __int64 a3)
{
unsigned __int64 v3; // x19
unsigned __int64 v4; // x21
unsigned __int64 v5; // x0
__int64 v6; // x3
__int64 v7; // x5
int v8; // w23
unsigned __int64 v9; // x4
__int64 v10; // x22
unsigned __int64 *v11; // x0
__int64 v12; // x22
unsigned __int64 v13; // x20
unsigned __int64 *v14; // x25
unsigned __int64 v15; // x5
unsigned __int64 v16; // x5
__int64 v17; // x0
unsigned __int64 v18; // x0
__int64 v19; // x2
__int64 v20; // x1
unsigned __int64 v21; // x2
__int64 v22; // x0
__int64 v23; // x0
unsigned __int64 v24; // x0
unsigned __int64 v25; // x2
__int64 v26; // x28
__int64 v27; // x26
unsigned __int64 v28; // x4
unsigned __int64 v29; // x3
unsigned __int64 v30; // x6
v3 = a1;
if ( a1 )
{
if ( CRYPTO_secure_allocated(a1) )
{
CRYPTO_THREAD_write_lock(qword_125F160);
v4 = sub_DB5EA8(v3);
OPENSSL_cleanse((_BYTE *)v3, v4);
qword_125F168 -= v4;
if ( v3 < qword_125F118 || v3 >= qword_125F118 + qword_125F120 )
OPENSSL_die("assertion failed: WITHIN_ARENA(ptr)", "crypto/mem_sec.c", 538);
v5 = (v3 + qword_125F120 - qword_125F118) / qword_125F138;
v6 = qword_125F130 - 1;
if ( v5 )
{
v7 = qword_125F140;
if ( ((*(unsigned __int8 *)(qword_125F140 + (v5 >> 3)) >> (v5 & 7)) & 1) == 0 )
{
do
{
if ( (v5 & 1) != 0 )
OPENSSL_die("assertion failed: (bit & 1) == 0", "crypto/mem_sec.c", 259);
v5 >>= 1;
--v6;
}
while ( v5 && ((*(unsigned __int8 *)(qword_125F140 + (v5 >> 3)) >> (v5 & 7)) & 1) == 0 );
}
}
else
{
v7 = qword_125F140;
}
v8 = v6;
if ( (v6 & 0x80000000) != 0 || qword_125F130 <= (int)v6 )
LABEL_66:
OPENSSL_die("assertion failed: list >= 0 && list < sh.freelist_size", "crypto/mem_sec.c", 270);
if ( ((((unsigned __int64)qword_125F120 >> v6) - 1) & (v3 - qword_125F118)) != 0 )
LABEL_69:
sub_4DEEEC();
v9 = (v3 - qword_125F118) / ((unsigned __int64)qword_125F120 >> v6) + (1LL << v6);
if ( !v9 || v9 >= qword_125F150 )
LABEL_67:
OPENSSL_die("assertion failed: bit > 0 && bit < sh.bittable_size", "crypto/mem_sec.c", 273);
if ( (*(unsigned __int8 *)(v7 + (v9 >> 3)) & (unsigned int)(1LL << (v9 & 7))) == 0 )
OPENSSL_die("assertion failed: sh_testbit(ptr, list, sh.bittable)", "crypto/mem_sec.c", 543);
v10 = 8 * v6;
sub_DB5DC0(v3, v6, qword_125F148);
v11 = (unsigned __int64 *)(qword_125F128 + v10);
v12 = v10 - 8;
sub_DB5CCC(v11, (unsigned __int64 *)v3);
while ( 1 )
{
v26 = 1LL << v8;
v27 = qword_125F118;
v28 = (unsigned __int64)qword_125F120 >> v8;
v29 = (v3 - qword_125F118) / ((unsigned __int64)qword_125F120 >> v8) + (1LL << v8);
v30 = (v29 ^ 1) >> 3;
if ( ((*(unsigned __int8 *)(qword_125F140 + v30) >> ((v29 ^ 1) & 7)) & 1) == 0 )
break;
if ( ((*(unsigned __int8 *)(qword_125F148 + v30) >> ((v29 ^ 1) & 7)) & 1) != 0 )
break;
v13 = ((v29 ^ 1) & (v26 - 1)) * v28;
v14 = (unsigned __int64 *)(qword_125F118 + v13);
if ( !(qword_125F118 + v13) )
break;
v15 = (v13 / v28 + v26) ^ 1;
if ( ((*(unsigned __int8 *)(qword_125F140 + (v15 >> 3)) >> (v15 & 7)) & 1) != 0 )
{
if ( ((*(unsigned __int8 *)(qword_125F148 + (v15 >> 3)) >> (v15 & 7)) & 1) != 0 )
v16 = (*(unsigned __int8 *)(qword_125F148 + v30) >> ((v29 ^ 1) & 7)) & 1LL;
else
v16 = qword_125F118 + (v15 & (v26 - 1)) * v28;
}
else
{
v16 = (*(unsigned __int8 *)(qword_125F140 + (v15 >> 3)) >> (v15 & 7)) & 1LL;
}
if ( v3 != v16 )
OPENSSL_die("assertion failed: ptr == sh_find_my_buddy(buddy, list)", "crypto/mem_sec.c", 549);
if ( !v3 )
OPENSSL_die("assertion failed: ptr != NULL", "crypto/mem_sec.c", 550);
if ( v8 < 0 || v8 >= qword_125F130 )
goto LABEL_66;
if ( ((v28 - 1) & (v3 - qword_125F118)) != 0 )
goto LABEL_69;
if ( !v29 || qword_125F150 <= v29 )
goto LABEL_67;
if ( (*(unsigned __int8 *)(qword_125F148 + (v29 >> 3)) & (unsigned int)(1LL << (v29 & 7))) != 0 )
OPENSSL_die("assertion failed: !sh_testbit(ptr, list, sh.bitmalloc)", "crypto/mem_sec.c", 551);
sub_DB5DC0(v3, v8, qword_125F140);
v17 = *(_QWORD *)v3;
if ( *(_QWORD *)v3 )
*(_QWORD *)(v17 + 8) = *(_QWORD *)(v3 + 8);
**(_QWORD **)(v3 + 8) = v17;
if ( *(_QWORD *)v3 )
{
v18 = *(_QWORD *)(*(_QWORD *)v3 + 8LL);
if ( v18 < qword_125F128 || (v19 = qword_125F130, v18 >= qword_125F128 + 8 * qword_125F130) )
{
if ( v18 < qword_125F118 || v18 >= qword_125F118 + qword_125F120 )
goto LABEL_70;
v19 = qword_125F130;
}
v20 = qword_125F148;
}
else
{
v20 = qword_125F148;
v19 = qword_125F130;
}
if ( v8 >= v19 )
goto LABEL_66;
if ( ((((unsigned __int64)qword_125F120 >> v8) - 1) & (v3 - qword_125F118)) != 0 )
goto LABEL_69;
v21 = (v3 - qword_125F118) / ((unsigned __int64)qword_125F120 >> v8) + v26;
if ( !v21 || v21 >= qword_125F150 )
goto LABEL_67;
if ( (*(unsigned __int8 *)(v20 + (v21 >> 3)) & (unsigned int)(1LL << (v21 & 7))) != 0 )
OPENSSL_die("assertion failed: !sh_testbit(ptr, list, sh.bitmalloc)", "crypto/mem_sec.c", 554);
sub_DB5DC0(v27 + v13, v8, qword_125F140);
v22 = *(_QWORD *)(v27 + v13);
if ( v22 )
*(_QWORD *)(v22 + 8) = v14[1];
*(_QWORD *)v14[1] = v22;
v23 = *(_QWORD *)(v27 + v13);
if ( v23 )
{
v24 = *(_QWORD *)(v23 + 8);
if ( (v24 < qword_125F128 || v24 >= qword_125F128 + 8 * qword_125F130)
&& (v24 < qword_125F118 || v24 >= qword_125F118 + qword_125F120) )
{
LABEL_70:
sub_4DEF0C();
}
}
--v8;
if ( (unsigned __int64)v14 > v3 )
v14 = (unsigned __int64 *)v3;
if ( v8 < 0 || qword_125F130 <= v8 )
goto LABEL_66;
if ( (((unsigned __int64)v14 - qword_125F118) & (((unsigned __int64)qword_125F120 >> v8) - 1)) != 0 )
goto LABEL_69;
v25 = ((unsigned __int64)v14 - qword_125F118) / ((unsigned __int64)qword_125F120 >> v8) + (1LL << v8);
if ( !v25 || v25 >= qword_125F150 )
goto LABEL_67;
if ( (*(unsigned __int8 *)(qword_125F148 + (v25 >> 3)) & (unsigned int)(1LL << (v25 & 7))) != 0 )
OPENSSL_die("assertion failed: !sh_testbit(ptr, list, sh.bitmalloc)", "crypto/mem_sec.c", 563);
sub_DB5BE4((__int64)v14, v8, qword_125F140);
sub_DB5CCC((unsigned __int64 *)(qword_125F128 + v12), v14);
v3 = *(_QWORD *)(qword_125F128 + v12);
v12 -= 8;
if ( (unsigned __int64 *)v3 != v14 )
OPENSSL_die("assertion failed: sh.freelist[list] == ptr", "crypto/mem_sec.c", 566);
}
CRYPTO_THREAD_unlock(qword_125F160);
}
else
{
CRYPTO_free((void *)v3, a2, a3);
}
}
}