//
// sub_1800158E0 from 0x1800158e0 to 0x180015a1d (317 bytes)
//
// 4 xrefs:
// > sub_180015B40 @ 0x180015c8b
// > ??> @ 0x18017f010
// > ??> @ 0x18017f020
// > ??> @ 0x1801f70bc
//
// 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:52:47 +0000
//
__int64 __fastcall sub_1800158E0(__int64 a1, int *a2, __int64 *a3, __int64 a4)
{
_BYTE *v4; // rax
int v7; // esi
int v8; // ecx
int v9; // ecx
__int64 i; // r11
int v11; // r9d
__int64 *v12; // r8
__int64 v13; // rcx
int v14; // ecx
__int64 j; // r11
int v16; // r9d
__int64 *v17; // r8
__int64 v18; // rcx
int v19; // ecx
__int64 k; // r11
int v21; // r9d
__int64 *v22; // r8
__int64 v23; // rcx
v4 = *(_BYTE **)(a4 + 440);
if ( v4 )
{
v7 = *a2;
if ( (unsigned int)*a2 > 0x2000 )
v7 = 0x2000;
v8 = a2[4];
if ( v8 == 8 )
{
if ( v7 > 0 )
{
v9 = a2[2];
for ( i = 0; i < v7; ++i )
{
v11 = 0;
if ( v9 > 0 )
{
v12 = a3;
do
{
v13 = *v12++;
++v11;
*v4++ = *(_BYTE *)(v13 + 4 * i);
v9 = a2[2];
}
while ( v11 < v9 );
}
}
}
}
else if ( v8 == 16 )
{
if ( v7 > 0 )
{
v14 = a2[2];
for ( j = 0; j < v7; ++j )
{
v16 = 0;
if ( v14 > 0 )
{
v17 = a3;
do
{
v18 = *v17++;
++v16;
*(_WORD *)v4 = *(_WORD *)(v18 + 4 * j);
v4 += 2;
v14 = a2[2];
}
while ( v16 < v14 );
}
}
}
}
else if ( v8 == 24 && v7 > 0 )
{
v19 = a2[2];
for ( k = 0; k < v7; ++k )
{
v21 = 0;
if ( v19 > 0 )
{
v22 = a3;
do
{
v23 = *v22++;
++v21;
*(_WORD *)v4 = *(_WORD *)(v23 + 4 * k);
v4[2] = *(_BYTE *)(v23 + 4 * k + 2);
v4 += 3;
v19 = a2[2];
}
while ( v21 < v19 );
}
}
}
*(_DWORD *)(a4 + 464) = v7;
}
return 0;
}