//
// sub_631710 from 0x631710 to 0x6318c6 (438 bytes)
//
// 3 xrefs:
// > sub_6318F0 @ 0x631942
// > sub_631978 @ 0x6319b2
// > sub_631978 @ 0x631a4c
//
// 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 sub_631710(int *a1, int a2)
{
int v4; // r10
int v5; // r11
int v6; // r6
void *v7; // r0
void *v8; // r7
unsigned int v9; // r0
unsigned int v10; // r5
const char *v11; // r2
int v12; // r0
int v14; // r3
int v15; // r11
int v16; // r10
v4 = *(_DWORD *)(a2 + 152);
v5 = *(_DWORD *)(a2 + 148);
v6 = a2 + 148;
v7 = off_ABAEAC(0x4000u);
v8 = v7;
if ( v7 )
{
*(_DWORD *)(a2 + 160) = v7;
*(_DWORD *)(a2 + 164) = 0x4000;
v9 = inflate(v6, 2);
v10 = v9;
if ( v9 <= 1 )
goto LABEL_10;
if ( v9 == -3 )
{
inflateEnd(v6);
if ( inflateInit2_(v6, -15, "1.2.8", 56) )
{
off_ABAEB0(v8);
v11 = *(const char **)(a2 + 172);
v12 = *a1;
if ( v11 )
goto LABEL_8;
goto LABEL_25;
}
*(_DWORD *)(a2 + 148) = v5;
*(_DWORD *)(a2 + 152) = v4;
while ( 1 )
{
*(_DWORD *)(a2 + 160) = v8;
*(_DWORD *)(a2 + 164) = 0x4000;
v10 = inflate(v6, 2);
if ( v10 > 1 )
break;
LABEL_10:
v14 = *(_DWORD *)(a2 + 164);
if ( v14 != 0x4000 )
{
v15 = *(unsigned __int8 *)(a2 + 229);
if ( !*(_BYTE *)(a2 + 229) )
{
v16 = sub_618748((int)a1, 1, (const char *)v8, 0x4000 - v14);
if ( v16 )
{
off_ABAEB0(v8);
inflateEnd(v6);
*(_DWORD *)(a2 + 144) = v15;
return v16;
}
}
}
if ( v10 == 1 )
{
off_ABAEB0(v8);
if ( !inflateEnd(v6) )
{
inflateEnd(v6);
*(_DWORD *)(a2 + 144) = 0;
return 0;
}
v11 = *(const char **)(a2 + 172);
v12 = *a1;
if ( v11 )
goto LABEL_8;
goto LABEL_25;
}
if ( !*(_DWORD *)(a2 + 152) )
{
off_ABAEB0(v8);
return 0;
}
}
}
off_ABAEB0(v8);
v11 = *(const char **)(a2 + 172);
v12 = *a1;
if ( v11 )
{
LABEL_8:
sub_6180F8(v12, "Error while processing content unencoding: %s", v11);
LABEL_9:
inflateEnd(v6);
*(_DWORD *)(a2 + 144) = 0;
return 61;
}
LABEL_25:
sub_6180F8(v12, "Error while processing content unencoding: Unknown failure within decompression software.");
goto LABEL_9;
}
inflateEnd(v6);
*(_DWORD *)(a2 + 144) = 0;
return 27;
}