//
// cocos2d::cc_utf8_to_utf16 from 0xb1d2c4 to 0xb1d434 (368 bytes)
//
// 2 xrefs:
// > cocos2d::CCLabelBMFont::setString @ 0xae275c
// > ??> @ 0xbd120
//
// 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
//
unsigned __int16 *cocos2d::cc_utf8_to_utf16(const char *a1, int *a2)
{
unsigned __int64 v3; // x2
__int64 v4; // x2
unsigned __int64 v5; // x0
void *v6; // x19
char *v7; // x0
void *v9; // x0
unsigned int *v10; // x2
int v11; // w1
size_t v12; // [xsp+48h] [xbp+48h]
_QWORD *v13; // [xsp+60h] [xbp+60h] BYREF
void *v14; // [xsp+68h] [xbp+68h] BYREF
__int64 v15; // [xsp+70h] [xbp+70h] BYREF
if ( !a1 )
return nullptr;
sub_D153B8((int)&v13, (char *)a1);
v3 = *(v13 - 3) + 1LL;
if ( v3 <= 0x3F80000000000000LL )
{
v5 = 2 * v3;
v4 = 2 * v3;
}
else
{
v4 = 2 * v3;
v5 = -1;
}
v12 = v4;
v6 = (void *)operator new[](v5);
memset(v6, 0, v12);
v14 = v6;
v15 = 0;
if ( !*(v13 - 3) || (unsigned __int8)llvm::ConvertUTF8toWide(2, (const void **)&v13, &v14, &v15) )
{
if ( a2 )
*a2 = cocos2d::cc_wcslen((const unsigned __int16 *)v6);
}
else
{
v9 = v6;
v6 = nullptr;
operator delete[](v9);
}
v7 = (char *)(v13 - 3);
if ( v13 - 3 != &qword_124B6B0 )
{
if ( &pthread_create )
{
v10 = (unsigned int *)(v13 - 1);
do
v11 = __ldaxr(v10);
while ( __stlxr(v11 - 1, v10) );
}
else
{
v11 = *((_DWORD *)v13 - 2);
*((_DWORD *)v13 - 2) = v11 - 1;
}
if ( v11 <= 0 )
operator delete(v7);
}
return (unsigned __int16 *)v6;
}