//
// sub_1800D5040 from 0x1800d5040 to 0x1800d5229 (489 bytes)
//
// 6 xrefs:
// > sub_1800DBAE0 @ 0x1800dbc1d
// > sub_1800DBDF0 @ 0x1800dbf7f
// > sub_1800DC1C0 @ 0x1800dc65d
// > ??> @ 0x180142cc0
// > ??> @ 0x180142cd4
// > ??> @ 0x1801ba77c
//
// 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
//
char *__fastcall sub_1800D5040(char *Source, char *a2, int a3, int a4, int a5)
{
__int64 v5; // rbp
__int64 v6; // r14
int v9; // r10d
_DWORD *v10; // rax
char *v13; // rsi
void *v14; // rax
__int64 v15; // rax
__int64 v16; // r9
unsigned __int8 *v17; // rdx
char v18; // r8
bool v19; // cc
__int64 v20; // r8
unsigned __int8 *v21; // rcx
char v22; // dl
bool v23; // cc
v5 = 0;
v6 = a4;
v9 = 0;
v10 = &unk_1801AA098;
while ( *(v10 - 72) )
{
if ( !*v10 )
{
++v9;
break;
}
if ( !v10[72] )
{
v9 += 2;
break;
}
if ( !v10[144] )
{
v9 += 3;
break;
}
v10 += 288;
v9 += 4;
if ( (__int64)v10 > (__int64)&qword_1801AB178 )
break;
}
if ( v9 > 15 )
return nullptr;
v13 = (char *)&unk_1801A9F78 + 288 * v9;
*(_DWORD *)v13 = 1;
*((_QWORD *)v13 + 1) = calloc(a3, 4u);
*((_QWORD *)v13 + 3) = calloc(v6 + 4LL * a5, 1u);
v14 = calloc(a5, 1u);
*((_DWORD *)v13 + 4) = a3;
*((_QWORD *)v13 + 5) = v14;
*((_DWORD *)v13 + 8) = v6;
*((_DWORD *)v13 + 12) = a5;
strncpy(v13 + 52, Source, 0x7Fu);
strncpy(v13 + 192, a2, 0x20u);
v15 = sub_1800D5590(v13 + 192);
if ( v15 )
{
v16 = 0;
v17 = (unsigned __int8 *)(v15 + 162);
while ( 1 )
{
v18 = *(v17 - 1);
switch ( v18 )
{
case 3:
if ( *v17 >> 4 >= *((_DWORD *)v13 + 12) )
goto LABEL_29;
break;
case 2:
v19 = (int)*v17 < *((_DWORD *)v13 + 8);
LABEL_19:
if ( !v19 )
goto LABEL_29;
break;
case 1:
v19 = (int)*v17 < *((_DWORD *)v13 + 4);
goto LABEL_19;
}
++v16;
v17 += 4;
if ( v16 > 14 )
{
v20 = 0;
v21 = (unsigned __int8 *)(v15 + 222);
while ( 1 )
{
v22 = *(v21 - 1);
switch ( v22 )
{
case 3:
if ( *v21 >> 4 >= *((_DWORD *)v13 + 12) )
goto LABEL_29;
break;
case 2:
v23 = (int)*v21 < *((_DWORD *)v13 + 8);
LABEL_26:
if ( !v23 )
goto LABEL_29;
break;
case 1:
v23 = (int)*v21 < *((_DWORD *)v13 + 4);
goto LABEL_26;
}
++v20;
v21 += 4;
if ( v20 > 5 )
goto LABEL_28;
}
}
}
}
LABEL_28:
v5 = v15;
LABEL_29:
*((_QWORD *)v13 + 29) = v5;
return v13;
}