//
// sub_18004A3A0 from 0x18004a3a0 to 0x18004a6ad (781 bytes)
//
// 2 xrefs:
// > sub_18004CB30 @ 0x18004cbc6
// > ??> @ 0x1801f8478
//
// 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:15 +0000
//
__int64 __fastcall sub_18004A3A0(__int64 a1, int *a2, unsigned int *a3)
{
unsigned int v6; // r12d
unsigned int v7; // eax
int v8; // edi
int v9; // eax
int v10; // r14d
__int64 v11; // rax
int v12; // eax
__int64 v13; // rbp
int v14; // edi
__int64 v15; // rsi
unsigned int v16; // eax
int v17; // eax
int i; // edx
__int64 v19; // rax
int v20; // eax
int v21; // ecx
signed int v22; // esi
__int64 v23; // rdi
int v24; // eax
__int64 v25; // rdi
int v26; // eax
unsigned int v27; // eax
unsigned int v28; // eax
int v29; // edi
__int64 v30; // rax
bool v32; // zf
*(_OWORD *)a3 = 0;
*((_OWORD *)a3 + 1) = 0;
*((_OWORD *)a3 + 2) = 0;
*((_QWORD *)a3 + 6) = 0;
a3[12] = 1;
v6 = -1;
if ( (unsigned int)sub_180048210(a2, 0x18u) != 5653314 )
goto LABEL_39;
*a3 = sub_180048210(a2, 0x10u);
v7 = sub_180048210(a2, 0x18u);
a3[1] = v7;
if ( v7 == -1 )
goto LABEL_39;
v8 = sub_1800504C0(v7);
if ( (int)(v8 + sub_1800504C0(*a3)) > 24 )
goto LABEL_39;
v9 = sub_180048210(a2, 1u);
if ( v9 )
{
if ( v9 != 1 )
return v6;
v10 = sub_180048210(a2, 5u) + 1;
v11 = sub_180033CC0(a1, 4 * a3[1]);
*((_QWORD *)a3 + 1) = v11;
if ( !v11 )
goto LABEL_38;
v12 = a3[1];
v13 = 0;
v14 = 0;
if ( v12 > 0 )
{
v15 = 0;
do
{
v16 = sub_1800504C0((unsigned int)(v12 - v14));
v17 = sub_180048210(a2, v16);
if ( v17 == -1 )
goto LABEL_39;
for ( i = 0; i < v17; *(_DWORD *)(*((_QWORD *)a3 + 1) + 4 * v15++) = v10 )
{
if ( v14 >= (int)a3[1] )
break;
++i;
++v14;
}
v12 = a3[1];
++v10;
}
while ( v14 < v12 );
}
}
else
{
v19 = sub_180033CC0(a1, 4 * a3[1]);
*((_QWORD *)a3 + 1) = v19;
if ( !v19 )
goto LABEL_38;
v20 = sub_180048210(a2, 1u);
v21 = a3[1];
v13 = 0;
v22 = 0;
if ( v20 )
{
if ( v21 > 0 )
{
v23 = 0;
do
{
if ( (unsigned int)sub_180048210(a2, 1u) )
{
v24 = sub_180048210(a2, 5u);
if ( v24 == -1 )
goto LABEL_39;
*(_DWORD *)(v23 + *((_QWORD *)a3 + 1)) = v24 + 1;
}
else
{
*(_DWORD *)(v23 + *((_QWORD *)a3 + 1)) = 0;
}
++v22;
v23 += 4;
}
while ( v22 < (int)a3[1] );
}
}
else if ( v21 > 0 )
{
v25 = 0;
do
{
v26 = sub_180048210(a2, 5u);
if ( v26 == -1 )
goto LABEL_39;
++v22;
*(_DWORD *)(v25 + *((_QWORD *)a3 + 1)) = v26 + 1;
v25 += 4;
}
while ( v22 < (int)a3[1] );
}
}
v27 = sub_180048210(a2, 4u);
a3[4] = v27;
if ( v27 )
{
if ( v27 - 1 > 1 )
goto LABEL_39;
a3[5] = sub_180048210(a2, 0x20u);
a3[6] = sub_180048210(a2, 0x20u);
a3[7] = sub_180048210(a2, 4u) + 1;
v28 = sub_180048210(a2, 1u);
a3[8] = v28;
if ( v28 == -1 )
goto LABEL_39;
v29 = 0;
if ( a3[4] == 1 )
{
if ( *a3 )
v29 = sub_1800500F0(a3);
}
else if ( a3[4] == 2 )
{
v29 = a3[1] * *a3;
}
v30 = sub_180033CC0(a1, 4 * v29);
*((_QWORD *)a3 + 5) = v30;
if ( !v30 )
{
LABEL_38:
v6 = -139;
LABEL_39:
sub_180050030(a1, a3);
return v6;
}
v32 = v29 == 0;
if ( v29 > 0 )
{
do
*(_DWORD *)(*((_QWORD *)a3 + 5) + 4 * v13++) = sub_180048210(a2, a3[7]);
while ( v13 < v29 );
v32 = v29 == 0;
}
if ( !v32 && *(_DWORD *)(*((_QWORD *)a3 + 5) + 4LL * v29 - 4) == -1 )
goto LABEL_39;
}
return 0;
}