//
// sub_DB5EA8 from 0xdb5ea8 to 0xdb6018 (368 bytes)
//
// 2 xrefs:
// > CRYPTO_secure_malloc @ 0xdb6890
// > CRYPTO_secure_free @ 0xdb6af0
//
// 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
//
unsigned __int64 __fastcall sub_DB5EA8(unsigned __int64 a1)
{
unsigned __int64 v2; // x1
int v3; // w4
__int64 v4; // x6
unsigned __int64 result; // x0
unsigned __int64 v6; // x5
unsigned __int64 v7; // x5
if ( qword_125F118 > a1 || a1 >= qword_125F118 + qword_125F120 )
OPENSSL_die("assertion failed: WITHIN_ARENA(ptr)", "crypto/mem_sec.c", 574);
v2 = (a1 + qword_125F120 - qword_125F118) / qword_125F138;
v3 = qword_125F130 - 1;
if ( v2 )
{
v4 = qword_125F140;
if ( ((*(unsigned __int8 *)(qword_125F140 + (v2 >> 3)) >> (v2 & 7)) & 1) == 0 )
{
do
{
if ( (v2 & 1) != 0 )
OPENSSL_die("assertion failed: (bit & 1) == 0", "crypto/mem_sec.c", 259);
v2 >>= 1;
--v3;
}
while ( v2 && ((*(unsigned __int8 *)(qword_125F140 + (v2 >> 3)) >> (v2 & 7)) & 1) == 0 );
}
}
else
{
v4 = qword_125F140;
}
if ( v3 < 0 || qword_125F130 <= v3 )
OPENSSL_die("assertion failed: list >= 0 && list < sh.freelist_size", "crypto/mem_sec.c", 270);
result = (unsigned __int64)qword_125F120 >> v3;
v6 = a1 - qword_125F118;
if ( ((((unsigned __int64)qword_125F120 >> v3) - 1) & v6) != 0 )
sub_4DEEEC();
v7 = v6 / result + (1LL << v3);
if ( !v7 || v7 >= qword_125F150 )
OPENSSL_die("assertion failed: bit > 0 && bit < sh.bittable_size", "crypto/mem_sec.c", 273);
if ( (*(unsigned __int8 *)(v4 + (v7 >> 3)) & (unsigned int)(1LL << (v7 & 7))) == 0 )
OPENSSL_die("assertion failed: sh_testbit(ptr, list, sh.bittable)", "crypto/mem_sec.c", 578);
return result;
}