//
// BN_mod_exp_simple from 0xa82f4c to 0xa83304 (952 bytes)
//
// 1 xrefs:
// > ??> @ 0x837ec
//
// 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:50 +0000
//
int __fastcall BN_mod_exp_simple(int **a1, int a2, int a3, int a4, int ***a5)
{
_DWORD *v7; // r5
int v9; // r9
int **v10; // r8
int **v11; // r0
bool v12; // zf
int v13; // r11
int v14; // r5
_BOOL4 is_zero; // r0
int v17; // r12
_DWORD *v18; // r5
int v19; // r10
int **v20; // r0
int v21; // r1
int v22; // r10
int v23; // r9
int v24; // r11
int v25; // r8
int is_bit_set; // r0
int v27; // r1
int v28; // r11
int v29; // [sp+0h] [bp-9Ch]
int v30; // [sp+Ch] [bp-90h]
int v31; // [sp+Ch] [bp-90h]
int v32; // [sp+10h] [bp-8Ch]
int v33; // [sp+10h] [bp-8Ch]
_DWORD *v34; // [sp+14h] [bp-88h]
int i; // [sp+14h] [bp-88h]
_DWORD v36[33]; // [sp+18h] [bp-84h] BYREF
v7 = (_DWORD *)a3;
if ( BN_get_flags(a3, 4) )
{
ERR_put_error(3, 126, 66, (int)"crypto/bn/bn_exp.c", 1256);
return 0;
}
else
{
v9 = BN_num_bits(v7);
if ( v9 )
{
BN_CTX_start((int)a5);
v10 = BN_CTX_get(a5);
v11 = BN_CTX_get(a5);
v12 = v11 == nullptr;
if ( v11 )
v12 = v10 == nullptr;
v13 = v12;
v36[0] = v11;
if ( v12 || (v30 = (int)v11, !BN_nnmod(v11, a2, a4, a5, v29)) )
{
LABEL_10:
v14 = 0;
LABEL_11:
BN_CTX_end(a5);
return v14;
}
is_zero = BN_is_zero(v30);
v17 = v30;
if ( is_zero )
{
BN_set_word(a1, v13);
v14 = 1;
goto LABEL_11;
}
if ( v9 >= 672 )
{
v32 = 32;
v31 = 6;
}
else if ( v9 > 239 )
{
v32 = 16;
v31 = 5;
}
else if ( v9 > 79 )
{
v32 = 8;
v31 = 4;
}
else
{
if ( v9 <= 23 )
{
v31 = 1;
LABEL_29:
if ( BN_set_word(a1, 1) )
{
v33 = v9 - 1;
v21 = v9 - 1;
for ( i = 1; ; i = 0 )
{
while ( !BN_is_bit_set(v7, v21) )
{
if ( !i && !BN_mod_mul(a1, a1, a1, a4, a5) )
goto LABEL_10;
if ( !v33 )
{
LABEL_55:
v14 = 1;
goto LABEL_11;
}
v21 = --v33;
}
if ( v31 == 1 )
{
v23 = 1;
v25 = 0;
}
else
{
v22 = v33 - 1;
if ( v33 - 1 < 0 )
{
v23 = 1;
v25 = 0;
}
else
{
v23 = 1;
v24 = 1;
v25 = 0;
do
{
is_bit_set = BN_is_bit_set(v7, v22);
v27 = v23 << (v24 - v25);
--v22;
if ( is_bit_set )
v25 = v24;
++v24;
if ( is_bit_set )
v23 = v27 | 1;
}
while ( v24 != v31 && v22 != -1 );
}
}
if ( !i )
break;
LABEL_47:
if ( !BN_mod_mul(a1, a1, v36[v23 >> 1], a4, a5) )
goto LABEL_10;
v33 += ~v25;
if ( v33 < 0 )
goto LABEL_55;
v21 = v33;
}
v28 = 0;
while ( 1 )
{
++v28;
if ( !BN_mod_mul(a1, a1, a1, a4, a5) )
break;
if ( v28 > v25 )
goto LABEL_47;
}
}
goto LABEL_10;
}
v32 = 4;
v31 = 3;
}
if ( BN_mod_mul(v10, v17, v17, a4, a5) )
{
v34 = v7;
v18 = v36;
v19 = 1;
while ( 1 )
{
v20 = BN_CTX_get(a5);
++v19;
v18[1] = v20;
++v18;
if ( !v20 || !BN_mod_mul(v20, *(v18 - 1), v10, a4, a5) )
break;
if ( v32 <= v19 )
{
v7 = v34;
goto LABEL_29;
}
}
}
goto LABEL_10;
}
if ( BN_is_one(a4) )
{
BN_set_word(a1, 0);
return 1;
}
else
{
return BN_set_word(a1, 1);
}
}
}