//
// TIFFFillTile from 0x8fedd0 to 0x8ff244 (1140 bytes)
//
// 2 xrefs:
// > TIFFReadEncodedTile @ 0x8fe7d4
// > ??> @ 0x6b84c
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:04:16 +0000
//
int __fastcall TIFFFillTile(_DWORD *a1, int a2)
{
__int64 v3; // r2
_DWORD *v7; // [sp+1Ch] [bp-28h]
__int64 v8; // [sp+20h] [bp-24h]
v7 = a1 + 10;
if ( TIFFFillStriles() && a1[44] )
{
if ( (a1[3] & 0x20000) == 0 )
{
v8 = *(_QWORD *)(v7[34] + 8 * a2);
if ( !v8 )
{
TIFFErrorExt(a1[157], (int)"TIFFFillTile", "%llu: Invalid tile byte count, tile %lu", 0LL, a2);
return 0;
}
if ( (a1[3] & 0x800) != 0 && ((a1[3] & *((unsigned __int16 *)v7 + 27)) != 0 || (a1[3] & 0x100) != 0) )
{
if ( (a1[3] & 0x200) != 0 && a1[147] )
{
TIFFfree(a1[147]);
a1[147] = 0;
a1[148] = 0;
}
a1[3] &= ~0x200u;
v3 = (int)a1[154];
if ( HIDWORD(v8) > (int)v3 >> 31
|| HIDWORD(v8) == HIDWORD(v3) && (unsigned int)v8 > (unsigned int)v3
|| *(_QWORD *)(v7[33] + 8 * a2) > (unsigned __int64)((int)a1[154] - v8) )
{
a1[123] = -1;
return 0;
}
a1[148] = v8;
a1[147] = a1[153] + *(_DWORD *)(v7[33] + 8 * a2);
a1[149] = 0;
a1[150] = v8;
a1[3] |= 0x800000u;
}
else
{
if ( HIDWORD(v8) != (int)v8 >> 31 )
{
TIFFErrorExt(a1[157], (int)"TIFFFillTile", "Integer overflow");
return 0;
}
if ( a1[148] < (int)v8 )
{
a1[123] = -1;
if ( (a1[3] & 0x200) == 0 )
{
TIFFErrorExt(a1[157], (int)"TIFFFillTile", "Data buffer too small to hold tile %lu", a2);
return 0;
}
if ( !TIFFReadBufferSetup(a1, 0, v8) )
return 0;
}
if ( (a1[3] & 0x800000) != 0 )
{
a1[123] = -1;
if ( !TIFFReadBufferSetup(a1, 0, v8) )
return 0;
}
if ( sub_8FE864((int)a1, a2, a1[147], v8, (int)"TIFFFillTile") != (_DWORD)v8 )
return 0;
a1[149] = 0;
a1[150] = v8;
if ( (a1[3] & *((unsigned __int16 *)v7 + 27)) == 0 && (a1[3] & 0x100) == 0 )
TIFFReverseBits(a1[147], a1[150]);
}
}
return sub_8FF5F4(a1, a2);
}
return 0;
}