//
// sub_180044E10 from 0x180044e10 to 0x18004539a (1418 bytes)
//
// 3 xrefs:
// > sub_1800445F0 @ 0x180044672
// > sub_180047910 @ 0x180047c60
// > ??> @ 0x1801f81d8
//
// 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_180044E10(__int64 a1, _QWORD *a2, _DWORD *a3, int a4)
{
_DWORD *v6; // r14
unsigned int v7; // edi
int v8; // ebp
__int64 v9; // rcx
__int64 v10; // rcx
__int64 v11; // r12
unsigned int v12; // r15d
__int64 v13; // r14
__int64 v14; // rsi
__int64 v15; // rbp
__int64 v16; // rax
__int64 v17; // rcx
void *v18; // rcx
unsigned int v19; // esi
unsigned __int64 v20; // rbp
_OWORD *v21; // rax
int v22; // esi
int v23; // r9d
int v24; // eax
int v26; // eax
__int64 v27; // rcx
unsigned int v28; // eax
__int64 v29; // rax
int v30; // esi
__int64 v31; // rdx
__int64 v32; // rcx
__int64 v33; // rax
__int64 v34; // r9
__int64 v35; // rax
__int64 v36; // rcx
int v37; // edx
int v38; // r8d
__int64 v39; // rax
__int64 v40; // rax
__int64 v41; // rsi
_DWORD *v42; // rax
int v43; // ecx
unsigned int v44; // [rsp+78h] [rbp+10h] BYREF
_DWORD *v45; // [rsp+80h] [rbp+18h] BYREF
int v46; // [rsp+88h] [rbp+20h]
v46 = a4;
v45 = a3;
v6 = a3;
v7 = 0;
*a3 = 0;
v8 = a4;
v9 = a2[1];
sub_1800427F0(
*(unsigned int **)(v9 + 120),
LOWORD(dword_1801ABCE0[((unsigned __int64)(unsigned int)dword_1801ABCE0[*(unsigned __int8 *)(v9 + 4036)] >> 8)
^ *(unsigned __int8 *)(v9 + 4037)])
^ ((unsigned __int16)dword_1801ABCE0[*(unsigned __int8 *)(v9 + 4036)] << 8));
if ( !(unsigned int)sub_1800453A0(a1, a2) )
return 0;
if ( *(_DWORD *)*a2 != 2 )
{
v10 = a2[1];
v11 = *(unsigned int *)(v10 + 1368);
v12 = *(_DWORD *)(v10 + 1376);
if ( (unsigned int)v11 > *(_DWORD *)(v10 + 448) || v12 > *(_DWORD *)(v10 + 452) )
{
v13 = 128;
v14 = 128;
v15 = 8;
do
{
v16 = a2[1];
v17 = *(_QWORD *)(v16 + v14);
if ( v17 )
{
free((void *)(v17 - 16));
*(_QWORD *)(v14 + a2[1]) = 0;
v16 = a2[1];
}
v18 = *(void **)(v14 + v16 + 3912);
if ( v18 )
{
free(v18);
*(_QWORD *)(v14 + a2[1] + 64) = 0;
*(_QWORD *)(v14 + a2[1] + 3912) = 0;
}
v14 += 8;
--v15;
}
while ( v15 );
v19 = 0;
if ( v12 )
{
v20 = v11 + 4;
while ( v20 >= 4 )
{
if ( 0xFFFFFFFFFFFFFFFFuLL / v20 < 4 )
break;
v21 = j__malloc_base(4 * v20);
if ( !v21 )
break;
*v21 = 0;
*(_QWORD *)(v13 + a2[1]) = v21 + 1;
if ( !(unsigned int)sub_180043C20(
v11,
(void **)(a2[1] + 4040LL + 8LL * v19),
(_QWORD *)(a2[1] + 192LL + 8LL * v19)) )
break;
++v19;
v13 += 8;
if ( v19 >= v12 )
goto LABEL_18;
}
*(_DWORD *)*a2 = 8;
return 0;
}
LABEL_18:
v8 = v46;
v6 = v45;
*(_DWORD *)(a2[1] + 448LL) = v11;
*(_DWORD *)(a2[1] + 452LL) = v12;
v10 = a2[1];
}
v22 = 0;
if ( *(_DWORD *)(v10 + 1376) )
{
do
{
v23 = *(_DWORD *)(v10 + 1384);
switch ( *(_DWORD *)(v10 + 1380) )
{
case 1:
if ( v22 == 1 )
++v23;
break;
case 2:
v26 = v23 + 1;
if ( v22 )
v26 = *(_DWORD *)(v10 + 1384);
v23 = v26;
break;
case 3:
v24 = v23 + 1;
if ( v22 != 1 )
v24 = *(_DWORD *)(v10 + 1384);
v23 = v24;
break;
}
if ( !(unsigned int)sub_180046ED0(a1, (_DWORD)a2, v22, v23, v8) )
return 0;
if ( *(_DWORD *)*a2 == 2 )
return 1;
v10 = a2[1];
}
while ( (unsigned int)++v22 < *(_DWORD *)(v10 + 1376) );
}
if ( !sub_180041B90(*(_QWORD *)(v10 + 120)) )
{
v27 = a2[1];
LODWORD(v45) = 0;
v28 = sub_1800419A0(*(_QWORD *)(v27 + 120));
if ( !(unsigned int)sub_180041D20(a1, *(_QWORD *)(a2[1] + 120LL), (unsigned int *)&v45, v28) )
return 0;
if ( (_DWORD)v45 )
{
v29 = a2[1];
if ( !*(_DWORD *)(v29 + 4112) )
(*(void (__fastcall **)(_QWORD *, _QWORD, _QWORD))(v29 + 56))(a2, 0, *(_QWORD *)(v29 + 104));
*(_DWORD *)*a2 = 2;
}
}
if ( *(_DWORD *)*a2 != 2 )
{
v30 = (unsigned __int16)sub_180041A60(*(__int64 **)(a2[1] + 120LL));
if ( (unsigned int)sub_180041D20(a1, *(_QWORD *)(a2[1] + 120LL), &v44, 0x10u) )
{
if ( v30 == v44 )
{
if ( v8 )
{
v31 = a2[1];
if ( *(_DWORD *)(v31 + 1380) == 1 )
{
if ( *(_DWORD *)(v31 + 1368) )
{
do
{
v40 = v7++;
*(_DWORD *)(*(_QWORD *)(a2[1] + 136LL) + 4 * v40) = *(_DWORD *)(*(_QWORD *)(a2[1] + 128LL) + 4 * v40)
- *(_DWORD *)(*(_QWORD *)(a2[1] + 136LL) + 4 * v40);
}
while ( v7 < *(_DWORD *)(a2[1] + 1368LL) );
}
}
else if ( *(_DWORD *)(v31 + 1380) == 2 )
{
if ( *(_DWORD *)(v31 + 1368) )
{
do
{
v39 = v7++;
*(_DWORD *)(4 * v39 + *(_QWORD *)(a2[1] + 128LL)) += *(_DWORD *)(*(_QWORD *)(a2[1] + 136LL) + 4 * v39);
}
while ( v7 < *(_DWORD *)(a2[1] + 1368LL) );
}
}
else if ( *(_DWORD *)(v31 + 1380) == 3 && *(_DWORD *)(v31 + 1368) )
{
do
{
v32 = a2[1];
v33 = v7++;
v34 = 4 * v33;
v35 = *(_QWORD *)(v32 + 136);
v36 = *(_QWORD *)(v32 + 128);
v37 = *(_DWORD *)(v34 + v35);
v38 = v37 & 1 | (2 * *(_DWORD *)(v36 + v34));
*(_DWORD *)(v36 + v34) = (v37 + v38) >> 1;
*(_DWORD *)(v34 + *(_QWORD *)(a2[1] + 136LL)) = (v38 - v37) >> 1;
}
while ( v7 < *(_DWORD *)(a2[1] + 1368LL) );
}
}
}
else
{
v41 = a2[1];
if ( !*(_DWORD *)(v41 + 4112) )
{
(*(void (__fastcall **)(_QWORD *, __int64, _QWORD))(v41 + 56))(a2, 2, *(_QWORD *)(v41 + 104));
v41 = a2[1];
}
if ( v8 && *(_DWORD *)(v41 + 1376) )
{
do
memset(*(void **)(a2[1] + 8LL * v7++ + 128), 0, 4LL * *(unsigned int *)(a2[1] + 1368LL));
while ( v7 < *(_DWORD *)(a2[1] + 1376LL) );
}
}
*v6 = 1;
v42 = (_DWORD *)a2[1];
v43 = v42[115];
if ( v43 )
{
v42[114] = v43;
v42 = (_DWORD *)a2[1];
}
*(_DWORD *)(*a2 + 4LL) = v42[344];
*(_DWORD *)(*a2 + 8LL) = *(_DWORD *)(a2[1] + 1380LL);
*(_DWORD *)(*a2 + 12LL) = *(_DWORD *)(a2[1] + 1384LL);
*(_DWORD *)(*a2 + 16LL) = *(_DWORD *)(a2[1] + 1372LL);
*(_DWORD *)(*a2 + 20LL) = *(_DWORD *)(a2[1] + 1368LL);
*(_QWORD *)(a2[1] + 464LL) = *(_QWORD *)(a2[1] + 1392LL) + *(unsigned int *)(a2[1] + 1368LL);
if ( !v8 || !(unsigned int)sub_180047E40(a2, a2[1] + 1368LL, a2[1] + 128LL) )
{
*(_DWORD *)*a2 = 2;
return 1;
}
}
return 0;
}
}
return 1;
}