//
// sub_180030440 from 0x180030440 to 0x180030758 (792 bytes)
//
// 2 xrefs:
// > sub_180031D30 @ 0x180032080
// > ??> @ 0x1801f7920
//
// 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_180030440(__int64 a1, int a2, __int64 a3, int a4, int *a5)
{
__int64 v5; // r10
__int64 v7; // r11
__int64 v8; // rbp
int v9; // esi
__int64 v10; // r9
_DWORD *v11; // rbx
__int64 v12; // rcx
__int64 v13; // rdi
__int64 v14; // rax
char *v15; // r12
char *v16; // r13
_DWORD *v17; // rcx
__int64 v18; // rdx
v5 = *(_QWORD *)(a1 + 376);
v7 = a4;
v8 = a3;
v9 = 0;
v10 = *(int *)(v5 + 4LL * a4 + 18616);
*(_DWORD *)(v5 + 4 * v7 + 18616) = 1 - v10;
v11 = (_DWORD *)(2304 * (v7 + 2 * v10) + v5 + 9288);
v12 = v7 + 2LL * (1 - (int)v10);
v13 = 2304 * v12 + v5 + 9288;
if ( a5[5] )
{
v9 = 2;
sub_180031430(a2, (_DWORD)v11, 2304 * v12 + v5 + 9288, (unsigned int)&unk_1801C0840, a3);
sub_180031430(a2 + 72, (_DWORD)v11 + 72, v13 + 72, (unsigned int)&unk_1801C0A80, v8 + 4);
v11 += 36;
v13 += 144;
v8 += 8;
}
v14 = a5[4];
if ( v9 < a5[16] )
{
if ( (_DWORD)v14 == 2 )
{
do
{
sub_180030EB0(a2 + 72 * v9, (_DWORD)v11, v13, (unsigned int)&unk_1801C0960, v8);
sub_180030EB0(a2 + 72 * (v9 + 1), (_DWORD)v11 + 72, v13 + 72, (unsigned int)&unk_1801C0BA0, v8 + 4);
v9 += 2;
v8 += 8;
v11 += 36;
v13 += 144;
}
while ( v9 < a5[16] );
}
else
{
v15 = (char *)&unk_1801C0840 + 144 * v14;
v16 = (char *)&unk_1801C0A80 + 144 * v14;
do
{
sub_180031430(a2 + 72 * v9, (_DWORD)v11, v13, (_DWORD)v15, v8);
sub_180031430(a2 + 72 * (v9 + 1), (_DWORD)v11 + 72, v13 + 72, (_DWORD)v16, v8 + 4);
v9 += 2;
v8 += 8;
v11 += 36;
v13 += 144;
}
while ( v9 < a5[16] );
}
}
if ( v9 < 32 )
{
v17 = (_DWORD *)(v8 + 256);
v18 = (unsigned int)(32 - v9);
do
{
v13 += 72;
*(v17 - 64) = *v11;
v11 += 18;
*(_DWORD *)(v13 - 72) = 0;
*(++v17 - 33) = *(v11 - 17);
*(_DWORD *)(v13 - 68) = 0;
*(v17 - 1) = *(v11 - 16);
*(_DWORD *)(v13 - 64) = 0;
v17[31] = *(v11 - 15);
*(_DWORD *)(v13 - 60) = 0;
v17[63] = *(v11 - 14);
*(_DWORD *)(v13 - 56) = 0;
v17[95] = *(v11 - 13);
*(_DWORD *)(v13 - 52) = 0;
v17[127] = *(v11 - 12);
*(_DWORD *)(v13 - 48) = 0;
v17[159] = *(v11 - 11);
*(_DWORD *)(v13 - 44) = 0;
v17[191] = *(v11 - 10);
*(_DWORD *)(v13 - 40) = 0;
v17[223] = *(v11 - 9);
*(_DWORD *)(v13 - 36) = 0;
v17[255] = *(v11 - 8);
*(_DWORD *)(v13 - 32) = 0;
v17[287] = *(v11 - 7);
*(_DWORD *)(v13 - 28) = 0;
v17[319] = *(v11 - 6);
*(_DWORD *)(v13 - 24) = 0;
v17[351] = *(v11 - 5);
*(_DWORD *)(v13 - 20) = 0;
v17[383] = *(v11 - 4);
*(_DWORD *)(v13 - 16) = 0;
v17[415] = *(v11 - 3);
*(_DWORD *)(v13 - 12) = 0;
v17[447] = *(v11 - 2);
*(_DWORD *)(v13 - 8) = 0;
v17[479] = *(v11 - 1);
*(_DWORD *)(v13 - 4) = 0;
--v18;
}
while ( v18 );
}
return 0;
}