//
// TIFFClientOpen from 0xc58f14 to 0xc595a4 (1680 bytes)
//
// 3 xrefs:
// > cocos2d::CCImage::_initWithTiffData @ 0xb0c37c
// > TIFFFdOpen @ 0xc64288
// > ??> @ 0x89b20
//
// 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 TIFFClientOpen(
const char *a1,
const char *a2,
__int64 a3,
__int64 a4,
__int64 a5,
__int64 a6,
__int64 a7,
__int64 a8,
__int64 a9,
void (*a10)())
{
int v17; // w26
size_t v18; // x0
void *v19; // x0
__int64 v20; // x27
_BOOL4 v21; // w28
void (*v22)(); // x0
int v23; // w1
int v24; // w0
const char *v25; // x1
int v26; // t1
int v27; // w0
__int64 v28; // x19
int v30; // w3
int v31; // w0
int v32; // w3
int v33; // w0
unsigned int v34; // w1
int v35; // w2
__int64 v36; // x2
int v37; // w0
int v38; // w3
int v39; // w0
__int64 v41; // [xsp+78h] [xbp+78h] BYREF
v17 = TIFFgetMode(a2, 16056320);
if ( v17 == -1 )
return 0;
v18 = strlen(a1);
v19 = TIFFmalloc(v18 + 1081);
v20 = (__int64)v19;
if ( !v19 )
{
v28 = 0;
TIFFErrorExt(a3, 16056320, "%s: Out of memory (TIFF structure)", a1);
return v28;
}
TIFFmemset(v19, 0, 0x438u);
*(_QWORD *)v20 = v20 + 1080;
strcpy((char *)(v20 + 1080), a1);
*(_QWORD *)(v20 + 648) = 0;
*(_DWORD *)(v20 + 12) = v17 & 0xFFFFFDBF;
*(_WORD *)(v20 + 640) = -1;
*(_DWORD *)(v20 + 644) = -1;
*(_DWORD *)(v20 + 636) = -1;
*(_QWORD *)(v20 + 952) = a3;
if ( a4 )
{
if ( a5 )
{
v21 = a8 == 0 || a6 == 0 || a7 == 0;
if ( !v21 )
{
*(_QWORD *)(v20 + 960) = a4;
*(_QWORD *)(v20 + 968) = a5;
*(_QWORD *)(v20 + 976) = a6;
*(_QWORD *)(v20 + 984) = a7;
*(_QWORD *)(v20 + 992) = a8;
if ( a9 )
{
*(_QWORD *)(v20 + 936) = a9;
v22 = a10;
if ( a10 )
goto LABEL_8;
}
else
{
*(_QWORD *)(v20 + 936) = sub_C58E98;
v22 = a10;
if ( a10 )
goto LABEL_8;
}
v22 = nullsub_18;
LABEL_8:
*(_QWORD *)(v20 + 944) = v22;
TIFFSetDefaultCompressionState(v20);
*(_DWORD *)(v20 + 16) = 1;
if ( v17 )
{
v23 = 32769;
if ( (v17 & 0xFFFFFFFD) != 0 )
goto LABEL_10;
}
else
{
v23 = 34817;
v21 = 1;
}
*(_DWORD *)(v20 + 16) = v23;
LABEL_10:
v24 = *(unsigned __int8 *)a2;
v25 = a2;
if ( *a2 )
{
do
{
switch ( v24 )
{
case '8':
if ( (v17 & 0x40) != 0 )
*(_DWORD *)(v20 + 16) |= 0x80000u;
break;
case 'B':
case 'H':
*(_DWORD *)(v20 + 16) = *(_DWORD *)(v20 + 16) & 0xFFFFFFFC | 1;
break;
case 'C':
if ( v21 )
*(_DWORD *)(v20 + 16) |= 0x8000u;
break;
case 'L':
*(_DWORD *)(v20 + 16) = *(_DWORD *)(v20 + 16) & 0xFFFFFFFC | 2;
break;
case 'M':
if ( v21 )
*(_DWORD *)(v20 + 16) |= 0x800u;
break;
case 'b':
if ( (v17 & 0x40) != 0 )
*(_DWORD *)(v20 + 16) |= 0x80u;
break;
case 'c':
if ( v21 )
*(_DWORD *)(v20 + 16) &= ~0x8000u;
break;
case 'h':
*(_DWORD *)(v20 + 16) |= 0x10000u;
break;
case 'm':
if ( v21 )
*(_DWORD *)(v20 + 16) &= ~0x800u;
break;
default:
break;
}
v26 = *(unsigned __int8 *)++v25;
v24 = v26;
}
while ( v26 );
}
if ( (v17 & 0x200) == 0
&& (*(__int64 (__fastcall **)(_QWORD, __int64, __int64))(v20 + 960))(*(_QWORD *)(v20 + 952), v20 + 616, 8) == 8 )
{
v30 = *(unsigned __int16 *)(v20 + 616);
if ( v30 == 18761 || v30 == 19789 )
{
v31 = *(_DWORD *)(v20 + 16);
if ( v30 == 19789 )
{
v31 |= 0x80u;
*(_DWORD *)(v20 + 16) = v31;
}
}
else
{
if ( v30 != 20549 )
{
TIFFErrorExt(
*(_QWORD *)(v20 + 952),
(__int64)a1,
"Not a TIFF or MDI file, bad magic number %d (0x%x)",
v30,
*(unsigned __int16 *)(v20 + 616));
goto LABEL_67;
}
v31 = *(_DWORD *)(v20 + 16);
}
if ( (v31 & 0x80) != 0 )
TIFFSwabShort(v20 + 618);
v32 = *(unsigned __int16 *)(v20 + 618);
if ( (unsigned __int16)(v32 - 42) > 1u )
{
TIFFErrorExt(
*(_QWORD *)(v20 + 952),
(__int64)a1,
"Not a TIFF file, bad version number %d (0x%x)",
v32,
*(unsigned __int16 *)(v20 + 618));
goto LABEL_67;
}
if ( v32 == 42 )
{
v33 = *(_DWORD *)(v20 + 16);
if ( (v33 & 0x80) != 0 )
{
TIFFSwabLong(v20 + 620);
v33 = *(_DWORD *)(v20 + 16);
}
*(_WORD *)(v20 + 632) = 8;
LABEL_57:
v34 = v33 | 0x200;
*(_QWORD *)(v20 + 872) = 0;
*(_DWORD *)(v20 + 16) = v33 | 0x200;
*(_QWORD *)(v20 + 904) = 0;
*(_QWORD *)(v20 + 880) = 0;
*(_QWORD *)(v20 + 888) = 0;
*(_QWORD *)(v20 + 896) = 0;
v35 = *(unsigned __int8 *)a2;
if ( v35 == 97 )
{
if ( (unsigned int)TIFFDefaultDirectory(v20) )
return v20;
}
else if ( v35 == 114 )
{
if ( (v33 & 0x80000) != 0 )
v36 = *(_QWORD *)(v20 + 624);
else
v36 = *(unsigned int *)(v20 + 620);
*(_QWORD *)(v20 + 32) = v36;
if ( (v33 & 0x800) != 0 )
{
if ( (*(unsigned int (__fastcall **)(_QWORD, __int64, __int64 *))(v20 + 936))(
*(_QWORD *)(v20 + 952),
v20 + 920,
&v41) )
{
*(_QWORD *)(v20 + 928) = v41;
v34 = *(_DWORD *)(v20 + 16);
}
else
{
v34 = *(_DWORD *)(v20 + 16) & 0xFFFFF7FF;
*(_DWORD *)(v20 + 16) = v34;
}
}
v28 = v20;
if ( (v34 & 0x10000) != 0 )
return v28;
if ( (unsigned int)TIFFReadDirectory(v20) )
{
v37 = *(_DWORD *)(v20 + 16);
*(_QWORD *)(v20 + 912) = -1;
*(_DWORD *)(v20 + 16) = v37 | 0x10;
return v28;
}
}
goto LABEL_67;
}
if ( (*(__int64 (__fastcall **)(_QWORD, __int64, __int64))(v20 + 960))(*(_QWORD *)(v20 + 952), v20 + 624, 8) == 8 )
{
if ( (*(_DWORD *)(v20 + 16) & 0x80) != 0 )
{
TIFFSwabShort(v20 + 620);
TIFFSwabLong8(v20 + 624);
}
v38 = *(unsigned __int16 *)(v20 + 620);
if ( v38 == 8 )
{
if ( !*(_WORD *)(v20 + 622) )
{
v39 = *(_DWORD *)(v20 + 16);
*(_WORD *)(v20 + 632) = 16;
v33 = v39 | 0x80000;
goto LABEL_57;
}
TIFFErrorExt(
*(_QWORD *)(v20 + 952),
(__int64)a1,
"Not a TIFF file, bad BigTIFF unused %d (0x%x)",
*(unsigned __int16 *)(v20 + 622),
*(unsigned __int16 *)(v20 + 622));
}
else
{
TIFFErrorExt(
*(_QWORD *)(v20 + 952),
(__int64)a1,
"Not a TIFF file, bad BigTIFF offsetsize %d (0x%x)",
v38,
*(unsigned __int16 *)(v20 + 620));
}
LABEL_67:
*(_DWORD *)(v20 + 12) = 0;
TIFFCleanup(v20);
return 0;
}
LABEL_76:
TIFFErrorExt(*(_QWORD *)(v20 + 952), (__int64)a1, "Cannot read TIFF header");
goto LABEL_67;
}
if ( !*(_DWORD *)(v20 + 12) )
goto LABEL_76;
v27 = *(_DWORD *)(v20 + 16);
if ( (v27 & 0x80) != 0 )
{
*(_WORD *)(v20 + 616) = 19789;
if ( (v27 & 0x80000) == 0 )
{
*(_DWORD *)(v20 + 620) = 0;
*(_WORD *)(v20 + 618) = 42;
TIFFSwabShort(v20 + 618);
LABEL_19:
*(_WORD *)(v20 + 632) = 8;
goto LABEL_39;
}
*(_WORD *)(v20 + 618) = 43;
*(_DWORD *)(v20 + 620) = 8;
*(_QWORD *)(v20 + 624) = 0;
TIFFSwabShort(v20 + 618);
TIFFSwabShort(v20 + 620);
}
else
{
*(_WORD *)(v20 + 616) = 18761;
if ( (v27 & 0x80000) == 0 )
{
*(_DWORD *)(v20 + 620) = 0;
*(_WORD *)(v20 + 618) = 42;
goto LABEL_19;
}
*(_WORD *)(v20 + 622) = 0;
*(_WORD *)(v20 + 618) = 43;
*(_QWORD *)(v20 + 624) = 0;
*(_WORD *)(v20 + 620) = 8;
}
*(_WORD *)(v20 + 632) = 16;
LABEL_39:
(*(void (__fastcall **)(_QWORD, _QWORD, _QWORD))(v20 + 976))(*(_QWORD *)(v20 + 952), 0, 0);
if ( (*(__int64 (__fastcall **)(_QWORD, __int64, _QWORD))(v20 + 968))(
*(_QWORD *)(v20 + 952),
v20 + 616,
*(unsigned __int16 *)(v20 + 632)) == *(unsigned __int16 *)(v20 + 632) )
{
if ( *(_WORD *)(v20 + 616) == 19789 )
*(_DWORD *)(v20 + 16) |= 0x80u;
if ( (unsigned int)TIFFDefaultDirectory(v20) )
{
*(_QWORD *)(v20 + 24) = 0;
v28 = v20;
*(_QWORD *)(v20 + 40) = 0;
*(_WORD *)(v20 + 48) = 0;
*(_WORD *)(v20 + 50) = 0;
return v28;
}
}
else
{
TIFFErrorExt(*(_QWORD *)(v20 + 952), (__int64)a1, "Error writing TIFF header");
}
goto LABEL_67;
}
}
}
TIFFErrorExt(a3, (__int64)"TIFFClientOpen", "One of the client procedures is NULL pointer.");
return 0;
}