//
// bn_sqr_recursive from 0xffd37c to 0xffd580 (516 bytes)
//
// 5 xrefs:
// > bn_sqr_recursive @ 0xffd418
// > bn_sqr_recursive @ 0xffd434
// > bn_sqr_recursive @ 0xffd448
// > BN_sqr @ 0xffd70c
// > ??> @ 0xc6dd8
//
// 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:15:51 +0000
//
__int64 __fastcall bn_sqr_recursive(_QWORD *a1, __int64 *a2, signed int a3, __int64 a4)
{
unsigned int v7; // w19
__int64 v8; // x26
__int64 *v10; // x28
int v11; // w0
size_t v12; // x25
size_t v13; // x27
__int64 v14; // x23
_QWORD *v15; // x25
int v16; // w23
int v17; // w20
__int64 result; // x0
unsigned __int64 *v19; // x4
unsigned __int64 v20; // x1
unsigned __int64 v21; // t1
if ( a3 == 4 )
return bn_sqr_comba4();
if ( a3 == 8 )
return bn_sqr_comba8();
if ( a3 <= 15 )
return bn_sqr_normal(a1, a2, a3, a4);
v7 = a3 >> 1;
v8 = a3 >> 1;
v10 = &a2[v8];
v11 = bn_cmp_words((__int64)a2, (__int64)&a2[v8], a3 >> 1);
if ( v11 <= 0 )
{
if ( !v11 )
{
v12 = 8LL * a3;
v13 = a4 + v12;
v14 = a4 + 16LL * a3;
memset((void *)(a4 + v12), 0, v12);
goto LABEL_7;
}
bn_sub_words(a4, v10, a2, v7);
}
else
{
bn_sub_words(a4, a2, v10, v7);
}
v12 = 8LL * a3;
v13 = a4 + v12;
v14 = a4 + 16LL * a3;
bn_sqr_recursive(a4 + v12, a4, v7, v14);
LABEL_7:
v15 = &a1[v12 / 8];
bn_sqr_recursive(a1, a2, v7, v14);
bn_sqr_recursive(v15, v10, v7, v14);
v16 = bn_add_words(a4, a1, v15, (unsigned int)a3);
v17 = v16 - bn_sub_words(v13, a4, v13, (unsigned int)a3);
result = v17 + (unsigned int)bn_add_words(&a1[v8], &a1[v8], v13, (unsigned int)a3);
if ( (_DWORD)result )
{
result = (int)result;
v19 = &a1[v7 + a3];
v20 = (int)result + *v19;
*v19 = v20;
if ( (int)result > v20 )
{
do
{
v21 = v19[1];
++v19;
result = v21 + 1;
*v19 = v21 + 1;
}
while ( v21 == -1 );
}
}
return result;
}