//
// sub_10043D0C4 from 0x10043d0c4 to 0x10043d3c8 (772 bytes)
//
// 3 xrefs:
// > sub_100442E2C @ 0x100442f90
// > sub_1004D0374 @ 0x1004d039c
// > sub_1004D03F8 @ 0x1004d0444
//
// 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_10043D0C4(__int64 a1, int a2)
{
__int64 v4; // x21
__int64 v5; // x8
__int64 v6; // x9
void (__fastcall *v7)(__int64); // x8
void (__fastcall *v8)(__int64, __int64, _QWORD, _QWORD, _QWORD); // x8
__int64 result; // x0
int v10; // w8
__int64 v11; // x20
__int64 v12; // x9
__int64 (__fastcall *v13)(__int64, int *); // x8
__int64 v14; // x20
__int64 v15; // x1
int v16; // [xsp+Ch] [xbp-44h] BYREF
int v17; // [xsp+10h] [xbp-40h] BYREF
char v18; // [xsp+17h] [xbp-39h] BYREF
__int128 v19; // [xsp+18h] [xbp-38h] BYREF
v4 = a1 + 69744;
v18 = 0;
v17 = 0;
if ( !*((_BYTE *)&qword_10086F310 + *(unsigned int *)(a1 + 69816)) )
{
sub_1004B5828(&v17);
if ( !a2 || (unsigned int)(v17 - *(_DWORD *)(v4 + 80)) > 0x3E7 || *(_BYTE *)(*(_QWORD *)(a1 + 1648) + 785LL) )
{
*(_DWORD *)(v4 + 80) = v17;
result = sub_1004B5E00(&v18);
if ( (_DWORD)result )
return result;
if ( v18 )
{
qword_10086F310 = 0x101010101010101LL;
qword_10086F318 = 0x101010101010101LL;
}
}
}
v5 = *(unsigned int *)(v4 + 72);
if ( *((_BYTE *)&qword_10086F318 + v5) )
{
*((_BYTE *)&qword_10086F318 + v5) = 0;
v6 = *(_QWORD *)(a1 + 1648);
*(_BYTE *)(v6 + 784) = 0;
v7 = *(void (__fastcall **)(__int64))(v6 + 944);
if ( v7 )
v7(v6 + 8);
}
if ( !a2 )
return 0;
if ( !*((_BYTE *)&qword_10086F310 + *(unsigned int *)(v4 + 72)) )
{
LABEL_29:
if ( *(_BYTE *)(*(_QWORD *)(a1 + 1648) + 785LL) )
{
result = sub_10043D6E0(a1);
if ( (_DWORD)result )
return result;
v16 = 0;
v12 = *(_QWORD *)(a1 + 1648);
v13 = *(__int64 (__fastcall **)(__int64, int *))(v12 + 824);
if ( v13 )
{
result = v13(v12 + 8, &v16);
if ( (_DWORD)result )
return result;
}
if ( *(_DWORD *)(a1 + 1664) )
{
*(_DWORD *)(a1 + 1664) = 0;
if ( v16 >= 1 )
{
v14 = 0;
while ( 1 )
{
result = sub_1004D03F8(a1, v14, 0, 0, &v19, 0, 0, 0);
if ( (_DWORD)result )
return result;
if ( v19 == *(_OWORD *)(a1 + 1668) )
{
*(_DWORD *)(a1 + 1664) = v14;
goto LABEL_41;
}
v14 = (unsigned int)(v14 + 1);
if ( (int)v14 >= v16 )
{
v14 = *(unsigned int *)(a1 + 1664);
goto LABEL_41;
}
}
}
}
v14 = 0;
LABEL_41:
if ( (unsigned int)sub_10043D80C(a1, v14) )
{
result = sub_10043D3C8(a1, 2, 0);
if ( (_DWORD)result )
return result;
}
}
return 0;
}
v8 = *(void (__fastcall **)(__int64, __int64, _QWORD, _QWORD, _QWORD))(v4 + 456);
if ( v8 && (*(_BYTE *)(v4 + 464) & 1) != 0 )
{
v8(a1, 1, 0, 0, *(_QWORD *)v4);
goto LABEL_28;
}
if ( *(_DWORD *)(a1 + 1656) == 2 )
{
if ( (unsigned int)sub_10043D3C8(a1, *(unsigned int *)(v4 + 84), *(unsigned int *)(v4 + 88)) )
goto LABEL_11;
goto LABEL_28;
}
result = sub_1004D0374(a1, &v16);
if ( (_DWORD)result )
return result;
v10 = v16;
if ( !v16 )
goto LABEL_11;
if ( v16 < 1 )
{
LODWORD(v11) = 0;
LABEL_48:
if ( (_DWORD)v11 == v10 )
v15 = 0;
else
v15 = (unsigned int)v11;
if ( (unsigned int)sub_10043D5A0(a1, v15) )
{
LABEL_11:
result = sub_10043D3C8(a1, 2, 0);
if ( (_DWORD)result )
return result;
}
LABEL_28:
*((_BYTE *)&qword_10086F310 + *(unsigned int *)(v4 + 72)) = 0;
goto LABEL_29;
}
v11 = 0;
while ( 1 )
{
result = sub_1004D03F8(a1, v11, 0, 0, &v19, 0, 0, 0);
if ( (_DWORD)result )
return result;
if ( v19 == *(_OWORD *)(v4 + 92) )
{
v10 = v16;
goto LABEL_48;
}
v11 = (unsigned int)(v11 + 1);
v10 = v16;
if ( (int)v11 >= v16 )
goto LABEL_48;
}
}