//
// sub_1800406E0 from 0x1800406e0 to 0x180040786 (166 bytes)
//
// 11 xrefs:
// > sub_18003FE60 @ 0x18003ff37
// > sub_18003FE60 @ 0x18003ffa4
// > sub_18003FE60 @ 0x180040062
// > sub_18003FE60 @ 0x1800400e7
// > sub_180040360 @ 0x18004043e
// > sub_180040360 @ 0x1800404ab
// > sub_180040360 @ 0x18004056a
// > sub_180040360 @ 0x1800405e8
// > ??> @ 0x1801371c8
// > ??> @ 0x1801371d8
// > ??> @ 0x1801b1374
//
// 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
//
unsigned __int64 __fastcall sub_1800406E0(_WORD *a1, unsigned __int64 a2, _WORD *a3)
{
_WORD *v3; // r9
unsigned __int64 result; // rax
unsigned __int64 v6; // rdx
unsigned __int64 v7; // rdx
_WORD *v8; // rdi
unsigned __int64 i; // rcx
v3 = a1;
result = a2 - (_QWORD)a1;
if ( !*a3 )
return (unsigned __int64)memset(a1, 0, 2 * ((__int64)result >> 1));
v6 = (result + 1) >> 1;
if ( (unsigned __int64)a1 > a2 )
v6 = 0;
if ( v6 >= 8 )
{
result = (unsigned __int64)&a1[v6 - 1];
if ( a1 > a3 || result < (unsigned __int64)a3 )
{
result = (unsigned __int16)*a3;
v7 = 2 * (v6 & 0xFFFFFFFFFFFFFFF8uLL);
v8 = a1;
for ( i = v7 >> 1; i; --i )
*v8++ = result;
v3 = (_WORD *)((char *)v3 + v7);
}
}
for ( ; v3 != (_WORD *)a2; ++v3 )
{
result = (unsigned __int16)*a3;
*v3 = result;
}
return result;
}