//
// sub_180042670 from 0x180042670 to 0x1800427ef (383 bytes)
//
// 2 xrefs:
// > sub_1800453A0 @ 0x180045788
// > ??> @ 0x1801f8040
//
// 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_180042670(__int64 a1, __int64 a2, __int64 *a3, __int64 a4, _DWORD *a5)
{
__int64 v9; // r8
int v11; // esi
__int64 v12; // rbx
char v13; // cl
unsigned int v14[10]; // [rsp+20h] [rbp-28h] BYREF
if ( (unsigned int)sub_180041D20(a1, a2, v14, 8u) )
{
v9 = v14[0];
if ( a4 )
*(_BYTE *)((unsigned int)(*a5)++ + a4) = v14[0];
if ( (v9 & 0x80u) == 0LL )
{
*a3 = v9;
return 1;
}
if ( (v9 & 0xC0) != 0 && (v9 & 0x20) == 0 )
{
v11 = 1;
v12 = v9 & 0x1F;
goto LABEL_24;
}
if ( (v9 & 0xE0) != 0 && (v9 & 0x10) == 0 )
{
v11 = 2;
v12 = v9 & 0xF;
goto LABEL_24;
}
if ( (v9 & 0xF0) != 0 && (v9 & 8) == 0 )
{
v11 = 3;
v12 = v9 & 7;
goto LABEL_24;
}
if ( (v9 & 0xF8) != 0 && (v9 & 4) == 0 )
{
v11 = 4;
v12 = v9 & 3;
goto LABEL_24;
}
if ( (v9 & 0xFC) != 0 && (v9 & 2) == 0 )
{
v11 = 5;
v12 = v9 & 1;
goto LABEL_24;
}
if ( (v9 & 0xFE) == 0 || (v9 & 1) != 0 )
{
LABEL_30:
*a3 = -1;
return 1;
}
v12 = 0;
v11 = 6;
LABEL_24:
while ( (unsigned int)sub_180041D20(a1, a2, v14, 8u) )
{
v13 = v14[0];
if ( a4 )
*(_BYTE *)((unsigned int)(*a5)++ + a4) = v14[0];
if ( (v13 & 0xC0) != 0x80 )
goto LABEL_30;
v12 = (v12 << 6) | v13 & 0x3F;
if ( !--v11 )
{
*a3 = v12;
return 1;
}
}
}
return 0;
}