//
// sub_180052A90 from 0x180052a90 to 0x180052e82 (1010 bytes)
//
// 4 xrefs:
// > sub_1800510D0 @ 0x1800513be
// > sub_180052020 @ 0x1800520a5
// > ??> @ 0x1801f8b14
// > ??> @ 0x1801f8b20
//
// 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_180052A90(__int64 a1, __int64 a2, char *a3, int a4, int a5)
{
char *v7; // r9
__int64 v9; // r12
__int64 result; // rax
char *v11; // rdi
int v12; // eax
__int64 v13; // rbp
int v14; // eax
int v15; // eax
int v16; // eax
int v17; // edx
int v18; // r8d
int v19; // eax
_DWORD *v20; // rcx
int v21; // eax
int v22; // esi
__int64 v23; // rdi
int v24; // eax
__int64 v25; // r8
__int64 v26; // rdx
__int64 v27; // r8
__int64 v28; // r9
unsigned __int64 v29; // rcx
_QWORD *v30; // rax
__int64 v31; // [rsp+40h] [rbp-78h] BYREF
int v32; // [rsp+48h] [rbp-70h]
char v33; // [rsp+60h] [rbp-58h] BYREF
char *v34; // [rsp+D0h] [rbp+18h]
v34 = a3;
v7 = a3;
v9 = 0;
while ( 1 )
{
if ( *(_DWORD *)(a2 + 128) == 3 )
{
result = sub_180053700(a1, a2);
if ( (int)result < 0 )
return result;
v7 = v34;
}
if ( *(_DWORD *)(a2 + 128) == 4 )
break;
LABEL_14:
if ( *(int *)(a2 + 128) >= 2 )
{
do
{
if ( !a4 )
return 0;
if ( sub_180053230(a1, a2, &v31, -1) < 0 )
return 4294967294LL;
v15 = *(_DWORD *)(a2 + 128);
*(float *)(a2 + 140) = (float)(8 * v32) + *(float *)(a2 + 140);
if ( v15 != 4 )
goto LABEL_24;
if ( *(_DWORD *)(a2 + 132) == (unsigned int)sub_18004B910((__int64)&v31) )
goto LABEL_23;
}
while ( !(unsigned int)sub_18004B880((__int64)&v31) );
if ( !a5 )
return 4294967294LL;
sub_1800484A0(a1, (_QWORD *)(a2 + 528));
sub_180048360(a1, a2 + 648);
*(_DWORD *)(a2 + 128) = 2;
if ( *(_DWORD *)(a2 + 8) )
goto LABEL_26;
sub_18004C5B0(a1, *(_QWORD *)(a2 + 104));
sub_18004C4D0(a1, *(_QWORD *)(a2 + 112));
}
LABEL_23:
v15 = *(_DWORD *)(a2 + 128);
if ( v15 == 4 )
goto LABEL_34;
LABEL_24:
if ( v15 >= 3 )
goto LABEL_34;
if ( *(_DWORD *)(a2 + 8) )
{
LABEL_26:
v16 = sub_18004B910((__int64)&v31);
v17 = *(_DWORD *)(a2 + 64);
v18 = v16;
v19 = 0;
if ( v17 > 0 )
{
v20 = *(_DWORD **)(a2 + 88);
do
{
if ( *v20 == v18 )
break;
++v19;
++v20;
}
while ( v19 < v17 );
}
v7 = v34;
if ( v19 != v17 )
{
*(_DWORD *)(a2 + 132) = v18;
*(_DWORD *)(a2 + 136) = v19;
sub_18004C040(a2 + 152, v18);
*(_DWORD *)(a2 + 128) = 3;
goto LABEL_34;
}
}
else
{
result = sub_180052E90(a1, a2, *(_QWORD *)(a2 + 104), *(_QWORD *)(a2 + 112), 0, 0, (__int64)&v31);
if ( (_DWORD)result )
return result;
v21 = *(_DWORD *)(a2 + 504);
++*(_DWORD *)(a2 + 136);
*(_DWORD *)(a2 + 132) = v21;
LABEL_34:
sub_18004BBC0(a1, (__int64 *)(a2 + 152), &v31);
v7 = v34;
}
}
while ( 1 )
{
v11 = &v33;
if ( v7 )
v11 = v7;
v12 = sub_18004BAA0((_QWORD *)(a2 + 152), (__int64)v11);
v34 = nullptr;
if ( v12 == -1 )
return 4294967293LL;
if ( v12 == -139 )
return 4294967157LL;
if ( v12 <= 0 )
goto LABEL_14;
v13 = *((_QWORD *)v11 + 3);
v14 = sub_180050790(a1, a2 + 648, (__int64)v11);
if ( v14 == -139 )
return 4294967157LL;
if ( !v14 )
{
if ( (unsigned int)sub_1800491D0((__int64 *)(a2 + 528), nullptr) )
return 4294967167LL;
sub_1800486F0((__int64 *)(a2 + 528), a2 + 648);
*(float *)(a2 + 144) = (float)(int)sub_1800491D0((__int64 *)(a2 + 528), nullptr) + *(float *)(a2 + 144);
*(float *)(a2 + 140) = (float)(8 * *((_DWORD *)v11 + 2)) + *(float *)(a2 + 140);
if ( v13 == -1 || *((_DWORD *)v11 + 4) )
return 1;
if ( *(_DWORD *)(a2 + 8) )
{
v22 = *(_DWORD *)(a2 + 136);
if ( v22 > 0 )
v13 -= *(_QWORD *)(*(_QWORD *)(a2 + 96) + 16LL * v22);
}
else
{
v22 = 0;
}
v23 = 0;
v24 = sub_1800491D0((__int64 *)(a2 + 528), nullptr);
v25 = 0;
if ( v13 >= 0 )
v25 = v13;
v26 = 0;
v27 = v25 - v24;
if ( v22 < 2LL )
{
if ( v22 <= 0 )
goto LABEL_53;
v28 = *(_QWORD *)(a2 + 96);
}
else
{
v28 = *(_QWORD *)(a2 + 96);
v29 = ((unsigned __int64)(v22 - 2LL) >> 1) + 1;
v30 = (_QWORD *)(v28 + 24);
v26 = 2 * v29;
do
{
v9 += *(v30 - 2);
v23 += *v30;
v30 += 4;
--v29;
}
while ( v29 );
if ( v26 >= v22 )
{
LABEL_53:
*(_QWORD *)(a2 + 120) = v27 + v23 + v9;
return 1;
}
}
v27 += *(_QWORD *)(v28 + 16 * v26 + 8);
goto LABEL_53;
}
v7 = nullptr;
}
}