//
// sub_1005B6CCC from 0x1005b6ccc to 0x1005b7020 (852 bytes)
//
// 1 xrefs:
// > sub_1005BB510 @ 0x1005bb61c
//
// 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 sub_1005B6CCC(_DWORD *a1, __int64 a2, __int64 a3, __int64 a4)
{
int v7; // w24
__int64 *v8; // x23
int v10; // w0
__int64 *v11; // x20
int v12; // w8
__int64 *v13; // x9
_QWORD *v14; // x10
int v15; // w11
__int64 v16; // t1
int v17; // w21
__int64 v18; // x0
_QWORD *v19; // x8
_BYTE v20[72]; // [xsp+0h] [xbp-80h] BYREF
if ( *(_DWORD *)(a2 + 16) )
return sub_1005AD044((__int64)a1, a2, (__int64)&off_100838868, a4);
v7 = *(_DWORD *)(a2 + 8);
v8 = *(__int64 **)a2;
if ( (sub_1005AB404(a2, (__int64)&off_1008388E0) & 0x80000000) == 0 )
return sub_1005AD044((__int64)a1, a2, (__int64)&off_100838868, a4);
v10 = sub_1005AB404((__int64)&off_100838868, a2);
if ( !v10 )
{
sub_1005AB128((__int64)a1, 0);
return 1;
}
if ( v10 >= 1 )
{
if ( a1 != (_DWORD *)a2 )
return sub_1005AAFFC((__int64)a1, a2) != 0;
return 1;
}
if ( a1 == (_DWORD *)a2 )
{
v11 = v8;
}
else
{
if ( (int)a1[3] <= 8 && !sub_1005AAF94((__int64)a1, 9) )
return 0;
v11 = *(__int64 **)a1;
*v11 = *v8;
v11[1] = v8[1];
v11[2] = v8[2];
v11[3] = v8[3];
v11[4] = v8[4];
v11[5] = v8[5];
v11[6] = v8[6];
v11[7] = v8[7];
v11[8] = v8[8];
}
if ( v7 < 9 )
{
v12 = 0;
}
else
{
v12 = v7 - 8;
v13 = v8 + 8;
v14 = v20;
v15 = v7 - 8;
do
{
v16 = *v13++;
*v14++ = v16;
--v15;
}
while ( v15 );
if ( v12 > 8 )
goto LABEL_21;
}
bzero(&v20[8 * v12], 8LL * (unsigned int)(8 - v12) + 8);
LABEL_21:
*(_QWORD *)v20 = *(__int128 *)v20 >> 9;
*(_QWORD *)&v20[8] = *(__int128 *)&v20[8] >> 9;
*(_QWORD *)&v20[16] = *(__int128 *)&v20[16] >> 9;
*(_QWORD *)&v20[24] = *(__int128 *)&v20[24] >> 9;
*(_QWORD *)&v20[32] = *(__int128 *)&v20[32] >> 9;
*(_QWORD *)&v20[40] = *(__int128 *)&v20[40] >> 9;
*(_QWORD *)&v20[48] = *(__int128 *)&v20[48] >> 9;
*(_OWORD *)&v20[56] >>= 9;
v11[8] &= 0x1FFuLL;
v17 = 9;
sub_1005B1BF0(v11, v11, (__int64 *)v20, 9);
v18 = sub_1005B1D18((unsigned __int64 *)v20, (unsigned __int64 *)v11, qword_10067C1A8, 9);
*v11 = *(_QWORD *)((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18);
v11[1] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 8);
v11[2] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 0x10);
v11[3] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 0x18);
v11[4] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 0x20);
v11[5] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 0x28);
v11[6] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 0x30);
v11[7] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 0x38);
v11[8] = *(_QWORD *)(((v18 - 1) & (unsigned __int64)v20 | (unsigned __int64)v11 & -v18) + 0x40);
a1[2] = 9;
v19 = *(_QWORD **)a1;
if ( !*(_QWORD *)(*(_QWORD *)a1 + 64LL) )
{
if ( v19[7] )
{
v17 = 8;
}
else if ( v19[6] )
{
v17 = 7;
}
else if ( v19[5] )
{
v17 = 6;
}
else if ( v19[4] )
{
v17 = 5;
}
else if ( v19[3] )
{
v17 = 4;
}
else if ( v19[2] )
{
v17 = 3;
}
else if ( v19[1] )
{
v17 = 2;
}
else
{
v17 = *v19 != 0;
}
}
a1[2] = v17;
return 1;
}