//
// sub_180098140 from 0x180098140 to 0x18009840c (716 bytes)
//
// 4 xrefs:
// > cocos2d::cc_utf8_to_utf16 @ 0x180098bc9
// > ??> @ 0x1801477f0
// > ??> @ 0x180147800
// > ??> @ 0x1801c09e4
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 11:22:10 +0000
//
__int64 __fastcall sub_180098140(unsigned __int64 *a1, unsigned __int64 a2, _WORD **a3, unsigned __int64 a4, int a5)
{
unsigned __int8 *v5; // r10
unsigned int v6; // edi
_WORD *v7; // r11
unsigned __int64 v9; // r9
_WORD *v10; // rsi
__int64 v11; // r15
__int64 v12; // rbx
int v13; // edx
unsigned __int16 v14; // ax
__int64 v15; // r14
__int64 v16; // rbp
unsigned __int8 *v17; // r8
char v18; // al
char v19; // al
unsigned __int8 v20; // r9
bool v21; // cf
int v22; // edx
int v23; // edx
int v24; // edx
int v25; // edx
int v26; // eax
unsigned int v27; // edx
v5 = (unsigned __int8 *)*a1;
v6 = 0;
v7 = *a3;
v9 = a2;
if ( *a1 < a2 )
{
v10 = v7 + 1;
v11 = a2 - (_QWORD)v5;
while ( 1 )
{
v12 = *v5;
v13 = 0;
v14 = byte_18010AA60[v12];
v15 = v14;
if ( v14 >= v11 )
{
v6 = 1;
goto LABEL_50;
}
v16 = v14;
v17 = &v5[v14 + 1];
if ( byte_18010AA60[v12] )
break;
LABEL_23:
if ( (char)v12 < -62 || (unsigned __int8)v12 > 0xF4u )
goto LABEL_46;
switch ( v16 )
{
case 0LL:
goto LABEL_31;
case 1LL:
goto LABEL_30;
case 2LL:
goto LABEL_29;
case 3LL:
goto LABEL_28;
case 4LL:
goto LABEL_27;
case 5LL:
++v5;
--v11;
v13 = (_DWORD)v12 << 6;
LABEL_27:
--v11;
v22 = *v5++ + v13;
v13 = v22 << 6;
LABEL_28:
--v11;
v23 = *v5++ + v13;
v13 = v23 << 6;
LABEL_29:
--v11;
v24 = *v5++ + v13;
v13 = v24 << 6;
LABEL_30:
--v11;
v25 = *v5++ + v13;
v13 = v25 << 6;
LABEL_31:
v26 = *v5++;
v13 += v26;
--v11;
break;
default:
break;
}
v27 = v13 - dword_18010AB60[v15];
if ( (unsigned __int64)v7 >= a4 )
{
LABEL_48:
v6 = 2;
v5 += -1 - v15;
goto LABEL_50;
}
if ( v27 > 0xFFFF )
{
if ( v27 <= 0x10FFFF )
{
if ( (unsigned __int64)v10 >= a4 )
goto LABEL_48;
*v7++ = ((v27 - 0x10000) >> 10) - 10240;
v10 += 2;
*v7 = (v27 & 0x3FF) - 9216;
}
else
{
if ( !a5 )
{
v6 = 3;
v5 += -1 - v15;
goto LABEL_50;
}
*v7 = -3;
++v10;
}
}
else
{
if ( v27 - 55296 <= 0x7FF )
{
if ( !a5 )
{
v5 += -1 - v15;
LABEL_46:
v6 = 3;
goto LABEL_50;
}
LOWORD(v27) = -3;
}
*v7 = v27;
++v10;
}
++v7;
if ( (unsigned __int64)v5 >= v9 )
goto LABEL_50;
}
if ( v14 != 1 )
{
if ( v14 != 2 )
{
if ( v14 != 3 )
goto LABEL_46;
v18 = *--v17;
if ( (unsigned __int8)(v18 + 0x80) > 0x3Fu )
goto LABEL_46;
}
v19 = *--v17;
if ( (unsigned __int8)(v19 + 0x80) > 0x3Fu )
goto LABEL_46;
}
v20 = *(v17 - 1);
if ( (unsigned __int8)(v20 + 0x80) > 0x3Fu )
goto LABEL_46;
switch ( (_DWORD)v12 )
{
case 0xE0:
v21 = v20 < 0xA0u;
break;
case 0xED:
if ( v20 > 0x9Fu )
goto LABEL_46;
LABEL_22:
v9 = a2;
goto LABEL_23;
case 0xF0:
v21 = v20 < 0x90u;
break;
default:
if ( (_DWORD)v12 == 244 && v20 > 0x8Fu )
goto LABEL_46;
goto LABEL_22;
}
if ( v21 )
goto LABEL_46;
goto LABEL_22;
}
LABEL_50:
*a1 = (unsigned __int64)v5;
*a3 = v7;
return v6;
}