//
// _TIFFFax3fillruns from 0x6c3778 to 0x6c3e58 (1760 bytes)
//
// 3 xrefs:
// > ??> @ 0x583bc
// > sub_6C6AF4 @ 0x6c6c84
// > ??> @ 0xab806c
//
// 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 TIFFFax3fillruns(int result, unsigned int *a2, unsigned int *a3, unsigned int a4)
{
unsigned int *v4; // [sp+4h] [bp-30h]
unsigned int *v5; // [sp+8h] [bp-2Ch]
int v6; // [sp+Ch] [bp-28h]
_BYTE *v7; // [sp+14h] [bp-20h]
_BYTE *v8; // [sp+14h] [bp-20h]
unsigned int v9; // [sp+18h] [bp-1Ch]
int v10; // [sp+1Ch] [bp-18h]
int v11; // [sp+1Ch] [bp-18h]
unsigned int v12; // [sp+20h] [bp-14h]
unsigned int v13; // [sp+20h] [bp-14h]
unsigned int v14; // [sp+24h] [bp-10h]
unsigned int v15; // [sp+24h] [bp-10h]
unsigned int v16; // [sp+28h] [bp-Ch]
unsigned int v17; // [sp+28h] [bp-Ch]
_DWORD *v18; // [sp+2Ch] [bp-8h]
_DWORD *v19; // [sp+2Ch] [bp-8h]
v6 = result;
v5 = a2;
v4 = a3;
if ( ((a3 - a2) & 1) != 0 )
{
*a3 = 0;
v4 = a3 + 1;
}
v9 = 0;
while ( v5 < v4 )
{
v12 = *v5;
if ( v9 + *v5 > a4 || v12 > a4 )
{
*v5 = a4 - v9;
v12 = *v5;
}
if ( v12 )
{
v7 = (_BYTE *)(v6 + (v9 >> 3));
v10 = v9 & 7;
if ( 8 - v10 >= v12 )
{
*v7 &= ~((int)byte_9E42B4[v12] >> v10);
}
else
{
if ( (v9 & 7) != 0 )
{
result = 255;
*v7++ &= 255 << (8 - v10);
v12 = v10 + v12 - 8;
}
v14 = v12 >> 3;
if ( v12 >> 3 )
{
if ( v14 > 7 )
{
while ( v14 && ((unsigned __int8)v7 & 3) != 0 )
{
*v7++ = 0;
--v14;
}
v18 = v7;
v16 = v14 >> 2;
v14 -= 4 * (v14 >> 2);
do
{
*v18++ = 0;
--v16;
}
while ( v16 );
v7 = v18;
}
switch ( v14 )
{
case 1u:
goto LABEL_27;
case 2u:
goto LABEL_26;
case 3u:
goto LABEL_25;
case 4u:
goto LABEL_24;
case 5u:
goto LABEL_23;
case 6u:
goto LABEL_22;
case 7u:
v7[6] = 0;
LABEL_22:
v7[5] = 0;
LABEL_23:
v7[4] = 0;
LABEL_24:
v7[3] = 0;
LABEL_25:
v7[2] = 0;
LABEL_26:
v7[1] = 0;
LABEL_27:
*v7 = 0;
v7 += v14;
break;
default:
break;
}
v12 &= 7u;
}
if ( v12 )
*v7 &= 255 >> v12;
}
v9 += *v5;
}
v13 = v5[1];
if ( v9 + v13 > a4 || v13 > a4 )
{
v5[1] = a4 - v9;
v13 = v5[1];
}
if ( v13 )
{
v8 = (_BYTE *)(v6 + (v9 >> 3));
v11 = v9 & 7;
if ( 8 - v11 >= v13 )
{
*v8 |= (int)byte_9E42B4[v13] >> v11;
}
else
{
if ( (v9 & 7) != 0 )
{
result = 255;
*v8++ |= 255 >> v11;
v13 = v11 + v13 - 8;
}
v15 = v13 >> 3;
if ( v13 >> 3 )
{
if ( v15 > 7 )
{
while ( v15 && ((unsigned __int8)v8 & 3) != 0 )
{
*v8++ = -1;
--v15;
}
v19 = v8;
v17 = v15 >> 2;
v15 -= 4 * (v15 >> 2);
do
{
*v19++ = -1;
--v17;
}
while ( v17 );
v8 = v19;
}
switch ( v15 )
{
case 1u:
goto LABEL_56;
case 2u:
goto LABEL_55;
case 3u:
goto LABEL_54;
case 4u:
goto LABEL_53;
case 5u:
goto LABEL_52;
case 6u:
goto LABEL_51;
case 7u:
v8[6] = -1;
LABEL_51:
v8[5] = -1;
LABEL_52:
v8[4] = -1;
LABEL_53:
v8[3] = -1;
LABEL_54:
v8[2] = -1;
LABEL_55:
v8[1] = -1;
LABEL_56:
*v8 = -1;
v8 += v15;
break;
default:
break;
}
v13 &= 7u;
}
if ( v13 )
*v8 |= 65280 >> v13;
}
v9 += v5[1];
}
v5 += 2;
}
if ( v9 != a4 )
return _assert2();
return result;
}