//
// BN_gcd from 0x86ef14 to 0x86f0e8 (468 bytes)
//
// 3 xrefs:
// > RSA_generate_key_ex @ 0x8bfa70
// > RSA_generate_key_ex @ 0x8bfbec
// > ??> @ 0x69d7c
//
// 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
//
bool __fastcall BN_gcd(int a1, int a2, int a3, int ***a4)
{
int *v8; // r5
int **v9; // r0
bool v10; // zf
int *v11; // r4
_BOOL4 v12; // r4
int v14; // r7
int *v15; // r3
int *v16; // r3
BN_CTX_start((int)a4);
v8 = (int *)BN_CTX_get(a4);
v9 = BN_CTX_get(a4);
v10 = v8 == nullptr;
if ( v8 )
v10 = v9 == nullptr;
v11 = (int *)v9;
if ( v10 || !BN_copy((int)v8, a2) || !BN_copy((int)v11, a3) )
goto LABEL_5;
v8[3] = 0;
v11[3] = 0;
v14 = 0;
if ( BN_cmp(v8, v11) < 0 )
{
v15 = v8;
v8 = v11;
v11 = v15;
}
while ( 2 )
{
if ( BN_is_zero((int)v11) )
{
LABEL_19:
if ( v14 && !BN_lshift(v8, v8, v14) )
break;
v12 = BN_copy(a1, (int)v8) != 0;
goto LABEL_6;
}
while ( 1 )
{
if ( BN_is_odd((int)v8) )
{
if ( BN_is_odd((int)v11) )
{
if ( !BN_sub(v8, v8, v11) || !BN_rshift1((int)v8, v8) )
goto LABEL_5;
}
else if ( !BN_rshift1((int)v11, v11) )
{
goto LABEL_5;
}
goto LABEL_16;
}
if ( !BN_is_odd((int)v11) )
break;
if ( !BN_rshift1((int)v8, v8) )
goto LABEL_5;
LABEL_16:
if ( BN_cmp(v8, v11) < 0 )
{
v16 = v8;
v8 = v11;
v11 = v16;
}
if ( BN_is_zero((int)v11) )
goto LABEL_19;
}
if ( BN_rshift1((int)v8, v8) && BN_rshift1((int)v11, v11) )
{
++v14;
continue;
}
break;
}
LABEL_5:
v12 = 0;
LABEL_6:
BN_CTX_end(a4);
return v12;
}