//
// inflateSync from 0xcc51a4 to 0xcc53fc (600 bytes)
//
// 1 xrefs:
// > ??> @ 0x619c8
//
// 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 inflateSync(__int64 *a1)
{
__int64 v1; // x20
unsigned int v2; // w5
int v3; // w1
unsigned int v4; // w2
unsigned __int64 v5; // x1
unsigned __int64 v6; // x3
unsigned int v7; // w5
unsigned int v8; // w1
unsigned int v9; // w2
_BOOL4 v10; // w3
int v11; // w3
__int64 v12; // x19
unsigned int v13; // w2
_BOOL4 v14; // w4
int v15; // w4
__int64 v16; // x21
bool v17; // zf
__int64 v18; // x19
int v19; // w1
__int64 v20; // x21
__int64 v22; // x22
_BYTE v24[8]; // [xsp+38h] [xbp+38h]
if ( !a1 )
return 4294967294LL;
v1 = a1[7];
if ( !v1 )
return 4294967294LL;
v2 = *((_DWORD *)a1 + 2);
if ( !v2 && *(_DWORD *)(v1 + 80) <= 7u )
return 4294967291LL;
if ( *(_DWORD *)v1 == 31 )
{
v8 = *(_DWORD *)(v1 + 132);
LOBYTE(v10) = v8 <= 3;
}
else
{
v3 = *(_DWORD *)(v1 + 80);
v4 = v3 & 0xFFFFFFF8;
v5 = *(_QWORD *)(v1 + 72) << (v3 & 7);
*(_DWORD *)v1 = 31;
*(_QWORD *)(v1 + 72) = v5;
*(_DWORD *)(v1 + 80) = v4;
if ( v4 > 7 )
{
v24[0] = v5;
v6 = v5 >> 8;
if ( v4 - 8 > 7 )
{
v24[1] = BYTE1(v5);
v6 = v5 >> 16;
if ( v4 - 16 > 7 )
{
v24[2] = BYTE2(v5);
v6 = v5 >> 24;
if ( v4 - 24 > 7 )
{
v24[3] = BYTE3(v5);
v6 = HIDWORD(v5);
}
}
}
*(_QWORD *)(v1 + 72) = v6;
v7 = ((v4 - 8) >> 3) + 1;
*(_DWORD *)(v1 + 80) = 0;
v8 = 0;
v9 = 0;
while ( 1 )
{
v11 = v8 >= 2 ? 255 : 0;
if ( (unsigned __int8)v24[v9] == v11 )
break;
v8 = 4 - v8;
LOBYTE(v10) = 1;
if ( !v24[v9] )
{
v10 = v8 <= 3;
goto LABEL_12;
}
v8 = 0;
++v9;
LABEL_13:
if ( v9 >= v7 )
goto LABEL_20;
}
v10 = ++v8 <= 3;
LABEL_12:
++v9;
if ( !v10 )
goto LABEL_20;
goto LABEL_13;
}
LOBYTE(v10) = 1;
v8 = 0;
LABEL_20:
*(_DWORD *)(v1 + 132) = v8;
v2 = *((_DWORD *)a1 + 2);
}
v12 = *a1;
if ( !v10 || v2 == 0 )
{
v16 = 0;
v13 = 0;
goto LABEL_33;
}
v13 = 0;
do
{
if ( v8 >= 2 )
v15 = 255;
else
v15 = 0;
if ( *(unsigned __int8 *)(v12 + v13) == v15 )
{
v14 = ++v8 <= 3;
}
else
{
v8 = 4 - v8;
if ( *(_BYTE *)(v12 + v13) )
{
v8 = 0;
++v13;
continue;
}
v14 = v8 <= 3;
}
++v13;
if ( !v14 )
break;
}
while ( v13 < v2 );
v16 = v13;
LABEL_33:
*(_DWORD *)(v1 + 132) = v8;
v17 = v8 == 4;
v18 = v12 + v16;
v19 = *((_DWORD *)a1 + 2);
v20 = v16 + a1[2];
*a1 = v18;
a1[2] = v20;
*((_DWORD *)a1 + 2) = v19 - v13;
if ( !v17 )
return 4294967293LL;
v22 = a1[5];
inflateReset(a1);
a1[2] = v20;
a1[5] = v22;
*(_DWORD *)v1 = 11;
return 0;
}