//
// sub_10065F540 from 0x10065f540 to 0x10065f72c (492 bytes)
//
// 2 xrefs:
// > sub_10065F920 @ 0x10065f9d5
// > cocos2d::cc_utf8_to_utf16 @ 0x10066077d
//
// 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_10065F540(char **a1, unsigned __int64 a2, _WORD **a3, unsigned __int64 a4, int a5)
{
char *v5; // r15
_WORD *v6; // r12
__int64 v7; // rbx
signed __int64 v8; // r13
unsigned int v9; // r14d
bool v10; // cl
__int64 result; // rax
int v12; // ecx
int v13; // edx
int v14; // edx
int v15; // edx
int v16; // edx
unsigned int v17; // ecx
unsigned __int64 v18; // [rsp+0h] [rbp-50h]
v5 = *a1;
v6 = *a3;
if ( (unsigned __int64)*a1 < a2 )
{
v18 = a2;
while ( 1 )
{
v7 = (unsigned __int8)*v5;
v8 = (unsigned __int16)byte_1008230B0[v7];
if ( (__int64)(a2 - (_QWORD)v5) <= v8 )
{
result = 1;
goto LABEL_25;
}
v9 = v8 + 1;
v10 = sub_10065F320(v5, (int)v8 + 1);
result = 3;
if ( !v10 )
goto LABEL_25;
v12 = 0;
switch ( (char)v8 )
{
case 0:
v13 = (unsigned __int8)v8;
goto LABEL_14;
case 1:
goto LABEL_13;
case 2:
goto LABEL_12;
case 3:
goto LABEL_11;
case 4:
goto LABEL_10;
case 5:
v12 = (_DWORD)v7 << 6;
LOBYTE(v7) = *++v5;
LABEL_10:
v14 = v12 + (unsigned __int8)v7;
LOBYTE(v7) = *++v5;
v12 = v14 << 6;
LABEL_11:
v15 = v12 + (unsigned __int8)v7;
LOBYTE(v7) = *++v5;
v12 = v15 << 6;
LABEL_12:
v16 = v12 + (unsigned __int8)v7;
LOBYTE(v7) = *++v5;
v12 = v16 << 6;
LABEL_13:
v13 = (v12 + (unsigned __int8)v7) << 6;
LOBYTE(v7) = *++v5;
LABEL_14:
++v5;
v12 = v13 + (unsigned __int8)v7;
break;
default:
break;
}
if ( (unsigned __int64)v6 >= a4 )
{
LABEL_26:
v5 -= v9;
result = 2;
goto LABEL_25;
}
v17 = v12 - dword_1008231B0[v8];
if ( v17 > 0xFFFF )
{
if ( v17 >= 0x110000 )
goto LABEL_20;
if ( (unsigned __int64)(v6 + 1) >= a4 )
goto LABEL_26;
*v6 = ((v17 + 67043328) >> 10) - 10240;
v6[1] = v17 & 0x3FF | 0xDC00;
v6 += 2;
a2 = v18;
if ( (unsigned __int64)v5 >= v18 )
break;
}
else
{
if ( (v17 & 0xF800) != 0xD800 )
{
*v6 = v17;
goto LABEL_4;
}
LABEL_20:
if ( !a5 )
{
v5 -= v9;
goto LABEL_25;
}
*v6 = -3;
LABEL_4:
++v6;
a2 = v18;
if ( (unsigned __int64)v5 >= v18 )
break;
}
}
}
result = 0;
LABEL_25:
*a1 = v5;
*a3 = v6;
return result;
}