//
// ConvertUTF32toUTF16 from 0x5e9ce8 to 0x5e9d74 (140 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
//
int __fastcall ConvertUTF32toUTF16(unsigned int **a1, unsigned int a2, _WORD **a3, unsigned int a4, int a5)
{
_WORD *v5; // r4
unsigned int *v7; // r9
int result; // r0
unsigned int v9; // r5
unsigned int v10; // r5
v5 = *a3;
v7 = *a1;
result = 0;
while ( (unsigned int)v7 < a2 )
{
if ( (unsigned int)v5 >= a4 )
goto LABEL_17;
v9 = *v7;
if ( *v7 < 0x10000 )
{
if ( v9 - 55296 >= 0x800 )
{
*v5 = v9;
}
else
{
if ( !a5 )
{
result = 3;
break;
}
LABEL_12:
*v5 = -3;
}
++v5;
goto LABEL_16;
}
if ( v9 <= 0x10FFFF )
{
if ( a4 <= (unsigned int)(v5 + 1) )
{
LABEL_17:
result = 2;
break;
}
v10 = v9 - 0x10000;
*v5 = (v10 >> 10) - 10240;
v5[1] = (v10 & 0x3FF) - 9216;
v5 += 2;
}
else
{
if ( a5 )
goto LABEL_12;
result = 3;
}
LABEL_16:
++v7;
}
*a1 = v7;
*a3 = v5;
return result;
}