//
// sub_1800954A0 from 0x1800954a0 to 0x1800957da (826 bytes)
//
// 2 xrefs:
// > cocos2d::cc_utf16_to_utf8 @ 0x180094f26
// > ??> @ 0x1801b6834
//
// 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
//
// Hidden C++ exception states: #wind=1
char __fastcall sub_1800954A0(unsigned __int16 *a1, char *a2)
{
__int64 v4; // rcx
unsigned __int16 *v6; // r8
__int64 *v7; // rdx
unsigned __int16 *v8; // rax
unsigned __int16 *v9; // r15
__int64 v10; // rbp
unsigned __int16 v11; // cx
_BYTE *v12; // r8
unsigned __int16 *v13; // rsi
unsigned __int64 v14; // rdx
__int64 v15; // rcx
unsigned __int64 v16; // r9
__m128i *v17; // rax
unsigned __int16 *v18; // rbx
char *v19; // rdx
char *v20; // r10
unsigned int v21; // eax
int v22; // r8d
__int64 v23; // r8
__int64 v24; // r9
char *v25; // rdx
int v26; // r8d
int v27; // r8d
int v28; // r8d
char *v29; // rax
char v30; // bl
char *v31; // rax
void *Block[2]; // [rsp+20h] [rbp-38h] BYREF
__int64 v33; // [rsp+30h] [rbp-28h]
v4 = *((_QWORD *)a1 + 2);
if ( !v4 )
return 1;
v6 = a1;
if ( *((_QWORD *)a1 + 3) <= 7u )
{
v7 = (__int64 *)a1;
}
else
{
v6 = *(unsigned __int16 **)a1;
v7 = *(__int64 **)a1;
}
v8 = v6;
v9 = (unsigned __int16 *)v7 + v4;
*(_OWORD *)Block = 0;
v10 = 0;
v33 = 0;
v11 = *v6;
if ( *v6 == 0xFFFE )
{
sub_180046C80(Block, nullptr, v6, v9 - v6);
v12 = Block[1];
v13 = (unsigned __int16 *)Block[0];
v14 = ((char *)Block[1] - (char *)Block[0]) >> 1;
v15 = 0;
if ( v14 )
{
if ( v14 < 0x20 )
goto LABEL_59;
if ( dword_1801A4360 < 2 )
goto LABEL_59;
v16 = v14 - ((((char *)Block[1] - (char *)Block[0]) >> 1) & 0x1F);
v17 = (__m128i *)((char *)Block[0] + 32);
do
{
v17[-2] = _mm_shuffle_epi8(_mm_loadu_si128(v17 - 2), (__m128i)xmmword_1801044E0);
v17[-1] = _mm_shuffle_epi8(_mm_loadu_si128(v17 - 1), (__m128i)xmmword_1801044E0);
*v17 = _mm_shuffle_epi8(_mm_loadu_si128(v17), (__m128i)xmmword_1801044E0);
v17[1] = _mm_shuffle_epi8(_mm_loadu_si128(v17 + 1), (__m128i)xmmword_1801044E0);
v15 += 32;
v17 += 4;
}
while ( v15 != v16 );
if ( v15 != v14 )
{
LABEL_59:
do
{
v13[v15] = __ROR2__(v13[v15], 8);
++v15;
}
while ( v15 != v14 );
}
}
v8 = v13;
v9 = &v13[(v12 - (_BYTE *)v13) >> 1];
v11 = *v13;
v10 = v33;
}
else
{
v13 = (unsigned __int16 *)Block[0];
}
v18 = v8 + 1;
if ( v11 != 0xFEFF )
v18 = v8;
sub_180078760(a2, 4LL * *((_QWORD *)a1 + 2) + 1, 0);
v19 = a2;
if ( *((_QWORD *)a2 + 3) > 0xFu )
v19 = *(char **)a2;
v20 = &v19[*((_QWORD *)a2 + 2)];
if ( v18 >= v9 )
{
LABEL_45:
v29 = a2;
if ( *((_QWORD *)a2 + 3) > 0xFu )
v29 = *(char **)a2;
sub_180078760(a2, v19 - v29, 0);
v30 = 1;
goto LABEL_48;
}
while ( 1 )
{
v21 = *v18++;
if ( v21 - 55296 <= 0x3FF )
break;
if ( v21 - 56320 <= 0x3FF )
goto LABEL_52;
LABEL_26:
if ( v21 < 0x80 )
{
v23 = 1;
goto LABEL_35;
}
if ( v21 < 0x800 )
{
v23 = 2;
goto LABEL_35;
}
if ( v21 >= 0x10000 )
{
if ( v21 < 0x110000 )
{
v23 = 4;
goto LABEL_35;
}
v21 = 65533;
}
v23 = 3;
LABEL_35:
v24 = v23;
v25 = &v19[v23];
if ( v25 > v20 )
goto LABEL_52;
v26 = v23 - 1;
if ( !v26 )
goto LABEL_43;
v27 = v26 - 1;
if ( !v27 )
goto LABEL_42;
v28 = v27 - 1;
if ( !v28 )
goto LABEL_41;
if ( v28 == 1 )
{
*--v25 = v21 & 0x3F | 0x80;
v21 >>= 6;
LABEL_41:
*--v25 = v21 & 0x3F | 0x80;
v21 >>= 6;
LABEL_42:
*--v25 = v21 & 0x3F | 0x80;
v21 >>= 6;
LABEL_43:
*--v25 = byte_1801044D8[v24] | v21;
}
v19 = &v25[v24];
if ( v18 >= v9 )
goto LABEL_45;
}
if ( v18 < v9 )
{
v22 = *v18;
if ( (unsigned int)(v22 - 56320) <= 0x3FF )
{
v21 = v22 + (v21 << 10) - 56613888;
++v18;
goto LABEL_26;
}
}
LABEL_52:
*((_QWORD *)a2 + 2) = 0;
if ( *((_QWORD *)a2 + 3) > 0xFu )
a2 = *(char **)a2;
*a2 = 0;
v30 = 0;
LABEL_48:
if ( v13 )
{
v31 = (char *)v13;
if ( (unsigned __int64)(2 * ((v10 - (__int64)v13) >> 1)) >= 0x1000 )
{
v13 = *((unsigned __int16 **)v13 - 1);
if ( (unsigned __int64)(v31 - (char *)v13 - 8) > 0x1F )
invalid_parameter_noinfo_noreturn();
}
j_j_free_0(v13);
}
return v30;
}