//
// sub_C2BC44 from 0xc2bc44 to 0xc2be80 (572 bytes)
//
// 2 xrefs:
// > jinit_memory_mgr @ 0xc2c310
// > jinit_memory_mgr @ 0xc2c318
//
// 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_C2BC44(__int64 result)
{
__int64 v1; // x22
__int64 v2; // x1
__int64 v3; // x21
__int64 v4; // x20
unsigned int v5; // w2
unsigned int v6; // w4
unsigned int v7; // w3
__int64 v8; // x1
unsigned int v9; // w2
unsigned int v10; // w3
unsigned int v11; // w4
_QWORD *v12; // x23
__int64 v13; // x20
__int64 i; // x19
__int64 v15; // x3
unsigned int v16; // w4
__int64 j; // x19
__int64 v18; // x3
unsigned int v19; // w4
unsigned int v20; // w2
unsigned int v21; // w2
v1 = *(_QWORD *)(result + 8);
v2 = *(_QWORD *)(v1 + 136);
if ( v2 )
{
v3 = 0;
v4 = 0;
do
{
while ( *(_QWORD *)v2 )
{
v2 = *(_QWORD *)(v2 + 48);
if ( !v2 )
goto LABEL_6;
}
v5 = *(_DWORD *)(v2 + 12);
v6 = *(_DWORD *)(v2 + 16);
v7 = *(_DWORD *)(v2 + 8);
v2 = *(_QWORD *)(v2 + 48);
v4 += v6 * (unsigned __int64)v5;
v3 += v5 * (unsigned __int64)v7;
}
while ( v2 );
LABEL_6:
v8 = *(_QWORD *)(v1 + 144);
if ( v8 )
goto LABEL_9;
}
else
{
v8 = *(_QWORD *)(v1 + 144);
v3 = 0;
v4 = 0;
if ( !v8 )
return result;
do
{
LABEL_9:
while ( *(_QWORD *)v8 )
{
v8 = *(_QWORD *)(v8 + 48);
if ( !v8 )
goto LABEL_11;
}
v9 = *(_DWORD *)(v8 + 12);
v10 = *(_DWORD *)(v8 + 16);
v11 = *(_DWORD *)(v8 + 8);
v8 = *(_QWORD *)(v8 + 48);
v4 += (v10 * (unsigned __int64)v9) << 7;
v3 += (v9 * (unsigned __int64)v11) << 7;
}
while ( v8 );
}
LABEL_11:
if ( v4 > 0 )
{
v12 = (_QWORD *)result;
result = jpeg_mem_available();
if ( result >= v3 )
{
v13 = 1000000000;
}
else
{
v13 = result / v4;
if ( v13 <= 0 )
v13 = 1;
}
for ( i = *(_QWORD *)(v1 + 136); i; i = *(_QWORD *)(i + 48) )
{
while ( *(_QWORD *)i )
{
i = *(_QWORD *)(i + 48);
if ( !i )
goto LABEL_22;
}
v15 = *(unsigned int *)(i + 8);
v16 = *(_DWORD *)(i + 16);
if ( v13 <= ((unsigned int)v15 - 1LL) / v16 )
{
v20 = *(_DWORD *)(i + 12);
*(_DWORD *)(i + 20) = v16 * v13;
jpeg_open_backing_store(v12, i + 56, (unsigned int)v15 * (unsigned __int64)v20, v15);
*(_DWORD *)(i + 44) = 1;
LODWORD(v15) = *(_DWORD *)(i + 20);
}
else
{
*(_DWORD *)(i + 20) = v15;
}
result = sub_C2B8BC(v12, 1, *(_DWORD *)(i + 12), v15);
*(_DWORD *)(i + 24) = *(_DWORD *)(v1 + 160);
*(_QWORD *)i = result;
*(_DWORD *)(i + 28) = 0;
*(_DWORD *)(i + 32) = 0;
*(_DWORD *)(i + 40) = 0;
}
LABEL_22:
for ( j = *(_QWORD *)(v1 + 144); j; j = *(_QWORD *)(j + 48) )
{
while ( *(_QWORD *)j )
{
j = *(_QWORD *)(j + 48);
if ( !j )
return result;
}
v18 = *(unsigned int *)(j + 8);
v19 = *(_DWORD *)(j + 16);
if ( v13 <= ((unsigned int)v18 - 1LL) / v19 )
{
v21 = *(_DWORD *)(j + 12);
*(_DWORD *)(j + 20) = v19 * v13;
jpeg_open_backing_store(v12, j + 56, ((unsigned int)v18 * (unsigned __int64)v21) << 7, v18);
*(_DWORD *)(j + 44) = 1;
LODWORD(v18) = *(_DWORD *)(j + 20);
}
else
{
*(_DWORD *)(j + 20) = v18;
}
result = sub_C2BA8C(v12, 1, *(_DWORD *)(j + 12), v18);
*(_DWORD *)(j + 24) = *(_DWORD *)(v1 + 160);
*(_QWORD *)j = result;
*(_DWORD *)(j + 28) = 0;
*(_DWORD *)(j + 32) = 0;
*(_DWORD *)(j + 40) = 0;
}
}
return result;
}