//
// sub_601C58 from 0x601c58 to 0x601d46 (238 bytes)
//
// 2 xrefs:
// > pugi::as_wide @ 0x606592
// > pugi::as_wide @ 0x6065a4
//
// 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 int **__fastcall sub_601C58(unsigned int **a1, unsigned __int8 *a2, unsigned int a3)
{
unsigned int v4; // r3
unsigned __int8 *v7; // r2
char *v8; // r4
int v9; // r1
_DWORD *v10; // r1
char *v11; // r0
int v12; // r2
_DWORD *v13; // lr
v4 = a3;
v7 = a2;
v8 = nullptr;
while ( v4 )
{
v9 = *v7;
if ( (v9 & 0x80) != 0 )
{
if ( (unsigned int)(v9 - 192) <= 0x1F && v4 > 1 && (v7[1] & 0xC0) == 0x80 )
{
v11 = v8 + 1;
v10 = v7 + 2;
v4 -= 2;
}
else if ( (unsigned int)(v9 - 224) <= 0xF && v4 > 2 && (v7[1] & 0xC0) == 0x80 && (v7[2] & 0xC0) == 0x80 )
{
v11 = v8 + 1;
v10 = v7 + 3;
v4 -= 3;
}
else if ( (unsigned int)(v9 - 240) <= 7
&& v4 > 3
&& (v7[1] & 0xC0) == 0x80
&& (v7[2] & 0xC0) == 0x80
&& (v7[3] & 0xC0) == 0x80 )
{
v11 = v8 + 1;
v10 = v7 + 4;
v4 -= 4;
}
else
{
v10 = v7 + 1;
--v4;
v11 = v8;
}
}
else
{
v10 = v7 + 1;
v11 = v8 + 1;
--v4;
if ( ((unsigned int)(v7 + 1) & 3) == 0 )
{
v12 = v8 - (char *)v7;
v13 = v10;
while ( 1 )
{
v10 = v13;
v11 = (char *)v13 + v12;
if ( v4 <= 3 )
break;
++v13;
if ( (*v10 & 0x80808080) != 0 )
break;
v4 -= 4;
}
}
}
v8 = v11;
v7 = (unsigned __int8 *)v10;
}
*a1 = (unsigned int *)&unk_ACDDB8;
sub_77871C(a1, v8, v7);
if ( v8 )
{
sub_777944(a1);
sub_6004FA(a2, a3, *a1);
}
return a1;
}