//
// BN_div_word from 0x7d87ec to 0x7d88cc (224 bytes)
//
// 3 xrefs:
// > a2d_ASN1_OBJECT @ 0x7bd6f0
// > BN_bn2dec @ 0x7d76d4
// > ??> @ 0x5e1bc
//
// 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
//
int __fastcall BN_div_word(int *a1, unsigned int a2)
{
int result; // r0
int v5; // r0
char v6; // r8
int v7; // r3
int v8; // r7
unsigned int v9; // r4
int v10; // r2
int v11; // r5
unsigned int v12; // r3
int v13; // r9
int v14; // r0
if ( !a2 )
return -1;
if ( !a1[1] )
return 0;
v5 = BN_num_bits_word(a2);
v6 = 32 - v5;
if ( !BN_lshift(a1, a1, 32 - v5) )
return -1;
v7 = a1[1];
v8 = v7 - 1;
if ( v7 - 1 < 0 )
{
result = 0;
}
else
{
v9 = a2 << v6;
v10 = *a1;
v11 = 4 * v8;
v12 = 0;
do
{
v13 = *(_DWORD *)(v10 + v11);
v14 = bn_div_words(v12, v13, v9);
--v8;
v10 = *a1;
*(_DWORD *)(*a1 + v11) = v14;
v12 = v13 - v9 * v14;
v11 -= 4;
}
while ( v8 != -1 );
result = v12 >> v6;
v7 = a1[1];
}
if ( v7 > 0 && !*(_DWORD *)(*a1 + 4 * (v7 + 0x3FFFFFFF)) )
a1[1] = v7 - 1;
return result;
}