//
// sub_180098D60 from 0x180098d60 to 0x18009911f (959 bytes)
//
// 2 xrefs:
// > cocos2d::cc_utf16_to_utf8 @ 0x18009866e
// > ??> @ 0x1801c0ab0
//
// 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
//
// Hidden C++ exception states: #wind=1
char __fastcall sub_180098D60(char *a1, _QWORD *a2)
{
char *v3; // rsi
__int64 v4; // rdx
__int16 *v6; // r8
char *v7; // rax
unsigned __int16 *v8; // rbp
__int16 v9; // ax
unsigned __int64 v10; // r8
__int64 v11; // rdx
unsigned __int64 v12; // r9
__int64 v13; // rcx
__m128i si128; // xmm1
unsigned __int16 *v15; // rbx
unsigned __int64 v16; // rdx
unsigned __int64 *v17; // rsi
unsigned __int64 v18; // rax
unsigned __int64 *v19; // rax
char *v20; // rdx
char *v21; // r10
unsigned int v22; // eax
int v23; // r8d
__int64 v24; // r8
__int64 v25; // r9
char *v26; // rdx
int v27; // r8d
int v28; // r8d
int v29; // r8d
char *v30; // rcx
unsigned __int64 v31; // rax
unsigned __int64 v32; // rdx
unsigned __int64 v33; // rcx
char v34; // bl
void *v35; // rcx
void *Block[2]; // [rsp+30h] [rbp-28h] BYREF
__int64 v37; // [rsp+40h] [rbp-18h]
v3 = a1;
v4 = *((_QWORD *)a1 + 2);
if ( !v4 )
return 1;
v6 = (__int16 *)a1;
if ( *((_QWORD *)a1 + 3) <= 7u )
{
v7 = a1;
}
else
{
v6 = *(__int16 **)a1;
v7 = *(char **)a1;
a1 = *(char **)a1;
}
v8 = (unsigned __int16 *)&v7[2 * v4];
*(_OWORD *)Block = 0;
v37 = 0;
v9 = *v6;
if ( *v6 == -2 )
{
sub_180048300((__int64)Block, nullptr, v6, ((char *)v8 - (char *)v6) >> 1);
v10 = ((char *)Block[1] - (char *)Block[0]) >> 1;
v11 = 0;
if ( v10 )
{
if ( v10 < 0x20 )
goto LABEL_68;
if ( dword_1801AE328 < 2 )
goto LABEL_68;
v12 = v10 - ((((char *)Block[1] - (char *)Block[0]) >> 1) & 0x1F);
v13 = 32;
si128 = _mm_load_si128((const __m128i *)&xmmword_180107C50);
do
{
*(__m128i *)((char *)Block[0] + v13 - 32) = _mm_shuffle_epi8(
_mm_loadu_si128((const __m128i *)((char *)Block[0] + v13 - 32)),
si128);
*(__m128i *)((char *)Block[0] + v13 - 16) = _mm_shuffle_epi8(
_mm_loadu_si128((const __m128i *)((char *)Block[0] + v13 - 16)),
si128);
*(__m128i *)((char *)Block[0] + v13) = _mm_shuffle_epi8(
_mm_loadu_si128((const __m128i *)((char *)Block[0] + v13)),
si128);
*(__m128i *)((char *)Block[0] + v13 + 16) = _mm_shuffle_epi8(
_mm_loadu_si128((const __m128i *)((char *)Block[0] + v13 + 16)),
si128);
v11 += 32;
v13 += 64;
}
while ( v11 != v12 );
if ( v11 != v10 )
{
LABEL_68:
do
{
*((_WORD *)Block[0] + v11) = __ROR2__(*((_WORD *)Block[0] + v11), 8);
++v11;
}
while ( v11 != v10 );
}
}
a1 = (char *)Block[0];
v8 = (unsigned __int16 *)((char *)Block[0] + 2 * (((char *)Block[1] - (char *)Block[0]) >> 1));
v9 = *(_WORD *)Block[0];
}
v15 = (unsigned __int16 *)(a1 + 2);
if ( v9 != -257 )
v15 = (unsigned __int16 *)a1;
v16 = 4LL * *((_QWORD *)v3 + 2) + 1;
v17 = a2 + 2;
v18 = a2[2];
if ( v16 > v18 )
{
sub_180078E30(a2, v16 - v18, 0);
v19 = a2 + 2;
}
else
{
*v17 = v16;
v19 = a2 + 2;
if ( a2[3] <= 0xFu )
*((_BYTE *)a2 + v16) = 0;
else
*(_BYTE *)(*a2 + v16) = 0;
}
v20 = (char *)a2;
if ( a2[3] > 0xFu )
{
v20 = (char *)*a2;
v17 = v19;
}
v21 = &v20[*v17];
if ( v15 >= v8 )
{
LABEL_49:
v30 = (char *)a2;
v31 = a2[3];
if ( v31 > 0xF )
v30 = (char *)*a2;
v32 = v20 - v30;
v33 = a2[2];
if ( v32 > v33 )
{
sub_180078E30(a2, v32 - v33, 0);
}
else
{
a2[2] = v32;
if ( v31 > 0xF )
a2 = (_QWORD *)*a2;
*((_BYTE *)a2 + v32) = 0;
}
v34 = 1;
goto LABEL_60;
}
while ( 1 )
{
v22 = *v15++;
if ( v22 - 55296 <= 0x3FF )
break;
if ( v22 - 56320 <= 0x3FF )
goto LABEL_55;
LABEL_30:
if ( v22 < 0x80 )
{
v24 = 1;
goto LABEL_39;
}
if ( v22 < 0x800 )
{
v24 = 2;
goto LABEL_39;
}
if ( v22 >= 0x10000 )
{
if ( v22 < 0x110000 )
{
v24 = 4;
goto LABEL_39;
}
v22 = 65533;
}
v24 = 3;
LABEL_39:
v25 = v24;
v26 = &v20[v24];
if ( v26 > v21 )
goto LABEL_55;
v27 = v24 - 1;
if ( !v27 )
goto LABEL_47;
v28 = v27 - 1;
if ( !v28 )
goto LABEL_46;
v29 = v28 - 1;
if ( !v29 )
goto LABEL_45;
if ( v29 == 1 )
{
*--v26 = v22 & 0x3F | 0x80;
v22 >>= 6;
LABEL_45:
*--v26 = v22 & 0x3F | 0x80;
v22 >>= 6;
LABEL_46:
*--v26 = v22 & 0x3F | 0x80;
v22 >>= 6;
LABEL_47:
*--v26 = byte_18010AB78[v25] | v22;
}
v20 = &v26[v25];
if ( v15 >= v8 )
goto LABEL_49;
}
if ( v15 < v8 )
{
v23 = *v15;
if ( (unsigned int)(v23 - 56320) <= 0x3FF )
{
v22 = v23 + (v22 << 10) - 56613888;
++v15;
goto LABEL_30;
}
}
LABEL_55:
a2[2] = 0;
if ( a2[3] > 0xFu )
a2 = (_QWORD *)*a2;
*(_BYTE *)a2 = 0;
v34 = 0;
LABEL_60:
v35 = Block[0];
if ( Block[0] )
{
if ( (unsigned __int64)(2 * ((signed __int64)(v37 - (unsigned __int64)Block[0]) >> 1)) >= 0x1000 )
{
v35 = *((void **)Block[0] - 1);
if ( (unsigned __int64)((char *)Block[0] - (char *)v35 - 8) > 0x1F )
invoke_watson(nullptr, nullptr, nullptr, 0, 0);
}
j_j_free_0(v35);
}
return v34;
}