//
// bn_mul_add_words from 0x10914c0 to 0x1091638 (376 bytes)
//
// 11 xrefs:
// > sub_FF9954 @ 0xff9a1c
// > bn_mul_normal @ 0xffa8c0
// > bn_mul_normal @ 0xffa8e4
// > bn_mul_normal @ 0xffa904
// > bn_mul_normal @ 0xffa924
// > bn_mul_low_normal @ 0xffbab4
// > bn_mul_low_normal @ 0xffbad8
// > bn_mul_low_normal @ 0xffbaf4
// > bn_mul_low_normal @ 0xffbb18
// > bn_sqr_normal @ 0xffd31c
// > ??> @ 0xaf078
//
// 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:21 +0000
//
unsigned __int64 __fastcall bn_mul_add_words(unsigned __int64 *a1, unsigned __int64 *a2, int a3, unsigned __int64 a4)
{
unsigned __int64 v4; // x4
unsigned __int64 v5; // x5
__int64 v6; // x8
unsigned __int64 v7; // x10
unsigned __int64 v8; // x6
unsigned __int64 v9; // x9
bool v10; // cf
__int64 v11; // x7
unsigned __int64 v12; // x4
unsigned __int64 v13; // x5
__int64 v14; // x6
unsigned __int64 v15; // x10
unsigned __int64 v16; // x8
unsigned __int64 v17; // x9
unsigned __int64 v18; // x5
unsigned __int64 v19; // x4
unsigned __int64 v20; // x9
unsigned __int64 v21; // x7
unsigned __int64 v22; // x8
unsigned __int64 v23; // x4
unsigned __int64 v24; // x5
unsigned __int64 v25; // x7
unsigned __int64 v26; // x6
unsigned __int64 v27; // x5
unsigned __int64 v28; // x6
unsigned __int64 v29; // x5
bool v30; // cc
unsigned __int64 v31; // x5
unsigned __int64 v32; // x6
unsigned __int64 v33; // x7
unsigned __int64 v34; // x6
unsigned __int64 v35; // x5
unsigned __int64 v36; // x5
unsigned __int64 v37; // x2
unsigned __int64 v38; // x5
unsigned __int64 v39; // x3
unsigned __int64 v40; // x1
unsigned __int64 v41; // x1
v4 = 0;
if ( a3 > 0 )
{
if ( (a3 & 0xFFFFFFFC) == 0 )
goto LABEL_21;
do
{
v5 = *a2;
a1 += 4;
a2 += 4;
v6 = *(a1 - 3);
a3 -= 4;
v7 = v5 * a4;
v8 = *(a1 - 4) + v4;
v9 = v5 * a4 + v8;
*(a1 - 4) = v9;
v10 = v8 >= v4;
v11 = *(a1 - 2);
v12 = *(a2 - 3);
v13 = (a4 * (unsigned __int128)v5) >> 64;
if ( !v10 )
++v13;
if ( v7 > v9 )
++v13;
v14 = *(a1 - 1);
v15 = v12 * a4;
v16 = v13 + v6;
v17 = v16 + v12 * a4;
*(a1 - 3) = v17;
v10 = v16 >= v13;
v18 = *(a2 - 2);
v19 = (a4 * (unsigned __int128)v12) >> 64;
if ( !v10 )
++v19;
if ( v15 > v17 )
++v19;
v20 = v18 * a4;
v21 = v19 + v11;
v22 = v21 + v18 * a4;
*(a1 - 2) = v22;
v10 = v21 >= v19;
v23 = *(a2 - 1);
v24 = (a4 * (unsigned __int128)v18) >> 64;
if ( !v10 )
++v24;
if ( v20 > v22 )
++v24;
v25 = v23 * a4;
v26 = v24 + v14;
v10 = v26 >= v24;
v27 = v26 + v23 * a4;
v4 = (a4 * (unsigned __int128)v23) >> 64;
if ( !v10 )
++v4;
if ( v25 > v27 )
++v4;
*(a1 - 1) = v27;
}
while ( (a3 & 0xFFFFFFFC) != 0 );
if ( a3 )
{
LABEL_21:
v28 = *a2 * a4;
v29 = *a1 + v4;
v30 = v4 > v29;
v31 = v28 + v29;
if ( v30 )
v4 = ((a4 * (unsigned __int128)*a2) >> 64) + 1;
else
v4 = (a4 * (unsigned __int128)*a2) >> 64;
if ( v28 > v31 )
++v4;
*a1 = v31;
if ( a3 != 1 )
{
v32 = a2[1];
v33 = (a4 * (unsigned __int128)v32) >> 64;
v34 = v32 * a4;
v35 = a1[1] + v4;
v10 = v35 >= v4;
v36 = v34 + v35;
if ( v10 )
v4 = v33;
else
v4 = v33 + 1;
if ( v34 > v36 )
++v4;
a1[1] = v36;
if ( a3 != 2 )
{
v37 = a2[2];
v38 = (a4 * (unsigned __int128)v37) >> 64;
v39 = v37 * a4;
v40 = a1[2] + v4;
v10 = v40 >= v4;
v41 = v39 + v40;
if ( v10 )
v4 = v38;
else
v4 = v38 + 1;
if ( v39 > v41 )
++v4;
a1[2] = v41;
}
}
}
}
return v4;
}