//
// sub_8C7DD0 from 0x8c7dd0 to 0x8ca818 (10824 bytes)
//
// 3 xrefs:
// > TIFFWriteDirectory @ 0x8c74d8
// > TIFFCheckpointDirectory @ 0x8c7524
// > TIFFWriteCustomDirectory @ 0x8c759c
//
// 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:03 +0000
//
int __fastcall sub_8C7DD0(int a1, int a2, int a3, _QWORD *a4)
{
__int64 v5; // r0
int v6; // r0
int v12; // [sp+18h] [bp-64h] BYREF
int v13; // [sp+1Ch] [bp-60h] BYREF
int v14; // [sp+20h] [bp-5Ch] BYREF
int v15; // [sp+24h] [bp-58h] BYREF
unsigned __int16 v16; // [sp+2Ah] [bp-52h] BYREF
char *v17; // [sp+2Ch] [bp-50h] BYREF
int v18; // [sp+30h] [bp-4Ch] BYREF
unsigned __int16 v19; // [sp+36h] [bp-46h] BYREF
unsigned int v20; // [sp+38h] [bp-44h] BYREF
int v21; // [sp+3Ch] [bp-40h]
int v22; // [sp+40h] [bp-3Ch]
_QWORD *v23; // [sp+44h] [bp-38h]
unsigned int j; // [sp+48h] [bp-34h]
unsigned int i; // [sp+4Ch] [bp-30h]
int v26; // [sp+50h] [bp-2Ch]
size_t v27; // [sp+54h] [bp-28h]
unsigned int v28; // [sp+58h] [bp-24h]
_WORD *k; // [sp+5Ch] [bp-20h]
_WORD *v30; // [sp+60h] [bp-1Ch]
int v31; // [sp+64h] [bp-18h]
_WORD *v32; // [sp+68h] [bp-14h]
_WORD *v33; // [sp+6Ch] [bp-10h]
if ( !*(_DWORD *)(a1 + 8) )
return 1;
TIFFFillStriles();
if ( a3 )
{
if ( (*(_DWORD *)(a1 + 12) & 0x1000) != 0 )
{
*(_DWORD *)(a1 + 12) &= ~0x1000u;
if ( !(*(int (__fastcall **)(int))(a1 + 528))(a1) )
{
TIFFErrorExt(*(_DWORD *)(a1 + 628), "TIFFWriteDirectorySec", "Error post-encoding before directory write");
return 0;
}
}
(*(void (__fastcall **)(int))(a1 + 556))(a1);
if ( *(int *)(a1 + 608) > 0 && (*(_DWORD *)(a1 + 12) & 0x40) != 0 && !TIFFFlushData1(a1) )
{
TIFFErrorExt(*(_DWORD *)(a1 + 628), "TIFFWriteDirectorySec", "Error flushing data before directory write");
return 0;
}
if ( (*(_DWORD *)(a1 + 12) & 0x200) != 0 && *(_DWORD *)(a1 + 588) )
{
TIFFfree(*(_DWORD *)(a1 + 588));
*(_DWORD *)(a1 + 588) = 0;
*(_DWORD *)(a1 + 608) = 0;
*(_DWORD *)(a1 + 592) = 0;
*(_DWORD *)(a1 + 596) = 0;
*(_DWORD *)(a1 + 600) = 0;
}
*(_DWORD *)(a1 + 12) &= 0xFFFFFFAF;
}
v21 = 0;
v23 = nullptr;
v22 = 0;
while ( 1 )
{
v20 = 0;
if ( a2 )
{
if ( (*(_DWORD *)(a1 + 40) & 2) != 0
&& (!sub_8CB6C8(a1, &v20, v21, 256, *(_DWORD *)(a1 + 56))
|| !sub_8CB6C8(a1, &v20, v21, 257, *(_DWORD *)(a1 + 60)))
|| (*(_DWORD *)(a1 + 40) & 4) != 0
&& (!sub_8CB6C8(a1, &v20, v21, 322, *(_DWORD *)(a1 + 68))
|| !sub_8CB6C8(a1, &v20, v21, 323, *(_DWORD *)(a1 + 72)))
|| (*(_DWORD *)(a1 + 40) & 8) != 0
&& (!sub_8CB400(a1, (int)&v20, v21, 282, *(float *)(a1 + 116))
|| !sub_8CB400(a1, (int)&v20, v21, 283, *(float *)(a1 + 120)))
|| (*(_DWORD *)(a1 + 40) & 0x10) != 0
&& (!sub_8CB400(a1, (int)&v20, v21, 286, *(float *)(a1 + 128))
|| !sub_8CB400(a1, (int)&v20, v21, 287, *(float *)(a1 + 132)))
|| (*(_DWORD *)(a1 + 40) & 0x20) != 0 && !sub_8CB1B0(a1, &v20, v21, 254, *(_DWORD *)(a1 + 80))
|| (*(_DWORD *)(a1 + 40) & 0x40) != 0 && !sub_8CAFFC(a1, &v20, v21, 258, *(unsigned __int16 *)(a1 + 84))
|| (*(_DWORD *)(a1 + 40) & 0x80) != 0 && !sub_8CAF14(a1, &v20, v21, 259, *(unsigned __int16 *)(a1 + 88))
|| (*(_DWORD *)(a1 + 40) & 0x100) != 0 && !sub_8CAF14(a1, &v20, v21, 262, *(unsigned __int16 *)(a1 + 90))
|| (*(_DWORD *)(a1 + 40) & 0x200) != 0 && !sub_8CAF14(a1, &v20, v21, 263, *(unsigned __int16 *)(a1 + 92))
|| (*(_DWORD *)(a1 + 40) & 0x400) != 0 && !sub_8CAF14(a1, &v20, v21, 266, *(unsigned __int16 *)(a1 + 94))
|| (*(_DWORD *)(a1 + 40) & 0x8000) != 0 && !sub_8CAF14(a1, &v20, v21, 274, *(unsigned __int16 *)(a1 + 96))
|| (*(_DWORD *)(a1 + 40) & 0x10000) != 0 && !sub_8CAF14(a1, &v20, v21, 277, *(unsigned __int16 *)(a1 + 98))
|| (*(_DWORD *)(a1 + 40) & 0x20000) != 0 && !sub_8CB6C8(a1, &v20, v21, 278, *(_DWORD *)(a1 + 100))
|| (*(_DWORD *)(a1 + 40) & 0x40000) != 0 && !sub_8CAFFC(a1, &v20, v21, 280, *(unsigned __int16 *)(a1 + 104))
|| (*(_DWORD *)(a1 + 40) & 0x80000) != 0 && !sub_8CAFFC(a1, &v20, v21, 281, *(unsigned __int16 *)(a1 + 106))
|| (*(_DWORD *)(a1 + 40) & 0x100000) != 0 && !sub_8CAF14(a1, &v20, v21, 284, *(unsigned __int16 *)(a1 + 126))
|| (*(_DWORD *)(a1 + 40) & 0x400000) != 0 && !sub_8CAF14(a1, &v20, v21, 296, *(unsigned __int16 *)(a1 + 124))
|| (*(_DWORD *)(a1 + 40) & 0x800000) != 0 && !sub_8CAF84(a1, &v20, v21, 297, 2, a1 + 136) )
{
goto LABEL_241;
}
if ( (*(_DWORD *)(a1 + 40) & 0x1000000) != 0 )
{
if ( (*(_DWORD *)(a1 + 12) & 0x400) != 0 )
{
if ( !sub_8CB770(a1, &v20, v21, 325, *(_DWORD *)(a1 + 168), *(_DWORD *)(a1 + 176)) )
goto LABEL_241;
}
else if ( !sub_8CB770(a1, &v20, v21, 279, *(_DWORD *)(a1 + 168), *(_DWORD *)(a1 + 176)) )
{
goto LABEL_241;
}
}
if ( (*(_DWORD *)(a1 + 40) & 0x2000000) != 0 )
{
if ( (*(_DWORD *)(a1 + 12) & 0x400) != 0 )
{
if ( !sub_8CB770(a1, &v20, v21, 324, *(_DWORD *)(a1 + 168), *(_DWORD *)(a1 + 172)) )
goto LABEL_241;
}
else if ( !sub_8CB770(a1, &v20, v21, 273, *(_DWORD *)(a1 + 168), *(_DWORD *)(a1 + 172)) )
{
goto LABEL_241;
}
}
if ( (*(_DWORD *)(a1 + 40) & 0x4000000) != 0 && !sub_8CBB38(a1, &v20, v21) )
goto LABEL_241;
if ( *(int *)(a1 + 40) < 0 )
{
if ( *(_WORD *)(a1 + 156) )
{
TIFFGetFieldDefaulted(a1, 0x152u, &v19, &v18);
if ( !sub_8CAF84(a1, &v20, v21, 338, v19, v18) )
goto LABEL_241;
}
}
if ( (*(_DWORD *)(a1 + 44) & 1) != 0 && !sub_8CAFFC(a1, &v20, v21, 339, *(unsigned __int16 *)(a1 + 86))
|| (*(_DWORD *)(a1 + 44) & 2) != 0
&& !sub_8CA844(
a1,
&v20,
v21,
(int (__fastcall *)(_DWORD, _DWORD))"/system/bin/linker",
*(unsigned __int16 *)(a1 + 98),
*(_DWORD *)(a1 + 108))
|| (*(_DWORD *)(a1 + 44) & 4) != 0
&& !sub_8CA844(a1, &v20, v21, 341, *(unsigned __int16 *)(a1 + 98), *(_DWORD *)(a1 + 112))
|| (*(_DWORD *)(a1 + 44) & 8) != 0 && !sub_8CB1B0(a1, &v20, v21, 32997, *(_DWORD *)(a1 + 64))
|| (*(_DWORD *)(a1 + 44) & 0x10) != 0 && !sub_8CB1B0(a1, &v20, v21, 32998, *(_DWORD *)(a1 + 76))
|| (*(_DWORD *)(a1 + 44) & 0x20) != 0 && !sub_8CAF84(a1, &v20, v21, 321, 2, a1 + 152)
|| (*(_DWORD *)(a1 + 44) & 0x80) != 0 && !sub_8CAF84(a1, &v20, v21, 530, 2, a1 + 192)
|| (*(_DWORD *)(a1 + 44) & 0x100) != 0 && !sub_8CAF14(a1, &v20, v21, 531, *(unsigned __int16 *)(a1 + 196))
|| (*(_DWORD *)(a1 + 44) & 0x200) != 0 && !sub_8CB470(a1, &v20, v21, 532, 6, *(_DWORD *)(a1 + 212))
|| (*(_DWORD *)(a1 + 44) & 0x1000) != 0 && !sub_8CBCC4(a1, &v20, v21)
|| (*(_DWORD *)(a1 + 44) & 0x4000) != 0
&& !sub_8CAD34(a1, &v20, v21, 333, *(_DWORD *)(a1 + 216), *(_DWORD *)(a1 + 220))
|| (*(_DWORD *)(a1 + 44) & 0x20000) != 0 && !sub_8CBF30(a1, &v20, v21) )
{
goto LABEL_241;
}
for ( i = 0; *(_DWORD *)(a1 + 660) > i; ++i )
{
v26 = *(_DWORD *)(*(_DWORD *)(a1 + 656) + 4 * i);
if ( *(unsigned __int16 *)(v26 + 24) > 0x41u
&& ((*(_DWORD *)(a1 + 4 * ((*(_WORD *)(v26 + 24) >> 5) + 10)) >> (*(_WORD *)(v26 + 24) & 0x1F)) & 1) != 0 )
{
switch ( *(_DWORD *)(v26 + 20) )
{
case 1:
if ( *(_DWORD *)(v26 + 8) != 2 )
_assert2();
if ( *(__int16 *)(v26 + 4) != -1 )
_assert2();
if ( *(_BYTE *)(v26 + 27) )
_assert2();
TIFFGetField(a1, *(_DWORD *)v26, &v17);
v27 = strlen(v17);
if ( !sub_8CAD34(a1, &v20, v21, (unsigned __int16)*(_DWORD *)v26, v27, v17) )
goto LABEL_241;
continue;
case 4:
if ( *(_DWORD *)(v26 + 8) != 3 )
_assert2();
if ( *(_WORD *)(v26 + 4) != 1 )
_assert2();
if ( *(_BYTE *)(v26 + 27) )
_assert2();
TIFFGetField(a1, *(_DWORD *)v26, &v16);
if ( !sub_8CAF14(a1, &v20, v21, (unsigned __int16)*(_DWORD *)v26, v16) )
goto LABEL_241;
continue;
case 6:
if ( *(_DWORD *)(v26 + 8) != 4 )
_assert2();
if ( *(_WORD *)(v26 + 4) != 1 )
_assert2();
if ( *(_BYTE *)(v26 + 27) )
_assert2();
TIFFGetField(a1, *(_DWORD *)v26, &v15);
if ( !sub_8CB1B0(a1, &v20, v21, (unsigned __int16)*(_DWORD *)v26, v15) )
goto LABEL_241;
continue;
case 0x28:
if ( *(_DWORD *)(v26 + 8) != 7 )
_assert2();
if ( *(__int16 *)(v26 + 4) != -3 )
_assert2();
if ( *(_BYTE *)(v26 + 27) != 1 )
_assert2();
TIFFGetField(a1, *(_DWORD *)v26, &v14, &v13);
if ( !sub_8CADAC(a1, &v20, v21, (unsigned __int16)*(_DWORD *)v26, v14, v13) )
goto LABEL_241;
continue;
default:
_assert2();
continue;
}
}
}
}
for ( j = 0; *(_DWORD *)(a1 + 224) > j; ++j )
{
switch ( *(_DWORD *)(*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j) + 8) )
{
case 1:
if ( !sub_8CAE24(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 2:
if ( !sub_8CAD34(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 3:
if ( !sub_8CAF84(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 4:
if ( !sub_8CB220(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 5:
if ( !sub_8CB470(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 6:
if ( !sub_8CAE9C(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 7:
if ( !sub_8CADAC(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 8:
if ( !sub_8CB138(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 9:
if ( !sub_8CB298(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 0xA:
if ( !sub_8CB4E8(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 0xB:
if ( !sub_8CB560(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 0xC:
if ( !sub_8CB5D8(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 0xD:
if ( !sub_8CB650(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 0x10:
if ( !sub_8CB310(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 0x11:
if ( !sub_8CB388(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
case 0x12:
if ( !sub_8CB954(
a1,
&v20,
v21,
(unsigned __int16)**(_DWORD **)(*(_DWORD *)(a1 + 228) + 12 * j),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 4),
*(_DWORD *)(*(_DWORD *)(a1 + 228) + 12 * j + 8)) )
goto LABEL_241;
break;
default:
_assert2();
break;
}
}
if ( v21 )
break;
v21 = TIFFmalloc(24 * v20);
if ( !v21 )
goto LABEL_176;
if ( a2 )
{
if ( !*(_QWORD *)(a1 + 16) && !sub_8CDA7C(a1) )
goto LABEL_241;
}
else
{
*(_QWORD *)(a1 + 16) = (((__int64 (__fastcall *)(_DWORD, _DWORD, _DWORD, _DWORD, int))*(_DWORD *)(a1 + 640))(
*(_DWORD *)(a1 + 628),
*(_DWORD *)(a1 + 640),
0,
0,
2)
+ 1)
& 0xFFFFFFFFFFFFFFFELL;
}
if ( a4 )
*a4 = *(_QWORD *)(a1 + 16);
if ( (*(_DWORD *)(a1 + 12) & 0x80000) != 0 )
v22 = 20 * v20 + 16;
else
v22 = 12 * v20 + 6;
*(_QWORD *)(a1 + 464) = *(_QWORD *)(a1 + 16) + (unsigned int)v22;
if ( (*(_DWORD *)(a1 + 12) & 0x80000) == 0 )
*(_QWORD *)(a1 + 464) = *(unsigned int *)(a1 + 464);
if ( *(_QWORD *)(a1 + 16) > *(_QWORD *)(a1 + 464) || (unsigned __int64)(unsigned int)v22 > *(_QWORD *)(a1 + 464) )
{
TIFFErrorExt(*(_DWORD *)(a1 + 628), "TIFFWriteDirectorySec", "Maximum TIFF file size exceeded");
goto LABEL_241;
}
if ( (*(_QWORD *)(a1 + 464) & 1) != 0 )
++*(_QWORD *)(a1 + 464);
if ( a2 )
++*(_WORD *)(a1 + 448);
}
if ( a2 && (*(_DWORD *)(a1 + 44) & 0x20000) != 0 && !*(_QWORD *)(a1 + 480) )
{
v28 = 0;
for ( k = (_WORD *)v21; ; k += 12 )
{
if ( v28 >= v20 )
_assert2();
if ( *k == 330 )
break;
++v28;
}
if ( (*(_DWORD *)(a1 + 12) & 0x80000) != 0 )
*(_QWORD *)(a1 + 480) = *(_QWORD *)(a1 + 16) + 20 * v28 + 20LL;
else
*(_QWORD *)(a1 + 480) = *(_QWORD *)(a1 + 16) + 12 * v28 + 10LL;
}
v23 = (_QWORD *)TIFFmalloc(v22);
if ( !v23 )
{
LABEL_176:
TIFFErrorExt(*(_DWORD *)(a1 + 628), "TIFFWriteDirectorySec", "Out of memory");
LABEL_241:
if ( v21 )
TIFFfree(v21);
if ( v23 )
TIFFfree(v23);
return 0;
}
if ( (*(_DWORD *)(a1 + 12) & 0x80000) != 0 )
{
v32 = v23;
*v23 = v20;
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabLong8(v32);
v32 += 4;
v33 = (_WORD *)v21;
for ( j = 0; j < v20; ++j )
{
*v32 = *v33;
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabShort(v32);
*++v32 = v33[1];
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabShort(v32);
TIFFmemcpy(++v32, v33 + 4, 8);
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabLong8(v32);
v32 += 4;
TIFFmemcpy(v32, v33 + 8, 8);
v32 += 4;
v33 += 12;
}
TIFFmemcpy(v32, a1 + 24, 8);
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabLong8(v32);
}
else
{
v30 = v23;
*(_WORD *)v23 = v20;
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabShort(v30);
++v30;
v31 = v21;
for ( j = 0; j < v20; ++j )
{
*v30 = *(_WORD *)v31;
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabShort(v30);
*++v30 = *(_WORD *)(v31 + 2);
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabShort(v30);
++v30;
v12 = *(_DWORD *)(v31 + 8);
TIFFmemcpy(v30, &v12, 4);
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabLong(v30);
v30 += 2;
TIFFmemcpy(v30, v31 + 16, 4);
v30 += 2;
v31 += 24;
}
v12 = *(_DWORD *)(a1 + 24);
if ( (*(_DWORD *)(a1 + 12) & 0x80) != 0 )
TIFFSwabLong(&v12);
TIFFmemcpy(v30, &v12, 4);
}
TIFFfree(v21);
v21 = 0;
LODWORD(v5) = (*(int (__fastcall **)(_DWORD, _DWORD, _DWORD, _DWORD, _DWORD))(a1 + 640))(
*(_DWORD *)(a1 + 628),
*(_DWORD *)(a1 + 640),
*(_DWORD *)(a1 + 16),
*(_DWORD *)(a1 + 20),
0);
if ( v5 != *(_QWORD *)(a1 + 16)
|| (v6 = (*(int (__fastcall **)(_DWORD, _QWORD *, int))(a1 + 636))(*(_DWORD *)(a1 + 628), v23, v22), v6 != v22) )
{
TIFFErrorExt(*(_DWORD *)(a1 + 628), "TIFFWriteDirectorySec", "IO error writing directory");
goto LABEL_241;
}
TIFFfree(v23);
if ( a3 )
{
TIFFFreeDirectory(a1);
*(_DWORD *)(a1 + 12) &= ~8u;
*(_DWORD *)(a1 + 12) &= ~0x200000u;
(*(void (__fastcall **)(int))(a1 + 564))(a1);
TIFFCreateDirectory(a1);
}
return 1;
}