//
// sub_180053530 from 0x180053530 to 0x1800536f6 (454 bytes)
//
// 3 xrefs:
// > sub_180050E70 @ 0x180050ee3
// > sub_1800523F0 @ 0x18005292d
// > ??> @ 0x1801f8b50
//
// This function is hookable on this platform (idp: pc, 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 10:53:18 +0000
//
__int64 __fastcall sub_180053530(__int64 a1, __int64 a2, __int64 a3)
{
int v3; // edi
__int64 v4; // r15
__int64 v8; // r14
int v9; // esi
int v10; // eax
__int64 v11; // rax
int v12; // eax
__int64 v13; // rcx
int v14; // eax
bool v15; // cc
int v16; // eax
int v17; // eax
__int64 v19[4]; // [rsp+20h] [rbp-78h] BYREF
_BYTE v20[48]; // [rsp+40h] [rbp-58h] BYREF
int v21; // [rsp+A8h] [rbp+10h]
v3 = *(_DWORD *)(a2 + 504);
v4 = 0;
v21 = v3;
v8 = 0;
v9 = -1;
while ( 1 )
{
while ( 1 )
{
while ( 1 )
{
v10 = sub_18004C1A0((__int64 *)(a2 + 32), (__int64)v19);
if ( v10 >= 0 )
break;
*(_QWORD *)(a2 + 16) -= v10;
}
if ( !v10 )
break;
v13 = *(_QWORD *)(a2 + 16);
*(_QWORD *)(a2 + 16) = v13 + v10;
if ( v13 < 0 || (unsigned int)sub_18004B880((__int64)v19) )
goto LABEL_25;
if ( (unsigned int)sub_18004B910((__int64)v19) == v3 )
{
sub_18004BBC0(a1, (__int64 *)(a2 + 152), v19);
v14 = sub_18004BAA0((_QWORD *)(a2 + 152), (__int64)v20);
v15 = v14 <= 0;
if ( v14 )
{
do
{
if ( !v15 )
{
v16 = sub_180050710(a3, (__int64)v20);
if ( v9 != -1 )
v8 += (__int64)(v16 + v9) >> 2;
v9 = v16;
}
v17 = sub_18004BAA0((_QWORD *)(a2 + 152), (__int64)v20);
v15 = v17 <= 0;
}
while ( v17 );
}
if ( sub_18004B8B0((__int64)v19) != -1 )
{
v8 = sub_18004B8B0((__int64)v19) - v8;
goto LABEL_25;
}
v3 = v21;
}
}
*errno() = 0;
if ( !*(_QWORD *)(a2 + 784) )
goto LABEL_25;
if ( !*(_QWORD *)a2 )
goto LABEL_25;
v11 = sub_18004C090(a1, a2 + 32, 8500);
if ( !v11 )
goto LABEL_25;
v12 = (*(__int64 (__fastcall **)(__int64, __int64, __int64, _QWORD))(a2 + 784))(v11, 1, 8500, *(_QWORD *)a2);
if ( v12 <= 0 )
break;
sub_18004C3B0(a2 + 32, v12);
}
if ( !v12 )
errno();
LABEL_25:
if ( v8 >= 0 )
return v8;
return v4;
}