//
// _TIFFFax3fillruns from 0xc42bf0 to 0xc42fc0 (976 bytes)
//
// 6 xrefs:
// > ??> @ 0x688b0
// > TIFFInitCCITTFax3 @ 0xc48bc8
// > TIFFInitCCITTFax4 @ 0xc48da0
// > TIFFInitCCITTRLE @ 0xc48fa4
// > TIFFInitCCITTRLEW @ 0xc49134
// > ??> @ 0x122b638
//
// 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 TIFFFax3fillruns(__int64 result, unsigned int *a2, unsigned int *a3, __int64 a4)
{
unsigned int *v4; // x19
unsigned int *v5; // x27
__int64 v6; // x26
unsigned int v7; // w20
const char *v8; // x4
unsigned int v9; // w21
int v10; // w25
__int64 v11; // x0
char v12; // w1
_BYTE *v13; // x22
int v14; // w25
int v15; // w0
int v16; // w2
void *v17; // x0
size_t v18; // x2
unsigned int v19; // w21
int v20; // w1
__int64 v21; // x0
_BYTE *v22; // x22
int v23; // w25
int v24; // w2
void *v25; // x0
size_t v26; // x2
const char *v27; // [xsp+60h] [xbp+60h]
const char *v28; // [xsp+60h] [xbp+60h]
__int64 v29; // [xsp+68h] [xbp+68h]
__int64 v30; // [xsp+68h] [xbp+68h]
v4 = a2;
v5 = a3;
v6 = result;
if ( (((_DWORD)a3 - (_DWORD)a2) & 4) != 0 )
{
*a3 = 0;
v5 = a3 + 1;
}
v7 = 0;
if ( v5 > a2 )
{
v8 = "SamplesPerPixel tag is missing, assuming correct SamplesPerPixel value is 3";
while ( 1 )
{
v9 = *v4;
if ( *v4 + v7 > (unsigned int)a4 || v9 > (unsigned int)a4 )
{
v9 = a4 - v7;
*v4 = a4 - v7;
}
if ( !v9 )
goto LABEL_22;
v10 = v7 & 7;
v11 = v7 >> 3;
v12 = 8 - v10;
v13 = (_BYTE *)(v6 + v11);
if ( v9 <= 8 - v10 )
{
*(_BYTE *)(v6 + v11) &= ~((int)(unsigned __int8)v8[v9 + 2256] >> v10);
goto LABEL_21;
}
if ( (v7 & 7) != 0 )
{
v9 += v10 - 8;
v14 = v9 >> 3;
*(_BYTE *)(v6 + v11) &= -1 << v12;
++v13;
if ( !(v9 >> 3) )
goto LABEL_19;
}
else
{
v14 = v9 >> 3;
if ( !(v9 >> 3) )
goto LABEL_20;
}
if ( v14 > 15 )
{
while ( ((unsigned __int8)v13 & 7) != 0 )
{
*v13++ = 0;
if ( !--v14 )
{
v16 = 0;
goto LABEL_17;
}
}
v16 = (unsigned __int64)v14 >> 3;
v14 -= 8 * v16;
LABEL_17:
v17 = v13;
v18 = 8 * ((unsigned int)(v16 - 1) + 1LL);
v27 = v8;
v29 = a4;
v13 += v18;
memset(v17, 0, v18);
v15 = v14 - 1;
v8 = v27;
a4 = v29;
if ( (unsigned int)(v14 - 1) > 0xE )
{
LABEL_18:
v9 &= 7u;
goto LABEL_19;
}
}
else
{
v15 = v14 - 1;
}
switch ( v15 )
{
case 0:
goto LABEL_49;
case 1:
goto LABEL_48;
case 2:
goto LABEL_47;
case 3:
goto LABEL_46;
case 4:
goto LABEL_45;
case 5:
goto LABEL_44;
case 6:
goto LABEL_43;
case 7:
goto LABEL_42;
case 8:
goto LABEL_41;
case 9:
goto LABEL_40;
case 10:
goto LABEL_39;
case 11:
goto LABEL_38;
case 12:
goto LABEL_37;
case 13:
goto LABEL_36;
case 14:
v13[14] = 0;
LABEL_36:
v13[13] = 0;
LABEL_37:
v13[12] = 0;
LABEL_38:
v13[11] = 0;
LABEL_39:
v13[10] = 0;
LABEL_40:
v13[9] = 0;
LABEL_41:
v13[8] = 0;
LABEL_42:
v13[7] = 0;
LABEL_43:
v13[6] = 0;
LABEL_44:
v13[5] = 0;
LABEL_45:
v13[4] = 0;
LABEL_46:
v13[3] = 0;
LABEL_47:
v13[2] = 0;
LABEL_48:
v13[1] = 0;
LABEL_49:
*v13 = 0;
v9 &= 7u;
v13 += v14;
break;
default:
goto LABEL_18;
}
LABEL_19:
if ( v9 )
LABEL_20:
*v13 &= 255 >> v9;
LABEL_21:
v7 += *v4;
LABEL_22:
v19 = v4[1];
result = v7 + v19;
if ( (unsigned int)a4 < (unsigned int)result || (unsigned int)a4 < v19 )
{
v19 = a4 - v7;
v4[1] = a4 - v7;
if ( (_DWORD)a4 == v7 )
goto LABEL_51;
LABEL_25:
v20 = v7 & 7;
v21 = v7 >> 3;
v22 = (_BYTE *)(v6 + v21);
if ( v19 <= 8 - v20 )
{
*(_BYTE *)(v6 + v21) |= (int)(unsigned __int8)v8[v19 + 2256] >> v20;
goto LABEL_54;
}
if ( (v7 & 7) != 0 )
{
v19 += v20 - 8;
v23 = v19 >> 3;
*(_BYTE *)(v6 + v21) |= 255 >> v20;
++v22;
if ( !(v19 >> 3) )
goto LABEL_57;
}
else
{
v23 = v19 >> 3;
if ( !(v19 >> 3) )
goto LABEL_58;
}
if ( v23 > 15 )
{
while ( ((unsigned __int8)v22 & 7) != 0 )
{
*v22++ = -1;
if ( !--v23 )
{
v24 = 0;
goto LABEL_32;
}
}
v24 = (unsigned __int64)v23 >> 3;
v23 -= 8 * v24;
LABEL_32:
v25 = v22;
v26 = 8 * ((unsigned int)(v24 - 1) + 1LL);
v28 = v8;
v30 = a4;
v22 += v26;
memset(v25, 255, v26);
v8 = v28;
a4 = v30;
}
switch ( v23 )
{
case 1:
goto LABEL_76;
case 2:
goto LABEL_75;
case 3:
goto LABEL_74;
case 4:
goto LABEL_73;
case 5:
goto LABEL_72;
case 6:
goto LABEL_71;
case 7:
goto LABEL_70;
case 8:
goto LABEL_69;
case 9:
goto LABEL_68;
case 10:
goto LABEL_67;
case 11:
goto LABEL_66;
case 12:
goto LABEL_65;
case 13:
goto LABEL_64;
case 14:
goto LABEL_63;
case 15:
v22[14] = -1;
LABEL_63:
v22[13] = -1;
LABEL_64:
v22[12] = -1;
LABEL_65:
v22[11] = -1;
LABEL_66:
v22[10] = -1;
LABEL_67:
v22[9] = -1;
LABEL_68:
v22[8] = -1;
LABEL_69:
v22[7] = -1;
LABEL_70:
v22[6] = -1;
LABEL_71:
v22[5] = -1;
LABEL_72:
v22[4] = -1;
LABEL_73:
v22[3] = -1;
LABEL_74:
v22[2] = -1;
LABEL_75:
v22[1] = -1;
LABEL_76:
*v22 = -1;
v22 += v23;
break;
default:
break;
}
v19 &= 7u;
LABEL_57:
if ( v19 )
LABEL_58:
*v22 |= 65280 >> v19;
LABEL_54:
result = v4[1];
v4 += 2;
v7 += result;
if ( v5 <= v4 )
return result;
}
else
{
if ( v19 )
goto LABEL_25;
LABEL_51:
v4 += 2;
if ( v5 <= v4 )
return result;
}
}
}
return result;
}