//
// sub_180040790 from 0x180040790 to 0x180040867 (215 bytes)
//
// 5 xrefs:
// > sub_18003D560 @ 0x18003d687
// > sub_18003D560 @ 0x18003d697
// > sub_18003DEC0 @ 0x18003dfe7
// > sub_18003DEC0 @ 0x18003dff7
// > ??> @ 0x1801b1398
//
// 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_180040790(__int64 *a1, const void *a2, size_t a3, unsigned int *a4)
{
size_t v4; // rax
__int64 v6; // r14
unsigned int v10; // edx
char *v11; // rbx
int v12; // ecx
__int64 v13; // rax
v4 = *a4;
v6 = *a1;
if ( v4 <= a3 )
{
sub_1800447F0(a1, v6 + a3);
v11 = (char *)(v6 + a1[2]);
}
else
{
sub_1800447F0(a1, v4 + v6);
v10 = a4[2];
v11 = (char *)(v6 + a1[2]);
v12 = *((unsigned __int8 *)a4 + 4);
v13 = *a4;
if ( v10 == 2 )
{
if ( (unsigned int)v13 != a3 )
memset(v11, v12, (unsigned int)v13 - a3);
v11 += *a4 - a3;
}
else if ( v10 == 3 )
{
v11 = (char *)fmt::BasicWriter::FillPadding(v11, (unsigned int)v13, a3, (unsigned int)(char)v12);
}
else if ( v13 != a3 )
{
memset(&v11[a3], v12, v13 - a3);
}
}
memmove(v11, a2, a3);
return v11;
}