//
// sub_BEA9C0 from 0xbea9c0 to 0xbeab30 (368 bytes)
//
// 3 xrefs:
// > png_compress_IDAT @ 0xbebadc
// > png_compress_IDAT @ 0xbebb88
// > png_compress_IDAT @ 0xbebd34
//
// 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_BEA9C0(__int64 a1)
{
unsigned __int64 v1; // x7
unsigned int v2; // w6
__int64 result; // x0
unsigned int v4; // w10
int v5; // w8
int v6; // w12
int v7; // w5
int v8; // w4
int v9; // w2
unsigned int v10; // w1
unsigned int v11; // w2
unsigned int v12; // w4
int v13; // w19
_BOOL4 v14; // w21
int v15; // w1
int v16; // w18
_BOOL4 v17; // w17
int v18; // w20
unsigned int v19; // w2
unsigned __int64 v20; // x3
unsigned __int64 v21; // x4
unsigned __int64 v22; // x3
v1 = *(_QWORD *)(a1 + 576);
v2 = *(_DWORD *)(a1 + 564);
if ( v1 > 0x7FFF || v2 > 0x7FFF )
return 0xFFFFFFFFLL;
if ( !*(_BYTE *)(a1 + 684) )
return v2 + v1 * v2;
v4 = *(unsigned __int8 *)(a1 + 690);
v5 = 1;
v6 = *(_DWORD *)(a1 + 560);
v7 = 0;
result = 0;
do
{
v8 = (7 - v7) >> 1;
v9 = ((v7 & 1) << (3 - (v5 >> 1))) & 7;
v10 = (1 << v8) - 1 - v9 + v6;
v11 = 7 - v9 + v6;
if ( v7 <= 1 )
LOBYTE(v8) = 3;
else
v11 = v10;
v12 = v11 >> v8;
v13 = (8 - v7) >> 1;
v14 = v12 != 0 && v4 > 7;
v15 = (!(v7 & 1) << (3 - (v7 >> 1))) & 7;
v16 = v14 || v12 != 0 && v4 <= 7;
v17 = v7 > 2;
v18 = v16 & v17;
v19 = 7 - v15 + v2;
if ( (v16 & v17) != 0 )
v19 = (1 << v13) - 1 - v15 + v2;
v20 = v12 * (unsigned __int64)v4 + 7;
v21 = v12 * (unsigned __int64)(v4 >> 3) + 1;
if ( !v18 )
LOBYTE(v13) = 3;
v22 = v20 >> 3;
if ( !v14 )
v21 = v22 + 1;
++v7;
++v5;
if ( v18 | v16 & !v17 )
result += (v19 >> v13) * v21;
}
while ( v7 != 7 );
return result;
}