//
// BN_bn2dec from 0x7d756c to 0x7d7788 (540 bytes)
//
// 4 xrefs:
// > OBJ_obj2txt @ 0x81cab8
// > i2s_ASN1_ENUMERATED @ 0x85cf50
// > i2s_ASN1_INTEGER @ 0x85cfc8
// > ??> @ 0x5fedc
//
// 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
//
_BYTE *__fastcall BN_bn2dec(_DWORD *a1)
{
int v2; // r0
int v3; // r4
int v4; // r10
int v5; // r7
int v6; // r9
int v7; // r0
bool v8; // zf
_BYTE *v9; // r8
int v10; // r6
int v12; // r0
int *v13; // r5
_BYTE *v14; // r4
int v15; // r0
int v16; // r10
int *v17; // r5
int v19; // t1
v2 = BN_num_bits(a1);
v3 = 3 * v2 / 10 + 3 * v2 / 1000;
v4 = v3 + 2;
v5 = (v3 + 2) / 9 + 1;
v6 = CRYPTO_malloc(4 * v5, "crypto/bn/bn_print.c", 73);
v7 = CRYPTO_malloc(v3 + 5, "crypto/bn/bn_print.c", 74);
v8 = v7 == 0;
if ( v7 )
v8 = v6 == 0;
v9 = (_BYTE *)v7;
if ( v8 )
{
ERR_put_error(3, 104, 65, "crypto/bn/bn_print.c", 76);
v10 = 0;
LABEL_6:
CRYPTO_free(v6, "crypto/bn/bn_print.c", 118);
BN_free(v10);
CRYPTO_free(v9, "crypto/bn/bn_print.c", 122);
return nullptr;
}
v12 = BN_dup((int)a1);
v10 = v12;
if ( !v12 )
goto LABEL_6;
if ( BN_is_zero(v12) )
{
v9[1] = 0;
*v9 = 48;
}
else
{
v13 = (int *)v6;
if ( BN_is_negative(v10) )
{
*v9 = 45;
v14 = v9 + 1;
}
else
{
v14 = v9;
}
while ( !BN_is_zero(v10) )
{
if ( v5 > ((int)v13 - v6) >> 2 )
{
v15 = BN_div_word(v10, 1000000000);
*v13++ = v15;
if ( v15 != -1 )
continue;
}
goto LABEL_6;
}
v16 = v4 + 3;
BIO_snprintf(v14, v9 - v14 + v16, "%u", *(v13 - 1));
v17 = v13 - 1;
if ( *v14 )
{
while ( *++v14 )
;
}
while ( (int *)v6 != v17 )
{
v19 = *--v17;
BIO_snprintf(v14, v9 - v14 + v16, "%09u", v19);
if ( *v14 )
{
while ( *++v14 )
;
}
}
}
CRYPTO_free(v6, "crypto/bn/bn_print.c", 118);
BN_free(v10);
return v9;
}