//
// sub_C58C1C from 0xc58c1c to 0xc58e78 (604 bytes)
//
// 1 xrefs:
// > TIFFInitNeXT @ 0xc58e7c
//
// 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_C58C1C(__int64 a1, char *a2, signed __int64 a3)
{
__int64 v3; // x22
char *v5; // x23
signed __int64 v6; // x21
unsigned __int8 *v7; // x1
signed __int64 v8; // x20
size_t v9; // x25
__int64 v10; // x0
unsigned __int64 v11; // x5
unsigned __int8 *v12; // x26
unsigned int v13; // w6
char *v14; // x4
unsigned int v15; // w0
unsigned __int64 v16; // x7
int v17; // w5
int v18; // w2
unsigned int v19; // w3
unsigned int v20; // t1
char v21; // w0
v3 = a3;
v5 = a2;
if ( a3 > 0 )
{
memset(a2, 255, a3);
v6 = *(_QWORD *)(a1 + 856);
v7 = *(unsigned __int8 **)(a1 + 904);
v8 = *(_QWORD *)(a1 + 912);
if ( !(v3 % v6) )
{
while ( 1 )
{
LODWORD(v11) = *v7;
v12 = v7 + 1;
--v8;
if ( *v7 )
{
if ( (_DWORD)v11 == 64 )
{
v9 = v7[4] + (v7[3] << 8);
v10 = v7[2] + (v7[1] << 8);
if ( v8 <= (__int64)(v9 + 3) || (__int64)(v10 + v9) > v6 )
{
LABEL_27:
TIFFErrorExt(
*(_QWORD *)(a1 + 952),
(__int64)"NeXTDecode",
"Not enough data for scanline %ld",
*(unsigned int *)(a1 + 636));
return 0;
}
TIFFmemcpy(&v5[v10], v7 + 5, v9);
v7 = &v12[v9 + 4];
v8 += -4LL - v9;
}
else
{
v13 = *(_DWORD *)(a1 + 88);
v11 = (unsigned __int8)v11;
v14 = v5;
++v7;
v15 = 0;
while ( 1 )
{
v16 = v11 >> 6;
v17 = v15 + (v11 & 0x3F);
v18 = v15 & 3;
v19 = v15 + 1;
if ( v15 != v17 )
break;
LABEL_19:
if ( v13 <= v15 )
goto LABEL_7;
if ( !v8 )
goto LABEL_27;
v20 = *v7++;
v11 = v20;
--v8;
}
while ( v15 < v13 )
{
if ( v18 == 2 )
{
*v14 |= 4 * v16;
v15 = v19;
}
else if ( v18 == 3 )
{
v21 = *v14++;
*(v14 - 1) = v16 | v21;
v15 = v19;
}
else
{
if ( v18 == 1 )
*v14 |= 16 * v16;
else
*v14 = (_BYTE)v16 << 6;
v15 = v19;
}
v18 = v15 & 3;
v19 = v15 + 1;
if ( v15 == v17 )
goto LABEL_19;
}
}
}
else
{
if ( v8 < v6 )
goto LABEL_27;
v8 -= v6;
TIFFmemcpy(v5, v7 + 1, v6);
v7 = &v12[v6];
}
LABEL_7:
v3 -= v6;
v5 += v6;
if ( v3 <= 0 )
goto LABEL_30;
}
}
goto LABEL_28;
}
v7 = *(unsigned __int8 **)(a1 + 904);
v8 = *(_QWORD *)(a1 + 912);
if ( a3 % *(_QWORD *)(a1 + 856) )
{
LABEL_28:
TIFFErrorExt(*(_QWORD *)(a1 + 952), (__int64)"NeXTDecode", "Fractional scanlines cannot be read");
return 0;
}
LABEL_30:
*(_QWORD *)(a1 + 904) = v7;
*(_QWORD *)(a1 + 912) = v8;
return 1;
}