//
// sub_180015E10 from 0x180015e10 to 0x180015f4c (316 bytes)
//
// 4 xrefs:
// > sub_180015AB0 @ 0x180015ae4
// > ??> @ 0x18017efa4
// > ??> @ 0x18017efdc
// > ??> @ 0x1801f70f8
//
// 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_180015E10(__int64 a1, __int64 a2, int a3, _DWORD *a4)
{
int v5; // ebp
__int64 v9; // rcx
__int64 v10; // rdx
int v11; // esi
int v12; // esi
unsigned int v13; // ecx
int v14; // edi
__int64 v15; // rdx
int v16; // edx
v5 = a3;
if ( !*(_QWORD *)(a1 + 376) )
return 31;
v9 = *(_QWORD *)(a1 + 8);
v10 = (unsigned int)(*(_DWORD *)(v9 + 8) - 1);
if ( *(_DWORD *)(v9 + 8) == 1 )
goto LABEL_10;
v10 = (unsigned int)(*(_DWORD *)(v9 + 8) - 2);
if ( *(_DWORD *)(v9 + 8) == 2 )
{
v11 = 2;
goto LABEL_11;
}
v10 = (unsigned int)(*(_DWORD *)(v9 + 8) - 3);
if ( *(_DWORD *)(v9 + 8) == 3 )
{
v11 = 3;
goto LABEL_11;
}
v10 = (unsigned int)(*(_DWORD *)(v9 + 8) - 4);
if ( (unsigned int)v10 > 1 )
{
LABEL_10:
v11 = 1;
goto LABEL_11;
}
v11 = 4;
LABEL_11:
v12 = *(_DWORD *)(v9 + 12) * v11;
if ( a3 )
{
do
{
v13 = *(_DWORD *)(a1 + 464);
v14 = v5;
if ( !v13 )
{
v15 = *(_QWORD *)(a1 + 376);
*(_DWORD *)(a1 + 460) = 0;
sub_1800445F0(a1, v15);
v13 = *(_DWORD *)(a1 + 464);
if ( !v13 )
break;
}
v16 = *(_DWORD *)(a1 + 460);
if ( v16 + v5 >= v13 )
{
*(_DWORD *)(a1 + 464) = 0;
v14 = v13 - v16;
}
memmove(
(void *)(a2 + (unsigned int)(*a4 * v12)),
(const void *)(*(_QWORD *)(a1 + 440) + (unsigned int)(v12 * v16)),
(unsigned int)(v12 * v14));
*(_DWORD *)(a1 + 460) += v14;
*a4 += v14;
v5 -= v14;
}
while ( v5 );
}
if ( (unsigned int)sub_180043FA0(*(_QWORD *)(a1 + 376), v10) != 4 )
return 0;
*a4 = 0;
return 16;
}