//
// cocos2d::cc_utf16_to_utf8 from 0x5ea858 to 0x5eaa7e (550 bytes)
//
// 0 xrefs:
//
// 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
//
char *cocos2d::cc_utf16_to_utf8(const unsigned __int16 *a1, int a2, int *a3, int *a4)
{
int v4; // r10
int v5; // r1
unsigned __int16 *v6; // r5
unsigned int v7; // r2
unsigned int v8; // r4
unsigned int v9; // r8
unsigned int v10; // r11
int v11; // r2
unsigned int v12; // r0
unsigned int v13; // r2
char *v14; // r0
char *v15; // r4
int v16; // r1
void *v17; // r11
int v18; // r2
bool v19; // zf
unsigned __int16 *v20; // r2
unsigned __int16 *v21; // r0
unsigned __int16 *v22; // r2
char *v23; // r4
char *v24; // r0
unsigned __int16 *v25; // r0
unsigned int *v26; // r3
int v27; // r2
unsigned int *v29; // r2
int v30; // r1
int v31; // [sp+4h] [bp-28h]
unsigned __int16 v34; // [sp+10h] [bp-1Ch]
unsigned __int16 *v35; // [sp+1Ch] [bp-10h] BYREF
void *v36; // [sp+20h] [bp-Ch] BYREF
if ( !a1 )
return nullptr;
v4 = 0;
v35 = (unsigned __int16 *)&unk_AC93B0;
v31 = cocos2d::cc_wcslen(a1);
while ( v4 < v31 )
{
v6 = v35;
v7 = *((_DWORD *)v35 - 3);
v8 = *((_DWORD *)v35 - 2);
v9 = v7 + 1;
v34 = a1[v4];
if ( v7 + 1 > v8 || (v5 = *((_DWORD *)v35 - 1), v5 > 0) )
{
if ( v7 < v9 )
++v7;
v10 = v7;
if ( v7 > 0x1FFFFFFE )
sub_7731C4("basic_string::_S_create", v5, v7);
if ( v7 > v8 && v7 < 2 * v8 )
v10 = 2 * v8;
v11 = 2 * (v10 + 1);
v12 = v11 + 12;
v13 = v11 + 28;
if ( v13 > 0x1000 && v10 > v8 )
{
v10 += (4096 - (v13 & 0xFFF)) >> 1;
if ( v10 >= 0x1FFFFFFE )
v10 = 536870910;
v12 = 2 * v10 + 14;
}
v14 = (char *)operator new(v12);
*((_DWORD *)v14 + 2) = 0;
v15 = v14;
v16 = *((_DWORD *)v6 - 3);
*((_DWORD *)v14 + 1) = v10;
v17 = v14 + 12;
if ( v16 )
{
if ( v16 == 1 )
*((_WORD *)v14 + 6) = *v6;
else
std::__copy_move::__copy_m(v6, (int)&v6[v16], v17);
}
v18 = *((_DWORD *)v6 - 3);
v19 = v15 == (char *)&std::wstring::_Rep::_S_empty_rep_storage;
if ( v15 != (char *)&std::wstring::_Rep::_S_empty_rep_storage )
{
*((_DWORD *)v15 + 2) = 0;
*(_DWORD *)v15 = v18;
v15 += 2 * v18;
}
v20 = v35;
if ( !v19 )
*((_WORD *)v15 + 6) = 0;
v21 = v20 - 6;
if ( v20 - 6 != (unsigned __int16 *)&std::wstring::_Rep::_S_empty_rep_storage )
{
if ( &pthread_create )
{
v29 = (unsigned int *)(v20 - 2);
__dmb(0xFu);
do
v30 = __ldrex(v29);
while ( __strex(v30 - 1, v29) );
__dmb(0xFu);
}
else
{
v30 = *((_DWORD *)v20 - 1);
*((_DWORD *)v20 - 1) = v30 - 1;
}
if ( v30 <= 0 )
operator delete(v21);
}
v35 = (unsigned __int16 *)v17;
}
v22 = v35;
++v4;
v35[*((_DWORD *)v35 - 3)] = v34;
v5 = (int)(v22 - 6);
if ( v22 - 6 != (unsigned __int16 *)&std::wstring::_Rep::_S_empty_rep_storage )
{
*((_DWORD *)v22 - 1) = 0;
*((_DWORD *)v22 - 3) = v9;
v22[v9] = 0;
}
}
v36 = &unk_ACDDA8;
if ( !v31 || llvm::convertUTF16ToUTF8String(&v35, (int *)&v36) )
{
v24 = (char *)operator new[](*((_DWORD *)v36 - 3) + 1);
v24[*((_DWORD *)v36 - 3)] = 0;
v23 = v24;
if ( v31 > 0 )
memcpy(v24, v36, *((_DWORD *)v36 - 3));
if ( a2 )
*(_DWORD *)a2 = *((_DWORD *)v36 - 3);
}
else
{
v23 = nullptr;
}
sub_774008(&v36);
v25 = v35 - 6;
if ( v35 - 6 != (unsigned __int16 *)&std::wstring::_Rep::_S_empty_rep_storage )
{
if ( &pthread_create )
{
v26 = (unsigned int *)(v35 - 2);
__dmb(0xFu);
do
v27 = __ldrex(v26);
while ( __strex(v27 - 1, v26) );
__dmb(0xFu);
}
else
{
v27 = *((_DWORD *)v35 - 1);
*((_DWORD *)v35 - 1) = v27 - 1;
}
if ( v27 <= 0 )
operator delete(v25);
}
return v23;
}