//
// BN_gcd from 0xa83b14 to 0xa83ce8 (468 bytes)
//
// 3 xrefs:
// > RSA_generate_key_ex @ 0xad4a70
// > RSA_generate_key_ex @ 0xad4bec
// > ??> @ 0x837fc
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:08:51 +0000
//
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;
}