//
// sub_18003FE60 from 0x18003fe60 to 0x18004010b (683 bytes)
//
// 7 xrefs:
// > sub_18003FE60 @ 0x18003fee2
// > sub_18003FE60 @ 0x18003ff4e
// > sub_18003FE60 @ 0x18003ff6d
// > sub_180040360 @ 0x1800403e9
// > sub_180040360 @ 0x180040455
// > sub_180040360 @ 0x180040474
// > ??> @ 0x1801b1350
//
// 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_18003FE60(unsigned __int64 *a1, int a2, unsigned int *a3, __int64 a4, unsigned int a5)
{
unsigned __int64 v5; // rbp
unsigned __int16 v7; // dx
unsigned int v9; // r12d
unsigned int v11; // edi
__int64 v13; // rbp
__int64 v14; // r14
unsigned __int64 v15; // r15
unsigned __int64 v16; // rbp
__int64 v17; // rax
unsigned __int64 v18; // rbp
__int64 v19; // rsi
unsigned __int64 v20; // rdi
unsigned __int64 v21; // r15
unsigned __int64 v22; // rcx
__int64 v23; // rdi
__int64 v24; // r12
unsigned __int64 v25; // rdi
__int64 v26; // rbx
unsigned __int64 v27; // rax
char *v28; // rbx
char *v29; // r15
char *v30; // rbx
__int64 v31; // rax
unsigned __int64 v32; // [rsp+30h] [rbp-48h] BYREF
int v33; // [rsp+38h] [rbp-40h]
unsigned __int16 v34; // [rsp+90h] [rbp+18h]
v5 = *a3;
v7 = *((_WORD *)a3 + 2);
v9 = a3[2];
v34 = v7;
if ( a2 >= -1 )
{
v21 = *a1;
v22 = a1[1];
v23 = a5 + a2;
if ( (unsigned int)v5 > (unsigned int)v23 )
{
v27 = v21 + v5;
v32 = v21 + v5;
if ( v21 + v5 > v22 )
{
sub_1800441F0(a1);
v27 = v32;
v7 = v34;
}
*a1 = v27;
v28 = (char *)(a1[2] + 2 * v21);
v29 = &v28[2 * v5];
if ( v9 == 1 )
{
sub_180040610(a4, a4 + a5, v28);
v30 = &v28[2 * v23];
sub_1800406E0(v30);
}
else if ( v9 == 3 )
{
v31 = fmt::BasicWriter::FillPadding(v28, (unsigned int)v5, v23, v7);
v30 = (char *)(v31 + 2 * v23);
sub_180040610(a4, a4 + a5, v31);
}
else
{
if ( v9 == 4 )
{
if ( a5 )
v28 = (char *)sub_180040610(a4, a4 + a5, v28);
}
else
{
sub_180040610(a4, a4 + a5, &v29[-2 * (unsigned int)v23]);
}
sub_1800406E0(v28);
v30 = v29;
}
return (__int64)(v30 - 2);
}
else
{
v24 = (unsigned int)v23;
v25 = v21 + v23;
if ( v25 > v22 )
sub_1800441F0(a1);
*a1 = v25;
v26 = a1[2] + 2 * v21;
sub_180040610(a4, a4 + a5, v26);
return v26 + 2 * (v24 - 1);
}
}
else
{
v11 = a5;
if ( a5 && *(_BYTE *)(a5 - 1 + a4) == 48 )
v11 = a5 - 1;
v33 = 4;
LODWORD(v32) = v11 - 1;
WORD2(v32) = 48;
if ( v11 - 1 < (unsigned int)v5 )
{
if ( v5 > a1[1] )
sub_1800441F0(a1);
v13 = (unsigned int)v5 - (v11 - 1);
v14 = (unsigned int)v13;
if ( v9 == 1 )
{
v17 = sub_18003FE60((_DWORD)a1, a2, (unsigned int)&v32, a4, v11);
v18 = *a1;
v19 = v17;
v20 = v14 + *a1;
if ( v20 > a1[1] )
sub_1800441F0(a1);
*a1 = v20;
sub_1800406E0((void *)(a1[2] + 2 * v18));
return v19;
}
else
{
v15 = *a1;
v16 = *a1 + v13;
if ( v16 > a1[1] )
sub_1800441F0(a1);
*a1 = v16;
sub_1800406E0((void *)(a1[2] + 2 * v15));
return sub_18003FE60((_DWORD)a1, a2, (unsigned int)&v32, a4, v11);
}
}
else
{
return sub_18003FE60((_DWORD)a1, a2, (unsigned int)&v32, a4, v11);
}
}
}