//
// jpeg_add_quant_table from 0x6717f0 to 0x6718b6 (198 bytes)
//
// 4 xrefs:
// > jpeg_default_qtables @ 0x6718cc
// > jpeg_default_qtables @ 0x6718dc
// > jpeg_set_linear_quality @ 0x6718fe
// > jpeg_set_linear_quality @ 0x67190e
//
// 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
//
int __fastcall jpeg_add_quant_table(_DWORD *a1, unsigned int a2, int a3, int a4, int a5)
{
_DWORD *v9; // r8
int result; // r0
int v11; // r3
int v12; // lr
int v13; // r5
int v14; // r1
int v15; // r2
__int16 v16; // r6
int v17; // t1
int v18; // r4
if ( a1[5] != 100 )
{
*(_DWORD *)(*a1 + 20) = 21;
*(_DWORD *)(*a1 + 24) = a1[5];
(*(void (__fastcall **)(_DWORD *))*a1)(a1);
}
if ( a2 > 3 )
{
*(_DWORD *)(*a1 + 20) = 32;
*(_DWORD *)(*a1 + 24) = a2;
(*(void (__fastcall **)(_DWORD *))*a1)(a1);
}
v9 = &a1[a2];
result = v9[22];
if ( !result )
{
result = jpeg_alloc_quant_table((int)a1);
v9[22] = result;
}
v11 = a5;
LOWORD(v12) = -31457;
v13 = a3 - 4;
v14 = 0;
if ( a5 )
v11 = 1;
HIWORD(v12) = 20971;
while ( 1 )
{
v17 = *(_DWORD *)(v13 + 4);
v13 += 4;
v18 = v11;
v15 = ((int)((unsigned __int64)((v17 * a4 + 50) * (__int64)v12) >> 32) >> 5) - ((v17 * a4 + 50) >> 31);
if ( v15 <= 0 )
{
LOWORD(v15) = 1;
LABEL_14:
v16 = v15;
goto LABEL_15;
}
if ( v15 < 0x8000 )
{
if ( v15 > 255 )
v18 = v11 & 1;
else
v18 = 0;
}
else
{
LOWORD(v15) = 0x7FFF;
}
v16 = 255;
if ( !v18 )
goto LABEL_14;
LABEL_15:
*(_WORD *)(result + 2 * v14++) = v16;
if ( v14 == 64 )
break;
result = v9[22];
}
*(_DWORD *)(v9[22] + 128) = 0;
return result;
}