//
// sub_10047FCF0 from 0x10047fcf0 to 0x10047fecc (476 bytes)
//
// 1 xrefs:
// > sub_10047F0DC @ 0x10047f0dc
//
// 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_10047FCF0(__int64 a1, __int64 a2, unsigned int a3, int a4)
{
__int64 result; // x0
_DWORD *v7; // x9
unsigned int v8; // w10
int v9; // w10
unsigned __int64 v10; // x9
unsigned int v11; // w12
unsigned int v12; // w8
int v13; // w10
unsigned int v14; // w11
bool v15; // zf
unsigned __int64 v16; // x11
unsigned __int64 v17; // x13
unsigned __int64 v18; // x12
unsigned int v19; // w20
__int64 v20; // x2
unsigned int v21; // w8
bool v22; // cf
unsigned int v23; // w8
unsigned int v24; // [xsp+4h] [xbp-102Ch] BYREF
char v25[4096]; // [xsp+8h] [xbp-1028h] BYREF
*(_DWORD *)(a1 + 508) = a3;
if ( a4 == 8 )
return sub_1004AA8B8(*(_QWORD *)(a1 + 368), *(_DWORD *)(a1 + 272) + a3, 0);
if ( !a3 )
{
LODWORD(v10) = 0;
goto LABEL_24;
}
v7 = *(_DWORD **)(a1 + 8);
v8 = v7[2] - 2;
if ( v8 > 3 )
v9 = 1;
else
v9 = dword_100647DD0[v8];
v11 = v7[5];
v12 = v9 * v7[3];
v13 = **(unsigned __int16 **)(a1 + 552);
if ( v13 == 1 )
{
v14 = v12;
if ( !v12 )
goto LABEL_16;
}
else
{
v15 = v13 != 3 || v12 == 0;
v14 = v12;
if ( v15 )
{
LABEL_16:
v14 = *(_DWORD *)(a1 + 504);
if ( !v14 )
goto LABEL_18;
}
}
v11 = v11 / v14 * v14;
LABEL_18:
v16 = v11;
v17 = v11 * (unsigned __int64)a3;
v18 = (unsigned int)v7[6];
v10 = v17 / v18;
if ( (v13 == 1 || v13 == 3) && v12 || (v12 = *(_DWORD *)(a1 + 504)) != 0 )
LODWORD(v10) = (unsigned int)v10 / v12 * v12;
*(_DWORD *)(a1 + 508) = (unsigned int)v10 * v18 / v16;
LABEL_24:
result = sub_1004AA8B8(*(_QWORD *)(a1 + 368), (unsigned int)(*(_DWORD *)(a1 + 272) + v10), 0);
if ( !(_DWORD)result )
{
if ( *(_QWORD *)(a1 + 320) )
{
v19 = a3 - *(_DWORD *)(a1 + 508);
while ( v19 )
{
v24 = 0;
if ( v19 >= 0x3E8 )
v20 = 1000;
else
v20 = v19;
result = sub_10045F7F8(a1, (__int64)v25, v20, &v24);
v21 = v24;
*(_DWORD *)(a1 + 508) += v24;
v22 = v19 >= v21;
v23 = v19 - v21;
if ( v22 )
v19 = v23;
else
v19 = 0;
if ( (_DWORD)result )
return result;
}
}
return 0;
}
return result;
}