//
// sub_1005AAD90 from 0x1005aad90 to 0x1005aaee0 (336 bytes)
//
// 5 xrefs:
// > sub_1005AAF94 @ 0x1005aafc0
// > sub_1005AAFFC @ 0x1005ab034
// > sub_1005AB128 @ 0x1005ab15c
// > sub_1005AB1B0 @ 0x1005ab234
// > sub_1005AB508 @ 0x1005ab560
//
// 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
//
_BYTE *__fastcall sub_1005AAD90(__int64 a1, int a2)
{
__int64 v3; // x2
__int64 v4; // x4
_BYTE *result; // x0
_QWORD *v6; // x8
int v7; // w10
int v8; // w12
int v9; // w9
__int64 v10; // x9
__int64 v11; // x11
_QWORD *v12; // x9
int v13; // w12
_BYTE *v14; // x13
_QWORD *v15; // x14
__int64 v16; // x15
__int64 v17; // x16
int v18; // w10
if ( a2 >= 0x800000 )
{
v3 = 114;
v4 = 296;
LABEL_15:
sub_1005E0E48(3, 120, v3, "bn_lib.c", v4);
return nullptr;
}
if ( (*(_BYTE *)(a1 + 20) & 2) != 0 )
{
v3 = 105;
v4 = 300;
goto LABEL_15;
}
result = sub_100588710((unsigned int)(8 * a2), (__int64)"bn_lib.c", 303);
if ( !result )
{
v3 = 65;
v4 = 305;
goto LABEL_15;
}
v6 = *(_QWORD **)a1;
if ( !*(_QWORD *)a1 )
return result;
v7 = *(_DWORD *)(a1 + 8);
v8 = v7 >> 2;
if ( v7 >> 2 < 1 )
{
v12 = result;
}
else
{
if ( ~v8 < -2 || v8 == 1 )
v9 = -2;
else
v9 = ~v8;
v10 = (unsigned int)(v8 + v9 + 1);
v11 = 4 * v10 + 4;
v12 = &result[32 * v10 + 32];
v13 = v8 + 1;
v14 = result;
v15 = *(_QWORD **)a1;
do
{
v16 = v15[2];
v17 = v15[3];
*(_OWORD *)v14 = *(_OWORD *)v15;
*((_QWORD *)v14 + 2) = v16;
*((_QWORD *)v14 + 3) = v17;
--v13;
v15 += 4;
v14 += 32;
}
while ( v13 > 1 );
v6 += v11;
}
v18 = v7 & 3;
switch ( v18 )
{
case 1:
LABEL_23:
*v12 = *v6;
return result;
case 2:
LABEL_22:
v12[1] = v6[1];
goto LABEL_23;
case 3:
v12[2] = v6[2];
goto LABEL_22;
}
return result;
}