//
// sub_180080240 from 0x180080240 to 0x180080375 (309 bytes)
//
// 5 xrefs:
// > sub_18007FBB0 @ 0x18007fddc
// > ??> @ 0x18013c4f8
// > ??> @ 0x18013c508
// > ??> @ 0x18013c51c
// > ??> @ 0x1801b50ac
//
// 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
//
_BYTE *__fastcall sub_180080240(unsigned __int16 *a1, __int64 a2, _BYTE *a3)
{
unsigned __int64 v3; // rdi
unsigned __int16 *v4; // r9
unsigned int v5; // eax
_BYTE *v6; // rbx
unsigned int v7; // ecx
char v8; // dl
__int64 v9; // rax
int v11; // edx
unsigned int v12; // eax
v3 = (unsigned __int64)&a1[a2];
v4 = a1;
if ( (unsigned __int64)a1 < v3 )
{
while ( 1 )
{
v5 = *v4;
v6 = a3;
if ( v5 < 0xD800 )
break;
if ( v5 - 57344 < 0x2000 )
{
a3[1] = (v5 >> 6) & 0x3F | 0x80;
a3[2] = v5 & 0x3F | 0x80;
LABEL_8:
a3 += 3;
LOBYTE(v5) = (v5 >> 12) | 0xE0;
goto LABEL_9;
}
if ( v5 - 55296 < 0x400 && (unsigned __int64)(v4 + 1) < v3 )
{
v11 = v4[1];
if ( (unsigned int)(v11 - 56320) < 0x400 )
{
v12 = (v11 & 0x3FF) + (((v5 & 0x3FF) + 64) << 10);
*a3 = (v12 >> 18) | 0xF0;
a3[1] = (v12 >> 12) & 0x3F | 0x80;
a3[3] = v12 & 0x3F | 0x80;
a3[2] = (v12 >> 6) & 0x3F | 0x80;
v9 = 4;
a3 += 4;
goto LABEL_11;
}
}
LABEL_10:
v9 = 2;
LABEL_11:
v4 = (unsigned __int16 *)((char *)v4 + v9);
if ( (unsigned __int64)v4 >= v3 )
return a3;
}
if ( v5 >= 0x80 )
{
v7 = v5 >> 6;
v8 = v5 & 0x3F | 0x80;
if ( v5 >= 0x800 )
{
a3[2] = v8;
a3[1] = v7 & 0x3F | 0x80;
goto LABEL_8;
}
a3[1] = v8;
a3 += 2;
LOBYTE(v5) = v7 | 0xC0;
}
else
{
++a3;
}
LABEL_9:
*v6 = v5;
goto LABEL_10;
}
return a3;
}