//
// sub_10065F070 from 0x10065f070 to 0x10065f2c4 (596 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
//
__int64 __fastcall sub_10065F070(unsigned int **a1, unsigned __int64 a2, __int64 *a3, unsigned __int64 a4, int a5)
{
unsigned int *v5; // r9
__int64 v6; // r10
__int64 result; // rax
unsigned __int64 v8; // r13
unsigned int v9; // r15d
unsigned __int16 v10; // r12
unsigned __int64 v11; // r13
unsigned int v12; // r15d
unsigned __int16 v13; // r12
v5 = *a1;
v6 = *a3;
result = 0;
if ( (unsigned __int64)*a1 < a2 )
{
result = 0;
if ( a5 )
{
while ( 2 )
{
v9 = *v5;
v10 = 1;
if ( *v5 >= 0x80 )
{
v10 = 2;
if ( v9 >= 0x800 )
{
v10 = 3;
if ( v9 >= 0x10000 )
{
v10 = (v9 < 0x110000) + 3;
if ( v9 >= 0x110000 )
{
v9 = 65533;
result = 3;
}
}
}
}
v8 = v6 + v10;
if ( v8 <= a4 )
{
switch ( v10 )
{
case 1u:
goto LABEL_6;
case 2u:
goto LABEL_5;
case 3u:
goto LABEL_4;
case 4u:
*(_BYTE *)--v8 = v9 & 0x3F | 0x80;
v9 >>= 6;
LABEL_4:
*(_BYTE *)--v8 = v9 & 0x3F | 0x80;
v9 >>= 6;
LABEL_5:
*(_BYTE *)--v8 = v9 & 0x3F | 0x80;
v9 >>= 6;
LABEL_6:
++v5;
*(_BYTE *)(v8 - 1) = byte_1008230A0[v10] | v9;
v6 = v10 + v8 - 1;
if ( (unsigned __int64)v5 < a2 )
continue;
goto LABEL_30;
}
}
break;
}
}
else
{
while ( 2 )
{
v12 = *v5;
if ( (*v5 & 0xFFFFF800) == 0xD800 )
{
result = 3;
goto LABEL_30;
}
v13 = 1;
if ( v12 >= 0x80 )
{
v13 = 2;
if ( v12 >= 0x800 )
{
v13 = 3;
if ( v12 >= 0x10000 )
{
v13 = (v12 < 0x110000) + 3;
if ( v12 >= 0x110000 )
{
v12 = 65533;
result = 3;
}
}
}
}
v11 = v6 + v13;
if ( v11 <= a4 )
{
switch ( v13 )
{
case 1u:
goto LABEL_18;
case 2u:
goto LABEL_17;
case 3u:
goto LABEL_16;
case 4u:
*(_BYTE *)--v11 = v12 & 0x3F | 0x80;
v12 >>= 6;
LABEL_16:
*(_BYTE *)--v11 = v12 & 0x3F | 0x80;
v12 >>= 6;
LABEL_17:
*(_BYTE *)--v11 = v12 & 0x3F | 0x80;
v12 >>= 6;
LABEL_18:
++v5;
*(_BYTE *)(v11 - 1) = byte_1008230A0[v13] | v12;
v6 = v13 + v11 - 1;
if ( (unsigned __int64)v5 < a2 )
continue;
goto LABEL_30;
}
}
break;
}
}
result = 2;
}
LABEL_30:
*a1 = v5;
*a3 = v6;
return result;
}