//
// sub_C55C04 from 0xc55c04 to 0xc55e2c (552 bytes)
//
// 2 xrefs:
// > sub_C55E2C @ 0xc55e64
// > sub_C56154 @ 0xc56198
//
// 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_C55C04(__int64 a1)
{
unsigned int *v1; // x1
__int64 v3; // x20
unsigned int v4; // w0
int v6; // w2
int v7; // w0
unsigned int v8; // w2
__int64 v9; // x1
__int64 v10; // x3
__int64 v11; // x0
__int64 v12; // x1
unsigned int v13; // w2
void *v14; // x0
v1 = (unsigned int *)(a1 + 56);
v3 = *(_QWORD *)(a1 + 848);
if ( *(_WORD *)(a1 + 170) != 1 )
{
TIFFErrorExt(
*(_QWORD *)(a1 + 952),
(__int64)"LogLuvInitState",
"SGILog compression cannot handle non-contiguous data");
return 0;
}
v4 = *(_DWORD *)v3;
if ( *(_DWORD *)v3 != -1 )
goto LABEL_5;
v6 = *(unsigned __int16 *)(a1 + 130);
v7 = *(unsigned __int16 *)(a1 + 118) | (8 * *(unsigned __int16 *)(a1 + 116));
if ( v7 == 132 )
goto LABEL_36;
if ( v7 > 132 )
{
if ( v7 == 259 )
{
v4 = 0;
goto LABEL_37;
}
if ( v7 > 259 )
{
if ( v7 == 260 )
goto LABEL_12;
}
else if ( v7 >= 257 )
{
LABEL_12:
if ( v6 == 1 )
v4 = 2;
else
v4 = -1;
*(_DWORD *)v3 = v4;
goto LABEL_16;
}
goto LABEL_43;
}
if ( v7 == 68 )
goto LABEL_41;
if ( v7 <= 68 )
{
if ( v7 != 65 )
goto LABEL_43;
LABEL_41:
v4 = 3;
goto LABEL_37;
}
if ( (unsigned int)(v7 - 129) > 1 )
{
LABEL_43:
v4 = -1;
goto LABEL_37;
}
LABEL_36:
v4 = 1;
LABEL_37:
if ( v6 != 3 )
v4 = -1;
*(_DWORD *)v3 = v4;
LABEL_16:
if ( v4 > 3 )
{
LABEL_4:
TIFFErrorExt(
*(_QWORD *)(a1 + 952),
(__int64)"LogLuvInitState",
"No support for converting user data format to LogLuv");
return 0;
}
LABEL_5:
switch ( v4 )
{
case 0u:
*(_DWORD *)(v3 + 8) = 12;
goto LABEL_19;
case 1u:
*(_DWORD *)(v3 + 8) = 6;
if ( (*(_DWORD *)(a1 + 16) & 0x400) == 0 )
goto LABEL_26;
goto LABEL_20;
case 2u:
*(_DWORD *)(v3 + 8) = 4;
goto LABEL_19;
case 3u:
*(_DWORD *)(v3 + 8) = 3;
LABEL_19:
if ( (*(_DWORD *)(a1 + 16) & 0x400) != 0 )
{
LABEL_20:
v8 = v1[12];
v9 = v1[11];
v10 = v8;
v11 = v9 * v8;
if ( !v9 )
goto LABEL_27;
}
else
{
LABEL_26:
v13 = v1[19];
v9 = v1[8];
v10 = v13;
v11 = v9 * v13;
if ( !v9 )
goto LABEL_27;
}
if ( v10 != v11 / v9 )
{
v11 = 0;
*(_QWORD *)(v3 + 24) = 0;
v12 = 0;
goto LABEL_28;
}
LABEL_27:
*(_QWORD *)(v3 + 24) = v11;
v12 = 4 * v11;
if ( v11 && v12 / v11 != 4 )
goto LABEL_24;
LABEL_28:
if ( !v12 || (v14 = TIFFmalloc(4 * v11), (*(_QWORD *)(v3 + 16) = v14) == 0) )
{
LABEL_24:
TIFFErrorExt(*(_QWORD *)(a1 + 952), (__int64)"LogLuvInitState", "No space for SGILog translation buffer");
return 0;
}
return 1;
default:
goto LABEL_4;
}
}