//
// _TIFFMergeFields from 0xc33bd4 to 0xc33cf8 (292 bytes)
//
// 14 xrefs:
// > _TIFFSetupFields @ 0xc33db4
// > _TIFFFindOrRegisterField @ 0xc341d4
// > TIFFMergeFieldInfo @ 0xc34464
// > TIFFReadCustomDirectory @ 0xc3bce4
// > TIFFReadDirectory @ 0xc3c44c
// > TIFFInitCCITTFax3 @ 0xc48b44
// > TIFFInitCCITTFax3 @ 0xc48c68
// > TIFFInitCCITTFax4 @ 0xc48d1c
// > TIFFInitCCITTFax4 @ 0xc48e40
// > TIFFInitCCITTRLE @ 0xc48f20
// > TIFFInitCCITTRLEW @ 0xc490b0
// > TIFFInitSGILog @ 0xc575dc
// > TIFFPredictorInit @ 0xc5d2b8
// > ??> @ 0x70728
//
// 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 TIFFMergeFields(_QWORD *a1, int *a2, unsigned int a3)
{
void *v4; // x1
__int64 v7; // x2
void *v8; // x2
int *v9; // x21
__int64 v10; // x0
v4 = (void *)a1[126];
a1[128] = 0;
if ( v4 && (v7 = a1[127]) != 0 )
{
v8 = TIFFCheckRealloc(a1, v4, v7 + a3, 8, "for fields array");
a1[126] = v8;
}
else
{
v8 = TIFFCheckMalloc(a1, a3, 8, "for fields array");
a1[126] = v8;
}
if ( v8 )
{
if ( a3 )
{
v9 = &a2[12 * a3];
do
{
while ( TIFFFindField(a1, *a2, 0) )
{
a2 += 12;
if ( a2 == v9 )
goto LABEL_10;
}
v10 = a1[127];
*(_QWORD *)(a1[126] + 8 * v10) = a2;
a2 += 12;
a1[127] = v10 + 1;
}
while ( a2 != v9 );
LABEL_10:
v8 = (void *)a1[126];
}
qsort(v8, a1[127], 8u, (int (*)(const void *, const void *))sub_C3398C);
return a3;
}
else
{
TIFFErrorExt(a1[119], "_TIFFMergeFields", "Failed to allocate fields array");
return 0;
}
}