//
// BN_div_recp from 0xe1aa20 to 0xe1ac64 (580 bytes)
//
// 2 xrefs:
// > BN_mod_mul_reciprocal @ 0xe1acd4
// > ??> @ 0xa6548
//
// 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 BN_div_recp(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int32x2_t *a5)
{
_QWORD **v10; // x20
__int64 v11; // x23
signed int v12; // w0
int v13; // w1
signed int v14; // w26
unsigned __int64 *v15; // x20
__int64 v16; // x0
_BOOL4 is_zero; // w0
int v19; // w1
BN_CTX_start((unsigned __int64)a5);
v10 = (_QWORD **)BN_CTX_get(a5);
v11 = BN_CTX_get(a5);
if ( !a1 )
{
a1 = BN_CTX_get(a5);
if ( a2 )
goto LABEL_3;
LABEL_19:
a2 = BN_CTX_get(a5);
goto LABEL_3;
}
if ( !a2 )
goto LABEL_19;
LABEL_3:
if ( !v10 || !v11 || !a1 || !a2 )
goto LABEL_14;
if ( (BN_ucmp((__int64 *)a3, (__int64 *)a4) & 0x80000000) == 0 )
{
v12 = BN_num_bits(a3);
v13 = *(_DWORD *)(a4 + 52);
v14 = 2 * *(_DWORD *)(a4 + 48);
if ( v12 >= v14 )
v14 = v12;
if ( v13 != v14 )
{
v13 = BN_reciprocal(a4 + 24, a4, v14, a5);
*(_DWORD *)(a4 + 52) = v13;
}
if ( v13 != -1 )
{
if ( (unsigned int)BN_rshift((__int64)v10, a3, *(_DWORD *)(a4 + 48)) )
{
if ( (unsigned int)BN_mul(v11, v10, (_QWORD **)(a4 + 24), (__int64)a5) )
{
if ( (unsigned int)BN_rshift(a1, v11, v14 - *(_DWORD *)(a4 + 48)) )
{
*(_DWORD *)(a1 + 16) = 0;
if ( (unsigned int)BN_mul(v11, (_QWORD **)a4, (_QWORD **)a1, (__int64)a5) )
{
if ( (unsigned int)BN_usub((unsigned __int64 *)a2, (__int64 *)a3, v11) )
{
*(_DWORD *)(a2 + 16) = 0;
LODWORD(v15) = 4;
while ( 1 )
{
LODWORD(v15) = (_DWORD)v15 - 1;
if ( (BN_ucmp((__int64 *)a2, (__int64 *)a4) & 0x80000000) != 0 )
break;
if ( !(_DWORD)v15 )
{
ERR_put_error(3, 130, 101, (__int64)"crypto/bn/bn_recp.c", 154);
goto LABEL_15;
}
if ( !(unsigned int)BN_usub((unsigned __int64 *)a2, (__int64 *)a2, a4) )
goto LABEL_14;
if ( !(unsigned int)BN_add_word(a1, 1u) )
{
LODWORD(v15) = 0;
goto LABEL_15;
}
}
is_zero = BN_is_zero(a2);
v19 = 0;
if ( !is_zero )
v19 = *(_DWORD *)(a3 + 16);
*(_DWORD *)(a2 + 16) = v19;
LODWORD(v15) = 1;
*(_DWORD *)(a1 + 16) = *(_DWORD *)(a4 + 16) ^ *(_DWORD *)(a3 + 16);
goto LABEL_15;
}
}
}
}
}
}
LABEL_14:
LODWORD(v15) = 0;
LABEL_15:
v16 = (__int64)a5;
goto LABEL_16;
}
BN_set_word(a1, 0);
v15 = BN_copy((unsigned __int64 *)a2, a3);
v16 = (__int64)a5;
if ( v15 )
{
BN_CTX_end((__int64)a5);
return 1;
}
LABEL_16:
BN_CTX_end(v16);
return (unsigned int)v15;
}