//
// jinit_d_main_controller from 0xc0f650 to 0xc0f848 (504 bytes)
//
// 2 xrefs:
// > jinit_master_decompress @ 0xc140a8
// > ??> @ 0x671a0
//
// 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 jinit_d_main_controller(__int64 a1, int a2)
{
__int64 (__fastcall *(__fastcall **v4)(__int64, int))(__int64); // x22
__int64 result; // x0
int v6; // w24
__int64 v7; // x27
_DWORD *v8; // x23
int v9; // w1
_DWORD *v10; // x20
int v11; // w24
__int64 v12; // x25
int v13; // w26
int v14; // w2
int v15; // w20
int v16; // w20
__int64 v17; // x0
__int64 v18; // x21
int v19; // w4
int v20; // w23
__int64 *v21; // x22
int v22; // w21
int v23; // w5
int v24; // w3
int v25; // w6
int v26; // w2
int v27; // w1
void (__fastcall *v28)(__int64); // x2
void (__fastcall *v29)(__int64); // x2
v4 = (__int64 (__fastcall *(__fastcall **)(__int64, int))(__int64))(**(__int64 (***)(void))(a1 + 8))();
*(_QWORD *)(a1 + 584) = v4;
*v4 = sub_C0F178;
if ( a2 )
{
v28 = **(void (__fastcall ***)(__int64))a1;
*(_DWORD *)(*(_QWORD *)a1 + 40LL) = 3;
v28(a1);
}
result = *(unsigned int *)(*(_QWORD *)(a1 + 640) + 16LL);
if ( (_DWORD)result )
{
v6 = *(_DWORD *)(a1 + 428);
if ( v6 <= 1 )
{
v29 = **(void (__fastcall ***)(__int64))a1;
*(_DWORD *)(*(_QWORD *)a1 + 40LL) = 48;
v29(a1);
v6 = *(_DWORD *)(a1 + 428);
}
v7 = *(_QWORD *)(a1 + 584);
result = (**(__int64 (__fastcall ***)(__int64, __int64, __int64))(a1 + 8))(a1, 1, 16LL * *(_DWORD *)(a1 + 56));
v8 = *(_DWORD **)(a1 + 304);
v9 = *(_DWORD *)(a1 + 56);
*(_QWORD *)(v7 + 104) = result;
v10 = v8;
*(_QWORD *)(v7 + 112) = result + 8LL * v9;
if ( v9 > 0 )
{
v11 = v6 + 4;
v12 = 0;
v13 = 0;
do
{
v14 = v8[3];
v15 = v8[10];
++v13;
v8 += 24;
v16 = v14 * v15 / *(_DWORD *)(a1 + 428);
v17 = (**(__int64 (__fastcall ***)(__int64))(a1 + 8))(a1) + 8LL * v16;
v18 = v17 + 8LL * v16 * v11;
v9 = *(_DWORD *)(a1 + 56);
*(_QWORD *)(*(_QWORD *)(v7 + 104) + v12) = v17;
result = *(_QWORD *)(v7 + 112);
*(_QWORD *)(result + v12) = v18;
v12 += 8;
}
while ( v13 < v9 );
v10 = *(_DWORD **)(a1 + 304);
}
v19 = *(_DWORD *)(a1 + 428);
v20 = v19 + 2;
}
else
{
v20 = *(_DWORD *)(a1 + 428);
v9 = *(_DWORD *)(a1 + 56);
v10 = *(_DWORD **)(a1 + 304);
v19 = v20;
}
v21 = (__int64 *)(v4 + 2);
v22 = 0;
if ( v9 > 0 )
{
while ( 1 )
{
v23 = v10[10];
v24 = v10[3];
v25 = v10[9];
++v22;
v26 = v10[7];
v10 += 24;
result = (*(__int64 (__fastcall **)(__int64, __int64, _QWORD, _QWORD))(*(_QWORD *)(a1 + 8) + 16LL))(
a1,
1,
(unsigned int)(v25 * v26),
(unsigned int)(v24 * v23 / v19 * v20));
v27 = *(_DWORD *)(a1 + 56);
*v21++ = result;
if ( v27 <= v22 )
break;
v19 = *(_DWORD *)(a1 + 428);
}
}
return result;
}