//
// sub_C3B530 from 0xc3b530 to 0xc3bb94 (1636 bytes)
//
// 2 xrefs:
// > TIFFReadDirectory @ 0xc3c614
// > TIFFReadDirectory @ 0xc3ccd8
//
// 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_C3B530(__int64 a1, __int64 a2, _WORD *a3)
{
unsigned int v3; // w22
unsigned __int64 v8; // x19
int v9; // w0
unsigned int v10; // w21
unsigned __int8 *v11; // x0
int v12; // w3
int v13; // w4
unsigned __int16 v14; // w3
__int64 v15; // x0
unsigned __int8 *v16; // x21
_WORD *v17; // x25
unsigned int v18; // w24
unsigned int v19; // w1
_WORD *v20; // x25
unsigned int v21; // w24
unsigned int v22; // w1
_WORD *v23; // x25
unsigned int v24; // w24
unsigned int v25; // w1
_WORD *v26; // x25
unsigned int v27; // w24
unsigned int v28; // w1
int v29; // w2
__int64 v30; // x3
__int64 v31; // x1
unsigned int v32; // w5
unsigned int v33; // w1
_WORD *v34; // x3
unsigned __int8 *v35; // x4
int v36; // w2
unsigned int v37; // w10
unsigned int v38; // w6
unsigned int v39; // w7
uint8x16_t *v40; // x11
unsigned int v41; // w8
uint16x8_t *v42; // x1
uint8x16_t v43; // t1
uint16x8_t *v44; // x9
__int64 v45; // x1
unsigned int v46; // [xsp+54h] [xbp+54h] BYREF
void *p; // [xsp+58h] [xbp+58h] BYREF
switch ( *(_WORD *)(a2 + 2) )
{
case 1:
case 3:
case 4:
case 6:
case 8:
case 9:
case 0x10:
case 0x11:
v3 = sub_C3856C(a1, a2, &v46, 2u, &p);
if ( v3 )
return v3;
v8 = (unsigned __int64)p;
if ( p )
{
v9 = *(unsigned __int16 *)(a2 + 2);
if ( v9 == 3 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x80) != 0 )
TIFFSwabArrayOfShort(p, v46);
goto LABEL_19;
}
if ( v9 == 8 )
{
v10 = 0;
if ( v46 )
{
do
{
if ( (*(_DWORD *)(a1 + 16) & 0x80) != 0 )
TIFFSwabShort(v8);
if ( *(__int16 *)v8 < 0 )
{
v3 = 4;
TIFFfree(p);
return v3;
}
++v10;
v8 += 2LL;
}
while ( v10 < v46 );
v8 = (unsigned __int64)p;
}
goto LABEL_19;
}
}
else
{
__break(0x3E8u);
}
v8 = (unsigned __int64)TIFFmalloc(2LL * (v46 & 0x7FFFFFFF));
if ( v8 )
{
switch ( *(_WORD *)(a2 + 2) )
{
case 1:
v32 = v46;
v11 = (unsigned __int8 *)p;
if ( v46 )
{
if ( ((unsigned __int64)p >= v8 + 2LL * v46 || v8 >= (unsigned __int64)p + v46) && v46 > 0x14 )
{
v33 = -((v8 >> 1) & 7) & 7;
if ( v33 > v46 )
v33 = v46;
if ( v33 )
{
*(_WORD *)v8 = *(unsigned __int8 *)p;
v34 = (_WORD *)(v8 + 2);
v35 = v11 + 1;
if ( v33 == 1 )
goto LABEL_106;
*(_WORD *)(v8 + 2) = v11[1];
v34 = (_WORD *)(v8 + 4);
v35 = v11 + 2;
if ( v33 == 2 )
goto LABEL_106;
*(_WORD *)(v8 + 4) = v11[2];
v34 = (_WORD *)(v8 + 6);
v35 = v11 + 3;
if ( v33 == 3
|| (*(_WORD *)(v8 + 6) = v11[3], v34 = (_WORD *)(v8 + 8), v35 = v11 + 4, v33 == 4)
|| (*(_WORD *)(v8 + 8) = v11[4], v34 = (_WORD *)(v8 + 10), v35 = v11 + 5, v33 == 5) )
{
LABEL_106:
v36 = v33;
}
else
{
*(_WORD *)(v8 + 10) = v11[5];
v34 = (_WORD *)(v8 + 12);
v35 = v11 + 6;
if ( v33 == 7 )
{
v34 = (_WORD *)(v8 + 14);
*(_WORD *)(v8 + 12) = v11[6];
v35 = v11 + 7;
v36 = 7;
}
else
{
v36 = 6;
}
}
}
else
{
v35 = (unsigned __int8 *)p;
v34 = (_WORD *)v8;
v36 = 0;
}
v37 = v32 - v33;
v38 = ((v32 - v33 - 16) >> 4) + 1;
v39 = 16 * v38;
if ( v32 - 1 - v33 <= 0xE )
goto LABEL_109;
v40 = (uint8x16_t *)&v11[v33];
v41 = 0;
v42 = (uint16x8_t *)(v8 + 2LL * v33);
do
{
v43 = *v40++;
v44 = v42;
++v41;
v42 += 2;
*v44 = vmovl_u8((uint8x8_t)v43.n128_u64[0]);
v44[1] = vmovl_high_u8(v43);
}
while ( v41 < v38 );
v35 += v39;
v36 += v39;
v34 += v39;
if ( v37 != v39 )
{
LABEL_109:
*v34 = *v35;
if ( v32 > v36 + 1 )
{
v34[1] = v35[1];
if ( v32 > v36 + 2 )
{
v34[2] = v35[2];
if ( v32 > v36 + 3 )
{
v34[3] = v35[3];
if ( v32 > v36 + 4 )
{
v34[4] = v35[4];
if ( v32 > v36 + 5 )
{
v34[5] = v35[5];
if ( v32 > v36 + 6 )
{
v34[6] = v35[6];
if ( v32 > v36 + 7 )
{
v34[7] = v35[7];
if ( v32 > v36 + 8 )
{
v34[8] = v35[8];
if ( v32 > v36 + 9 )
{
v34[9] = v35[9];
if ( v32 > v36 + 10 )
{
v34[10] = v35[10];
if ( v32 > v36 + 11 )
{
v34[11] = v35[11];
if ( v32 > v36 + 12 )
{
v34[12] = v35[12];
if ( v32 > v36 + 13 )
{
v34[13] = v35[13];
if ( v32 > v36 + 14 )
v34[14] = v35[14];
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
else
{
v45 = 0;
do
{
*(_WORD *)(v8 + 2 * v45) = v11[v45];
++v45;
}
while ( v32 > (unsigned int)v45 );
}
}
goto LABEL_18;
case 4:
v16 = (unsigned __int8 *)p;
if ( !v46 )
goto LABEL_104;
v26 = (_WORD *)v8;
v27 = 0;
while ( 1 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x80) != 0 )
TIFFSwabLong(v16);
if ( *(_DWORD *)v16 > 0xFFFFu )
goto LABEL_33;
v28 = v46;
++v27;
*v26++ = *(_DWORD *)v16;
v16 += 4;
if ( v27 >= v28 )
goto LABEL_17;
}
case 6:
v11 = (unsigned __int8 *)p;
if ( !v46 )
goto LABEL_18;
v29 = *(char *)p;
if ( v29 < 0 )
goto LABEL_34;
v30 = v46 - 1;
v31 = 0;
while ( 1 )
{
*(_WORD *)(v8 + 2 * v31) = v29;
if ( v31 == v30 )
goto LABEL_18;
v29 = (char)v11[++v31];
if ( v29 < 0 )
goto LABEL_34;
}
case 9:
v16 = (unsigned __int8 *)p;
if ( !v46 )
goto LABEL_104;
v23 = (_WORD *)v8;
v24 = 0;
while ( 1 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x80) != 0 )
TIFFSwabLong(v16);
if ( *(_DWORD *)v16 > 0xFFFFu )
goto LABEL_33;
v25 = v46;
++v24;
*v23++ = *(_DWORD *)v16;
v16 += 4;
if ( v24 >= v25 )
goto LABEL_17;
}
case 0x10:
v16 = (unsigned __int8 *)p;
if ( !v46 )
goto LABEL_104;
v20 = (_WORD *)v8;
v21 = 0;
break;
case 0x11:
v16 = (unsigned __int8 *)p;
if ( !v46 )
{
LABEL_104:
v11 = v16;
goto LABEL_18;
}
v17 = (_WORD *)v8;
v18 = 0;
while ( 1 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x80) != 0 )
TIFFSwabLong8(v16);
if ( *(_QWORD *)v16 > 0xFFFFu )
goto LABEL_33;
v19 = v46;
++v18;
*v17++ = *(_QWORD *)v16;
v16 += 8;
if ( v18 >= v19 )
goto LABEL_17;
}
default:
goto LABEL_17;
}
while ( 1 )
{
if ( (*(_DWORD *)(a1 + 16) & 0x80) != 0 )
TIFFSwabLong8(v16);
if ( *(_QWORD *)v16 > 0xFFFFu )
break;
v22 = v46;
++v21;
*v20++ = *(_QWORD *)v16;
v16 += 8;
if ( v21 >= v22 )
{
LABEL_17:
v11 = (unsigned __int8 *)p;
LABEL_18:
TIFFfree(v11);
LABEL_19:
v12 = *(unsigned __int16 *)(a1 + 130);
v13 = *(unsigned __int16 *)v8;
*a3 = v13;
if ( v12 != 1 )
{
if ( *(unsigned __int16 *)(v8 + 2) == v13 )
{
v14 = v12 - 2;
v15 = 0;
while ( v15 != v14 )
{
++v15;
if ( *(unsigned __int16 *)(v8 + 4 + 2 * v15 - 2) != v13 )
goto LABEL_94;
}
goto LABEL_24;
}
LABEL_94:
v3 = 5;
TIFFfree((void *)v8);
return v3;
}
LABEL_24:
TIFFfree((void *)v8);
return v3;
}
}
LABEL_33:
v11 = (unsigned __int8 *)p;
LABEL_34:
v3 = 4;
TIFFfree(v11);
goto LABEL_24;
}
v3 = 7;
TIFFfree(p);
return v3;
default:
return 2;
}
}