//
// ConvertUTF8toUTF16 from 0xb1c73c to 0xb1c974 (568 bytes)
//
// 2 xrefs:
// > llvm::ConvertUTF8toWide @ 0xb1ccb4
// > ??> @ 0x6b4c0
//
// 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 ConvertUTF8toUTF16(
unsigned __int8 **a1,
unsigned __int64 a2,
_WORD **a3,
unsigned __int64 a4,
int a5)
{
unsigned __int8 *v5; // x27
_WORD *v8; // x26
int v9; // w24
int v10; // w23
__int64 v11; // x25
int v12; // w0
int v13; // w1
unsigned __int8 *v14; // x2
int v15; // w0
int v16; // w0
unsigned __int8 *v17; // x2
int v18; // w0
int v19; // w1
unsigned __int8 *v20; // x2
int v21; // w0
unsigned int v22; // w0
__int64 result; // x0
unsigned int v24; // w0
v5 = *a1;
v8 = *a3;
if ( (unsigned __int64)*a1 >= a2 )
{
LABEL_28:
result = 0;
}
else
{
v9 = *v5;
v10 = byte_F1C6F0[*v5];
v11 = (unsigned __int8)v10;
if ( (__int64)(a2 - (_QWORD)v5) > (unsigned __int8)v10 )
{
while ( 1 )
{
if ( !(unsigned __int8)sub_B1BED4(v5, v10 + 1) )
{
result = 3;
goto LABEL_19;
}
v12 = 0;
switch ( v10 )
{
case 0:
v20 = v5;
v21 = 0;
goto LABEL_10;
case 1:
v17 = v5;
v18 = 0;
goto LABEL_9;
case 2:
v16 = 0;
goto LABEL_8;
case 3:
v14 = v5;
v15 = 0;
goto LABEL_7;
case 4:
v13 = 0;
goto LABEL_6;
case 5:
++v5;
v13 = v9 << 6;
LABEL_6:
v14 = v5 + 1;
v15 = (*v5 + v13) << 6;
LABEL_7:
v5 = v14 + 1;
v16 = (*v14 + v15) << 6;
LABEL_8:
v17 = v5 + 1;
v18 = (*v5 + v16) << 6;
LABEL_9:
v19 = *v17;
v20 = v17 + 1;
v21 = (v19 + v18) << 6;
LABEL_10:
v5 = v20 + 1;
v12 = *v20 + v21;
break;
default:
break;
}
v22 = v12 - *(_DWORD *)&byte_F1C6F0[4 * v10 + 256];
if ( a4 <= (unsigned __int64)v8 )
{
LABEL_29:
result = 2;
v5 += ~v11;
goto LABEL_19;
}
if ( v22 <= 0xFFFF )
break;
if ( v22 > 0x10FFFF )
goto LABEL_14;
if ( a4 <= (unsigned __int64)(v8 + 1) )
goto LABEL_29;
v24 = v22 - 0x10000;
*v8 = (v24 >> 10) - 10240;
v8[1] = (v24 & 0x3FF) - 9216;
v8 += 2;
if ( (unsigned __int64)v5 >= a2 )
goto LABEL_28;
LABEL_17:
v9 = *v5;
v10 = byte_F1C6F0[*v5];
v11 = (unsigned __int8)v10;
if ( (unsigned __int8)v10 >= (__int64)(a2 - (_QWORD)v5) )
goto LABEL_18;
}
if ( v22 - 55296 <= 0x7FF )
{
LABEL_14:
if ( !a5 )
{
result = 3;
v5 += ~v11;
goto LABEL_19;
}
LOWORD(v22) = -3;
}
*v8++ = v22;
if ( (unsigned __int64)v5 >= a2 )
goto LABEL_28;
goto LABEL_17;
}
LABEL_18:
result = 1;
}
LABEL_19:
*a1 = v5;
*a3 = v8;
return result;
}