//
// sub_10945E0 from 0x10945e0 to 0x109497c (924 bytes)
//
// 1 xrefs:
// > BN_mod_exp_recp @ 0x1094b74
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// 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 13:17:23 +0000
//
unsigned __int64 *__fastcall sub_10945E0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, int32x2_t *a5)
{
int v10; // w21
__int64 v12; // x26
__int64 v13; // x0
__int64 v14; // x25
int v15; // w28
int v16; // w27
__int64 *v17; // x20
int v18; // w25
__int64 v19; // x0
__int64 v20; // x1
int v21; // w21
int i; // s8
int v23; // w25
int v24; // w27
int v25; // w26
int v26; // w20
int v27; // w1
int is_bit_set; // w0
char v29; // w1
int v30; // w20
unsigned int v31; // w20
_BYTE v32[64]; // [xsp+70h] [xbp+70h] BYREF
__int64 v33; // [xsp+B0h] [xbp+B0h]
char v34; // [xsp+B8h] [xbp+B8h] BYREF
v10 = BN_num_bits(a3);
if ( v10 )
{
BN_CTX_start((unsigned __int64)a5);
v12 = BN_CTX_get(a5);
v13 = BN_CTX_get(a5);
v33 = v13;
v14 = v13;
if ( !v12 || !v13 )
goto LABEL_39;
BN_RECP_CTX_init(v32);
if ( *(_DWORD *)(a4 + 16) )
{
if ( !BN_copy((unsigned __int64 *)v12, a4) )
goto LABEL_39;
*(_DWORD *)(v12 + 16) = 0;
if ( (int)BN_RECP_CTX_set(v32, v12, a5) <= 0 )
goto LABEL_39;
}
else if ( (int)BN_RECP_CTX_set(v32, a4, a5) <= 0 )
{
goto LABEL_39;
}
if ( !(unsigned int)BN_nnmod(v14, a2, a4, a5) )
goto LABEL_39;
if ( BN_is_zero(v14) )
{
v31 = 1;
BN_set_word(a1, 0);
goto LABEL_40;
}
if ( v10 > 671 )
{
v16 = 32;
v15 = 6;
}
else if ( v10 > 239 )
{
v16 = 16;
v15 = 5;
}
else
{
if ( v10 <= 79 )
{
v15 = 1;
if ( v10 > 23 )
{
v16 = 4;
v15 = 3;
goto LABEL_15;
}
LABEL_20:
if ( (unsigned int)BN_set_word(a1, 1) )
{
v21 = v10 - 1;
for ( i = 1; ; i = 0 )
{
while ( !(unsigned int)BN_is_bit_set(a3, v21) )
{
if ( i )
{
if ( !v21 )
goto LABEL_46;
}
else
{
if ( !(unsigned int)BN_mod_mul_reciprocal(a1, a1, a1, v32, a5) )
goto LABEL_39;
if ( !v21 )
{
LABEL_46:
v31 = 1;
goto LABEL_40;
}
}
--v21;
}
if ( v15 == 1 )
{
v24 = 1;
v25 = 0;
}
else
{
v23 = v21 - 1;
if ( v21 - 1 < 0 )
{
v24 = 1;
v25 = 0;
}
else
{
v24 = 1;
v25 = 0;
v26 = 1;
do
{
v27 = v23--;
is_bit_set = BN_is_bit_set(a3, v27);
v29 = v26 - v25;
if ( is_bit_set )
{
v25 = v26;
v24 = (v24 << v29) | 1;
}
++v26;
}
while ( v26 != v15 && v23 != -1 );
}
}
v30 = 0;
if ( !i )
break;
LABEL_33:
if ( !(unsigned int)BN_mod_mul_reciprocal(a1, a1, *(&v33 + (v24 >> 1)), v32, a5) )
goto LABEL_39;
v21 += ~v25;
if ( v21 < 0 )
goto LABEL_46;
}
while ( 1 )
{
++v30;
if ( !(unsigned int)BN_mod_mul_reciprocal(a1, a1, a1, v32, a5) )
break;
if ( v30 > v25 )
goto LABEL_33;
}
}
LABEL_39:
v31 = 0;
LABEL_40:
BN_CTX_end((__int64)a5);
BN_RECP_CTX_free(v32);
return (unsigned __int64 *)v31;
}
v16 = 8;
v15 = 4;
}
LABEL_15:
if ( (unsigned int)BN_mod_mul_reciprocal(v12, v14, v14, v32, a5) )
{
v17 = (__int64 *)&v34;
v18 = 1;
while ( 1 )
{
++v18;
v19 = BN_CTX_get(a5);
*v17 = v19;
if ( !v19 )
break;
v20 = *(v17++ - 1);
if ( !(unsigned int)BN_mod_mul_reciprocal(v19, v20, v12, v32, a5) )
break;
if ( v18 >= v16 )
goto LABEL_20;
}
}
goto LABEL_39;
}
if ( !(unsigned int)BN_is_one(a4) )
return BN_set_word(a1, 1);
BN_set_word(a1, 0);
return (_QWORD *)(dword_0 + 1);
}