//
// sub_BF9DF0 from 0xbf9df0 to 0xbf9f2c (316 bytes)
//
// 1 xrefs:
// > sub_BF7EF4 @ 0xbf7f24
//
// 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_BF9DF0(__int64 a1)
{
__int64 v2; // x23
__int64 result; // x0
__int64 *v4; // x21
int v5; // w20
__int64 v6; // x22
__int64 v7; // x25
__int64 v8; // x26
__int64 v9; // x1
__int64 v10; // x22
__int64 v11; // x25
__int64 v12; // x1
_QWORD v13[2]; // [xsp+50h] [xbp+50h]
_QWORD v14[2]; // [xsp+60h] [xbp+60h]
v2 = *(_QWORD *)(a1 + 560);
if ( *(_DWORD *)(a1 + 348) )
sub_BF85BC(*(_QWORD *)(a1 + 560));
result = *(unsigned int *)(a1 + 372);
v13[0] = 0;
v13[1] = 0;
v14[0] = 0;
v14[1] = 0;
if ( (int)result > 0 )
{
v4 = (__int64 *)(a1 + 376);
v5 = 0;
do
{
v6 = *v4;
if ( !*(_DWORD *)(a1 + 460) && !*(_DWORD *)(a1 + 468) )
{
v7 = *(int *)(v6 + 20);
if ( !*((_DWORD *)v13 + v7) )
{
v8 = a1 + 8 * v7;
v9 = *(_QWORD *)(v8 + 160);
if ( !v9 )
{
v9 = jpeg_alloc_huff_table(a1);
*(_QWORD *)(v8 + 160) = v9;
}
sub_BF81A0((void (__fastcall ***)(_QWORD))a1, v9, *(_QWORD *)(v2 + 8 * (v7 + 16)));
*((_DWORD *)v13 + v7) = 1;
}
}
if ( *(_DWORD *)(a1 + 464) )
{
v10 = *(int *)(v6 + 24);
if ( !*((_DWORD *)v14 + v10) )
{
v11 = a1 + 8 * v10;
v12 = *(_QWORD *)(v11 + 192);
if ( !v12 )
{
v12 = jpeg_alloc_huff_table(a1);
*(_QWORD *)(v11 + 192) = v12;
}
sub_BF81A0((void (__fastcall ***)(_QWORD))a1, v12, *(_QWORD *)(v2 + 8 * (v10 + 20)));
*((_DWORD *)v14 + v10) = 1;
}
}
result = *(unsigned int *)(a1 + 372);
++v5;
++v4;
}
while ( (int)result > v5 );
}
return result;
}