//
// BN_exp from 0xe1667c to 0xe16828 (428 bytes)
//
// 1 xrefs:
// > ??> @ 0x3d218
//
// 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_exp(unsigned __int64 *a1, __int64 a2, __int64 a3, int32x2_t *a4)
{
unsigned __int64 *v8; // x24
unsigned __int64 *v9; // x0
__int64 **v10; // x22
unsigned int v11; // w19
int v13; // w25
int v14; // w19
int v15; // w0
int v16; // w1
if ( !(unsigned int)BN_get_flags(a3, 4u) )
{
BN_CTX_start((unsigned __int64)a4);
if ( a1 == (unsigned __int64 *)a3 || (v8 = a1, a1 == (unsigned __int64 *)a2) )
{
v8 = (unsigned __int64 *)BN_CTX_get(a4);
v9 = (unsigned __int64 *)BN_CTX_get(a4);
v10 = (__int64 **)v9;
if ( !v9 )
goto LABEL_6;
}
else
{
v9 = (unsigned __int64 *)BN_CTX_get(a4);
v10 = (__int64 **)v9;
if ( !v9 )
goto LABEL_6;
}
if ( !v8 || !BN_copy(v9, a2) )
goto LABEL_6;
v13 = BN_num_bits(a3);
if ( (unsigned int)BN_is_odd(a3) )
{
if ( !BN_copy(v8, a2) )
goto LABEL_6;
}
else if ( !(unsigned int)BN_set_word((__int64)v8, 1) )
{
goto LABEL_6;
}
v14 = 1;
if ( v13 <= 1 )
{
LABEL_23:
v11 = 1;
if ( a1 != v8 )
{
v11 = 1;
BN_copy(a1, (__int64)v8);
}
goto LABEL_7;
}
while ( 1 )
{
v15 = BN_sqr((__int64)v10, v10, (__int64)a4);
v16 = v14++;
if ( !v15
|| (unsigned int)BN_is_bit_set(a3, v16) && !(unsigned int)BN_mul((__int64)v8, (_QWORD **)v8, v10, (__int64)a4) )
{
break;
}
if ( v14 == v13 )
goto LABEL_23;
}
LABEL_6:
v11 = 0;
LABEL_7:
BN_CTX_end((__int64)a4);
return v11;
}
ERR_put_error(3, 123, 66, (__int64)"crypto/bn/bn_exp.c", 48);
return 0;
}