//
// sub_B4B7FC from 0xb4b7fc to 0xb4b9f4 (504 bytes)
//
// 2 xrefs:
// > pugi::as_wide @ 0xb5b444
// > pugi::as_wide @ 0xb5b470
//
// 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 **__usercall sub_B4B7FC@(unsigned __int8 *a1@, unsigned __int64 a2@, int **a3@)
{
unsigned __int64 v6; // x0
__int64 v7; // x19
unsigned __int8 *v8; // x1
int v9; // w2
int *v11; // x2
if ( !a2 )
{
*a3 = (int *)&unk_124B6E8;
sub_D1D800(a3, 0, 0);
return a3;
}
v6 = a2;
v7 = 0;
v8 = a1;
while ( 1 )
{
while ( 1 )
{
LABEL_3:
while ( 1 )
{
v9 = *v8;
if ( (v9 & 0x80) == 0 )
break;
if ( (unsigned int)(v9 - 192) > 0x1F || v6 <= 1 )
{
if ( (unsigned int)(v9 - 224) > 0xF || v6 <= 2 )
{
if ( (unsigned int)(v9 - 240) > 7
|| v6 <= 3
|| (v8[1] & 0xC0) != 0x80
|| (v8[2] & 0xC0) != 0x80
|| (v8[3] & 0xC0) != 0x80 )
{
goto LABEL_21;
}
v6 -= 4LL;
++v7;
v8 += 4;
if ( !v6 )
goto LABEL_11;
}
else
{
if ( (v8[1] & 0xC0) != 0x80 || (v8[2] & 0xC0) != 0x80 )
goto LABEL_21;
v6 -= 3LL;
++v7;
v8 += 3;
if ( !v6 )
goto LABEL_11;
}
}
else if ( (v8[1] & 0xC0) == 0x80 )
{
v6 -= 2LL;
++v7;
v8 += 2;
if ( !v6 )
goto LABEL_11;
}
else
{
LABEL_21:
--v6;
++v8;
if ( !v6 )
goto LABEL_11;
}
}
++v7;
--v6;
if ( ((unsigned __int64)(v8 + 1) & 3) == 0 && v6 > 3 )
break;
++v8;
if ( !v6 )
goto LABEL_11;
}
if ( (*(_DWORD *)++v8 & 0x80808080) == 0 )
{
while ( 1 )
{
v6 -= 4LL;
v8 += 4;
v7 += 4;
if ( v6 <= 3 )
break;
if ( (*(_DWORD *)v8 & 0x80808080) != 0 )
goto LABEL_3;
}
if ( !v6 )
break;
}
}
LABEL_11:
*a3 = (int *)&unk_124B6E8;
sub_D1D800(a3, v7, 0);
if ( v7 )
{
v11 = *a3;
if ( (*(*a3 - 2) & 0x80000000) == 0 )
{
sub_D1B6B8(a3);
v11 = *a3;
}
sub_B4A9BC(a1, a2, v11);
}
return a3;
}