//
// bn_compute_wNAF from 0xa846a0 to 0xa849e0 (832 bytes)
//
// 3 xrefs:
// > ec_wNAF_mul @ 0xa009a0
// > ec_wNAF_mul @ 0xa00d70
// > ??> @ 0x7b62c
//
// 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
//
char *__fastcall bn_compute_wNAF(_DWORD *a1, int a2, unsigned int *a3)
{
unsigned int is_zero; // r11
int v6; // r9
int v7; // r6
int v8; // r4
char v9; // r2
unsigned int v10; // r8
unsigned int v11; // r5
int v12; // lr
int v13; // r10
char *v14; // r9
char v15; // r1
int v16; // r4
int is_bit_set; // r0
int v18; // r1
bool v19; // zf
char v20; // r0
int v21; // r0
void *v22; // r0
char *result; // r0
int v24; // r2
char v25; // [sp+8h] [bp-1Ch]
int v26; // [sp+Ch] [bp-18h]
char *v27; // [sp+10h] [bp-14h]
int v28; // [sp+14h] [bp-10h]
is_zero = BN_is_zero((int)a1);
if ( is_zero )
{
result = (char *)CRYPTO_malloc((char *)&dword_0 + 1, (int)"crypto/bn/bn_intern.c", 31);
if ( result )
{
*result = 0;
*a3 = 1;
return result;
}
v24 = 33;
LABEL_45:
ERR_put_error(3, 142, 65, (int)"crypto/bn/bn_intern.c", v24);
v22 = nullptr;
goto LABEL_34;
}
if ( (unsigned int)(a2 - 1) > 6 )
{
ERR_put_error(3, 142, 68, (int)"crypto/bn/bn_intern.c", 43);
v22 = nullptr;
goto LABEL_34;
}
v6 = 1 << a2;
v7 = 2 * (1 << a2);
v8 = v7 - 1;
if ( BN_is_negative((int)a1) )
v9 = -1;
else
v9 = 1;
v25 = v9;
if ( !*a1 || !a1[1] )
{
ERR_put_error(3, 142, 68, (int)"crypto/bn/bn_intern.c", 55);
v22 = nullptr;
goto LABEL_34;
}
v10 = BN_num_bits(a1);
v27 = (char *)CRYPTO_malloc((void *)(v10 + 1), (int)"crypto/bn/bn_intern.c", 60);
if ( !v27 )
{
v24 = 66;
goto LABEL_45;
}
v28 = v8 >> 1;
v11 = a2 + 1;
v26 = -v6;
v12 = *(_DWORD *)*a1 & v8;
v13 = v6;
v14 = v27 - 1;
while ( v12 )
{
v15 = v12 & 1;
if ( (v12 & 1) == 0 )
goto LABEL_12;
if ( (v12 & v13) == 0 )
{
v18 = v12;
LABEL_32:
if ( v18 <= v26 )
goto LABEL_33;
goto LABEL_19;
}
if ( v10 > v11 )
{
v18 = v12 - v7;
goto LABEL_32;
}
v18 = v12 & v28;
LABEL_19:
if ( v13 <= v18 || (v18 & 1) == 0 )
{
LABEL_33:
ERR_put_error(3, 142, 68, (int)"crypto/bn/bn_intern.c", 101);
v22 = v27;
goto LABEL_34;
}
v12 -= v18;
v19 = v12 == v7;
if ( v12 != v7 )
v19 = v12 == 0;
v20 = !v19;
if ( v13 == v12 )
v21 = 0;
else
v21 = v20 & 1;
if ( v21 )
{
ERR_put_error(3, 142, 68, (int)"crypto/bn/bn_intern.c", 113);
v22 = v27;
goto LABEL_34;
}
v15 = v18 * v25;
LABEL_12:
*++v14 = v15;
v16 = v12 >> 1;
is_bit_set = BN_is_bit_set(a1, v11);
++is_zero;
++v11;
v12 = v16 + v13 * is_bit_set;
if ( v7 < v12 )
{
ERR_put_error(3, 142, 68, (int)"crypto/bn/bn_intern.c", 124);
v22 = v27;
goto LABEL_34;
}
}
if ( v10 > v11 )
{
v15 = 0;
goto LABEL_12;
}
if ( v10 + 1 >= is_zero )
{
*a3 = is_zero;
return v27;
}
ERR_put_error(3, 142, 68, (int)"crypto/bn/bn_intern.c", 130);
v22 = v27;
LABEL_34:
CRYPTO_free(v22, (int)"crypto/bn/bn_intern.c", 137);
return nullptr;
}