//
// sub_C5533C from 0xc5533c to 0xc55b08 (1996 bytes)
//
// 2 xrefs:
// > sub_C55E2C @ 0xc55e84
// > sub_C55E2C @ 0xc55e8c
//
// 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_C5533C(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 v3; // x3
__int64 v5; // x23
__int64 v6; // x25
int v7; // w24
_BYTE *v8; // x2
__int64 v9; // x4
int v10; // w26
__int64 v11; // x27
int32x4_t v12; // q0
int v13; // w5
__int64 v14; // x20
int v15; // w1
int v16; // w3
__int64 v17; // x0
int v18; // w19
__int64 v19; // x19
unsigned __int64 v20; // x5
__int64 v21; // x0
__int64 v22; // x6
unsigned __int64 v23; // x7
unsigned __int64 v24; // x1
__int64 v25; // x8
_BYTE *v26; // x9
__int64 v27; // x10
__int64 v28; // x3
unsigned __int64 v29; // x14
uint32x4_t *v30; // x0
unsigned __int64 v31; // x1
int8x16_t *v32; // x2
unsigned __int64 v33; // x11
bool v34; // zf
_BYTE *v35; // x2
__int64 v36; // x1
unsigned __int64 v37; // x3
unsigned int v38; // w0
__int64 v39; // x1
_DWORD *v40; // x0
__int64 v41; // x1
__int64 v42; // x0
__int64 v43; // x4
__int64 v44; // x0
__int64 v45; // x1
__int64 i; // x0
_BYTE *v48; // x3
unsigned int v49; // w1
__int64 v50; // x1
int v51; // w0
unsigned int v52; // w5
__int64 v53; // x0
int v54; // w3
int v55; // [xsp+6Ch] [xbp+6Ch]
int32x4_t v56; // [xsp+70h] [xbp+70h]
int32x4_t v57; // [xsp+70h] [xbp+70h]
v3 = a1[106];
v5 = a2;
v6 = a3 / *(int *)(v3 + 8);
if ( *(_DWORD *)v3 != 2 )
{
v5 = *(_QWORD *)(v3 + 16);
(*(void (__fastcall **)(__int64, __int64, __int64))(v3 + 32))(v3, a2, a3 / *(int *)(v3 + 8));
}
v7 = 24;
v8 = (_BYTE *)a1[113];
v9 = a1[110] - a1[114];
while ( v6 <= 0 )
{
LABEL_62:
v7 -= 8;
if ( v7 == -8 )
{
v45 = a1[110];
a1[113] = v8;
a1[114] = v45 - v9;
return 1;
}
}
v10 = 255 << v7;
v11 = 0;
v12 = vdupq_n_s32(-v7);
while ( 1 )
{
if ( v9 > 3 )
goto LABEL_7;
v50 = a1[110];
a1[113] = v8;
a1[114] = v50 - v9;
v57 = v12;
v51 = TIFFFlushData1(a1);
v12 = v57;
if ( !v51 )
return 0xFFFFFFFFLL;
v8 = (_BYTE *)a1[113];
v9 = a1[110] - a1[114];
LABEL_7:
v13 = *(_DWORD *)(v5 + 4 * v11);
v14 = v11;
v15 = v13 & v10;
LABEL_8:
v16 = v15;
v17 = v14 + 1;
v18 = 1;
while ( v6 > v17 )
{
v15 = *(_DWORD *)(v5 + 4 * v17) & v10;
if ( v15 != v16 )
{
if ( v18 > 3 )
goto LABEL_14;
v14 = v17;
goto LABEL_8;
}
++v18;
++v17;
if ( v18 == 129 )
goto LABEL_14;
}
if ( v18 < 4 )
v14 = v17;
LABEL_14:
if ( (unsigned __int64)(v14 - v11 - 2) > 1 )
{
LABEL_15:
if ( v14 <= v11 )
goto LABEL_59;
v55 = v18;
v19 = v14 - v11;
while ( 2 )
{
if ( v19 > 127 )
v19 = 127;
if ( v19 + 2 < v9 )
{
*v8 = v19;
v20 = (unsigned __int64)(v8 + 1);
v21 = v9 - 1;
v22 = v19 - 1;
if ( v19 )
goto LABEL_18;
LABEL_57:
v9 = v21;
v8 = (_BYTE *)v20;
if ( v11 >= v14 )
goto LABEL_58;
}
else
{
v41 = a1[110];
a1[113] = v8;
a1[114] = v41 - v9;
v56 = v12;
if ( !(unsigned int)TIFFFlushData1(a1) )
return 0xFFFFFFFFLL;
v8 = (_BYTE *)a1[113];
v22 = v19 - 1;
v42 = a1[114];
v43 = a1[110];
v20 = (unsigned __int64)(v8 + 1);
*v8 = v19;
v9 = v43 - v42;
v12 = v56;
v21 = v9 - 1;
if ( !v19 )
goto LABEL_57;
LABEL_18:
v23 = v5 + 4 * v11;
if ( (v23 >= (unsigned __int64)&v8[v19 + 1] || v20 >= v5 + 4 * (v19 + v11)) && (unsigned __int64)v19 > 0x13 )
{
v24 = -(__int64)((v23 >> 2) & 3) & 3;
if ( v19 <= v24 )
v24 = v19;
if ( v24 )
{
v25 = v11 + 1;
v26 = v8 + 2;
v8[1] = *(_DWORD *)v23 >> v7;
v27 = v11 + 1;
v28 = v19 - 2;
if ( v24 != 1 )
{
v26 = v8 + 3;
v27 = v11 + 2;
v8[2] = *(_DWORD *)(v23 + 4) >> v7;
v28 = v19 - 3;
if ( v24 == 3 )
{
v26 = v8 + 4;
v27 = v11 + 3;
v28 = v19 - 4;
v8[3] = *(_DWORD *)(v23 + 8) >> v7;
}
}
}
else
{
v27 = v11;
v28 = v22;
v26 = (_BYTE *)v20;
v25 = v11 + 1;
}
v29 = v24 + 1;
v30 = (uint32x4_t *)(v5 + 4 * v11 + 4 * v24);
v31 = v19 - v24;
v32 = (int8x16_t *)&v8[v29];
v33 = 16 * (((v31 - 16) >> 4) + 1);
*v32 = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(*v30, v12)), vshlq_u32(v30[1], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[2], v12)), vshlq_u32(v30[3], v12)));
if ( (v31 - 16) >> 4 )
{
v32[1] = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[4], v12)), vshlq_u32(v30[5], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[6], v12)), vshlq_u32(v30[7], v12)));
if ( (v31 - 16) >> 4 != 1 )
{
v32[2] = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[8], v12)), vshlq_u32(v30[9], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[10], v12)), vshlq_u32(v30[11], v12)));
if ( (v31 - 16) >> 4 != 2 )
{
v32[3] = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[12], v12)), vshlq_u32(v30[13], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[14], v12)), vshlq_u32(v30[15], v12)));
if ( (v31 - 16) >> 4 != 3 )
{
v32[4] = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[16], v12)), vshlq_u32(v30[17], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[18], v12)), vshlq_u32(v30[19], v12)));
if ( (v31 - 16) >> 4 != 4 )
{
v32[5] = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[20], v12)), vshlq_u32(v30[21], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[22], v12)), vshlq_u32(v30[23], v12)));
if ( (v31 - 16) >> 4 != 5 )
{
v32[6] = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[24], v12)), vshlq_u32(v30[25], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[26], v12)), vshlq_u32(v30[27], v12)));
if ( (v31 - 16) >> 4 != 6 )
v32[7] = vmovn_hight_s16(
vmovn_s16(vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[28], v12)), vshlq_u32(v30[29], v12))),
vmovn_hight_s32(vmovn_s32(vshlq_u32(v30[30], v12)), vshlq_u32(v30[31], v12)));
}
}
}
}
}
}
v34 = v33 == v31;
v35 = &v26[v33];
v36 = v27 + v33;
v37 = v28 - v33;
if ( !v34 )
{
v38 = *(_DWORD *)(v5 + 4 * v36);
v39 = 4 * v36;
v26[v33] = v38 >> v7;
if ( v37 )
{
v40 = (_DWORD *)(v5 + v39);
v35[1] = *(_DWORD *)(v5 + v39 + 4) >> v7;
if ( v37 != 1 )
{
v35[2] = v40[2] >> v7;
if ( v37 != 2 )
{
v35[3] = v40[3] >> v7;
if ( v37 != 3 )
{
v35[4] = v40[4] >> v7;
if ( v37 != 4 )
{
v35[5] = v40[5] >> v7;
if ( v37 != 5 )
{
v35[6] = v40[6] >> v7;
if ( v37 != 6 )
{
v35[7] = v40[7] >> v7;
if ( v37 != 7 )
{
v35[8] = v40[8] >> v7;
if ( v37 != 8 )
{
v35[9] = v40[9] >> v7;
if ( v37 != 9 )
{
v35[10] = v40[10] >> v7;
if ( v37 != 10 )
{
v35[11] = v40[11] >> v7;
if ( v37 != 11 )
{
v35[12] = v40[12] >> v7;
if ( v37 != 12 )
{
v35[13] = v40[13] >> v7;
if ( v37 != 13 )
v35[14] = v40[14] >> v7;
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
for ( i = 0; i != v19; ++i )
{
v48 = &v8[i];
v49 = *(_DWORD *)(v23 + 4 * i);
v48[1] = v49 >> v7;
}
v25 = v11 + 1;
}
v11 = v25 + v22;
v8 = (_BYTE *)(v20 + v19);
v9 = v9 - 2 + 1 - v19;
if ( v25 + v22 >= v14 )
{
LABEL_58:
v18 = v55;
goto LABEL_59;
}
}
v19 = v14 - v11;
continue;
}
}
v52 = v13 & v10;
v53 = v11 + 1;
do
{
v54 = *(_DWORD *)(v5 + 4 * v53++);
if ( (v10 & v54) != v52 )
goto LABEL_15;
}
while ( v53 != v14 );
v9 -= 2;
*v8 = 126 - v11 + v14;
v11 = v14;
v8[1] = v52 >> v7;
v8 += 2;
LABEL_59:
v44 = 0;
if ( v18 > 3 )
{
v9 -= 2;
v44 = v18;
*v8 = v18 + 126;
v8[1] = *(_DWORD *)(v5 + 4 * v14) >> v7;
v8 += 2;
}
v11 += v44;
if ( v6 <= v11 )
goto LABEL_62;
}
}