//
// sub_C0373C from 0xc0373c to 0xc03dc0 (1668 bytes)
//
// 2 xrefs:
// > jpeg_write_coefficients @ 0xc03f38
// > jpeg_write_coefficients @ 0xc03f40
//
// 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_C0373C(__int64 a1)
{
int v2; // w27
__int64 v3; // x20
unsigned int v4; // w22
__int64 v5; // x19
__int64 v6; // x0
int v7; // w25
int v8; // w1
unsigned int v9; // w24
__int64 v10; // x26
unsigned int v11; // w0
__int64 v12; // x18
int v13; // w0
_DWORD *v14; // x30
int v15; // w2
int v16; // w3
int v17; // w17
unsigned int v18; // w21
int v19; // w5
int v20; // w17
__int64 v21; // x8
int v22; // w16
int v23; // w15
int v24; // w14
int v25; // w13
int v26; // w12
int v27; // w11
int v28; // w10
int v29; // w9
int v30; // w6
int v31; // w1
_QWORD *v32; // x1
_WORD *v33; // x7
bool v34; // cc
int v35; // w6
_WORD *v36; // x7
int v37; // w4
_WORD *v38; // x9
int v39; // w7
_WORD *v40; // x9
_WORD *v41; // x9
_WORD *v42; // x9
_WORD *v43; // x9
_WORD *v44; // x9
_WORD *v45; // x7
int v46; // w9
_WORD *v47; // x1
unsigned __int64 v48; // x1
unsigned __int64 v49; // x1
__int64 result; // x0
_DWORD *v51; // x27
__int64 v52; // x0
unsigned int v53; // [xsp+6Ch] [xbp+6Ch]
_QWORD v54[4]; // [xsp+70h] [xbp+70h]
_QWORD v55[10]; // [xsp+90h] [xbp+90h] BYREF
v2 = *(_DWORD *)(a1 + 372);
v53 = *(_DWORD *)(a1 + 408) - 1;
v3 = *(_QWORD *)(a1 + 520);
v4 = *(_DWORD *)(a1 + 368) - 1;
if ( v2 > 0 )
{
v5 = 0;
do
{
v6 = (*(__int64 (__fastcall **)(__int64, _QWORD, _QWORD, _QWORD, _QWORD))(*(_QWORD *)(a1 + 8) + 64LL))(
a1,
*(_QWORD *)(*(_QWORD *)(v3 + 32) + 8LL * *(int *)(*(_QWORD *)(a1 + 8 * v5 + 376) + 4LL)),
(unsigned int)(*(_DWORD *)(*(_QWORD *)(a1 + 8 * v5 + 376) + 12LL) * *(_DWORD *)(v3 + 16)),
*(unsigned int *)(*(_QWORD *)(a1 + 8 * v5 + 376) + 12LL),
0);
v2 = *(_DWORD *)(a1 + 372);
v54[v5++] = v6;
}
while ( v2 > (int)v5 );
}
v7 = *(_DWORD *)(v3 + 24);
v8 = *(_DWORD *)(v3 + 28);
if ( v7 >= v8 )
goto LABEL_58;
v9 = *(_DWORD *)(v3 + 20);
v10 = 8LL * v7;
v11 = *(_DWORD *)(a1 + 408);
do
{
if ( v11 <= v9 )
goto LABEL_57;
while ( 1 )
{
if ( v2 > 0 )
{
v12 = 0;
v13 = 0;
while ( 1 )
{
v14 = *(_DWORD **)(a1 + 8 * v12 + 376);
v15 = v14[14];
v16 = v15;
if ( v53 <= v9 )
v16 = v14[18];
v17 = v14[15];
if ( v17 > 0 )
break;
LABEL_40:
if ( v2 <= (int)++v12 )
goto LABEL_41;
}
v18 = *(_DWORD *)(v3 + 16);
v19 = v7;
v20 = v7 + v17;
v21 = v10;
while ( 1 )
{
if ( v4 <= v18 && v19 >= v14[19]
|| (v48 = *(_QWORD *)(v54[v12] + v21) + ((unsigned __int64)(v9 * v15) << 7), v16 <= 0) )
{
v22 = 9;
v23 = 8;
v24 = 7;
v25 = 6;
v26 = 5;
v27 = 4;
v28 = 3;
v29 = 2;
v30 = 1;
v31 = 0;
}
else
{
v55[v13] = v48;
if ( v16 == 1 )
{
++v13;
v22 = 10;
v23 = 9;
v24 = 8;
v25 = 7;
v26 = 6;
v27 = 5;
v28 = 4;
v29 = 3;
v30 = 2;
v31 = 1;
}
else
{
v55[v13 + 1] = v48 + 128;
if ( v16 == 2 )
{
v13 += 2;
v22 = 11;
v23 = 10;
v24 = 9;
v25 = 8;
v26 = 7;
v27 = 6;
v28 = 5;
v29 = 4;
v30 = 3;
v31 = 2;
}
else
{
v55[v13 + 2] = v48 + 256;
if ( v16 == 3 )
{
v13 += 3;
v22 = 12;
v23 = 11;
v24 = 10;
v25 = 9;
v26 = 8;
v27 = 7;
v28 = 6;
v29 = 5;
v30 = 4;
v31 = 3;
}
else
{
v55[v13 + 3] = v48 + 384;
if ( v16 == 4 )
{
v13 += 4;
v22 = 13;
v23 = 12;
v24 = 11;
v25 = 10;
v26 = 9;
v27 = 8;
v28 = 7;
v29 = 6;
v30 = 5;
v31 = 4;
}
else
{
v55[v13 + 4] = v48 + 512;
if ( v16 == 5 )
{
v13 += 5;
v22 = 14;
v23 = 13;
v24 = 12;
v25 = 11;
v26 = 10;
v27 = 9;
v28 = 8;
v29 = 7;
v30 = 6;
v31 = 5;
}
else
{
v55[v13 + 5] = v48 + 640;
if ( v16 == 6 )
{
v13 += 6;
v22 = 15;
v23 = 14;
v24 = 13;
v25 = 12;
v26 = 11;
v27 = 10;
v28 = 9;
v29 = 8;
v30 = 7;
v31 = 6;
}
else
{
v55[v13 + 6] = v48 + 768;
if ( v16 == 7 )
{
v13 += 7;
v22 = 16;
v23 = 15;
v24 = 14;
v25 = 13;
v26 = 12;
v27 = 11;
v28 = 10;
v29 = 9;
v30 = 8;
v31 = 7;
}
else
{
v55[v13 + 7] = v48 + 896;
if ( v16 == 8 )
{
v13 += 8;
v22 = 17;
v23 = 16;
v24 = 15;
v25 = 14;
v26 = 13;
v27 = 12;
v28 = 11;
v29 = 10;
v30 = 9;
v31 = 8;
}
else
{
v55[v13 + 8] = v48 + 1024;
v49 = v48 + 1152;
if ( v16 == 9 )
{
v13 += 9;
v22 = 18;
v23 = 17;
v24 = 16;
v25 = 15;
v26 = 14;
v27 = 13;
v28 = 12;
v29 = 11;
v30 = 10;
v31 = 9;
}
else
{
v55[v13 + 9] = v49;
v13 += 10;
v22 = 19;
v23 = 18;
v24 = 17;
v25 = 16;
v26 = 15;
v27 = 14;
v28 = 13;
v29 = 12;
v30 = 11;
v31 = 10;
}
}
}
}
}
}
}
}
}
}
if ( v15 <= v31 )
goto LABEL_26;
v32 = (_QWORD *)(v3 + 8LL * v13);
v33 = (_WORD *)v32[5];
v34 = v15 <= v30;
v55[v13] = v33;
v35 = v13 + 1;
*v33 = *(_WORD *)v55[v13 - 1];
if ( v34 )
goto LABEL_44;
v36 = (_WORD *)v32[6];
v55[v35] = v36;
v37 = v13 + 2;
*v36 = *(_WORD *)v55[v13];
if ( v15 <= v29 )
goto LABEL_39;
v38 = (_WORD *)v32[7];
v55[v37] = v38;
v39 = v13 + 3;
*v38 = *(_WORD *)v55[v35];
if ( v15 <= v28 )
{
LABEL_45:
v13 = v39;
goto LABEL_26;
}
v40 = (_WORD *)v32[8];
v55[v39] = v40;
v35 = v13 + 4;
*v40 = *(_WORD *)v55[v37];
if ( v15 <= v27 )
goto LABEL_44;
v41 = (_WORD *)v32[9];
v55[v35] = v41;
v37 = v13 + 5;
*v41 = *(_WORD *)v55[v39];
if ( v15 <= v26 )
goto LABEL_39;
v42 = (_WORD *)v32[10];
v55[v37] = v42;
v39 = v13 + 6;
*v42 = *(_WORD *)v55[v35];
if ( v15 <= v25 )
goto LABEL_45;
v43 = (_WORD *)v32[11];
v55[v39] = v43;
v35 = v13 + 7;
*v43 = *(_WORD *)v55[v37];
if ( v15 <= v24 )
{
LABEL_44:
v13 = v35;
LABEL_26:
++v19;
v21 += 8;
if ( v19 == v20 )
goto LABEL_40;
}
else
{
v44 = (_WORD *)v32[12];
v55[v35] = v44;
v37 = v13 + 8;
*v44 = *(_WORD *)v55[v39];
if ( v15 > v23 )
{
v45 = (_WORD *)v32[13];
v55[v37] = v45;
v46 = v13 + 9;
*v45 = *(_WORD *)v55[v35];
if ( v15 <= v22 )
{
v13 += 9;
}
else
{
v47 = (_WORD *)v32[14];
v13 += 10;
v55[v46] = v47;
*v47 = *(_WORD *)v55[v37];
}
goto LABEL_26;
}
LABEL_39:
++v19;
v13 = v37;
v21 += 8;
if ( v19 == v20 )
goto LABEL_40;
}
}
}
LABEL_41:
result = (*(__int64 (__fastcall **)(__int64, _QWORD *))(*(_QWORD *)(a1 + 560) + 8LL))(a1, v55);
if ( !(_DWORD)result )
{
*(_DWORD *)(v3 + 24) = v7;
*(_DWORD *)(v3 + 20) = v9;
return result;
}
v11 = *(_DWORD *)(a1 + 408);
if ( v11 <= ++v9 )
break;
v2 = *(_DWORD *)(a1 + 372);
}
v8 = *(_DWORD *)(v3 + 28);
v2 = *(_DWORD *)(a1 + 372);
LABEL_57:
++v7;
*(_DWORD *)(v3 + 20) = 0;
v10 += 8;
v9 = 0;
}
while ( v7 < v8 );
LABEL_58:
v34 = v2 <= 1;
v51 = *(_DWORD **)(a1 + 520);
++*(_DWORD *)(v3 + 16);
if ( v34 )
{
v52 = *(_QWORD *)(a1 + 376);
if ( v51[4] >= (unsigned int)(*(_DWORD *)(a1 + 368) - 1) )
v51[7] = *(_DWORD *)(v52 + 76);
else
v51[7] = *(_DWORD *)(v52 + 12);
}
else
{
v51[7] = 1;
}
v51[5] = 0;
v51[6] = 0;
return 1;
}