//
// sub_4F598 from 0x4f598 to 0x4f6dc (324 bytes)
//
// 4 xrefs:
// > sub_753C4 @ 0x7740e
// > sub_7AB38 @ 0x7b3d4
// > sub_838A4 @ 0x8463c
// > sub_87B50 @ 0x8888a
//
// 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 sub_4F598(int *a1, int a2)
{
_DWORD *v4; // r0
int v5; // r1
int i; // r2
int v7; // r0
int v8; // r6
int v9; // r5
int v10; // r1
int result; // r0
int v12; // r1
int v13; // r0
int v14; // r6
int v15; // r5
int v16; // r8
int v17; // r0
int v18; // r0
int v19; // r1
int v20; // r0
a1[266] = a2;
v4 = (_DWORD *)sub_BD580(
*(int *)((char *)&dword_14C + (_DWORD)off_E8000),
172 * a2,
"../../src/fmod_music.cpp",
597,
0);
a1[267] = (int)v4;
if ( !v4 )
return 38;
v5 = a1[266];
for ( i = 0; i < v5; ++i )
{
*v4 = v4;
v4[1] = v4;
v4[2] = 0;
v4 += 43;
}
a1[201] = 2 * a2;
v7 = sub_BD580(*(int *)((char *)&dword_14C + (_DWORD)off_E8000), 784 * a2, "../../src/fmod_music.cpp", 612, 0);
a1[268] = v7;
if ( !v7 )
return 38;
v8 = 0;
v9 = 0;
while ( 1 )
{
v10 = a1[201];
if ( v9 >= v10 )
break;
sub_4B398((_DWORD *)(v7 + v8));
result = sub_4B46C((_DWORD *)(a1[268] + v8), v9, a1[4]);
if ( result )
return result;
v7 = a1[268];
++v9;
v12 = v7 + v8;
v8 += 392;
*(_DWORD *)(v12 + 380) = 1000;
}
v13 = sub_BD580(*(int *)((char *)&dword_14C + (_DWORD)off_E8000), 552 * v10, "../../src/fmod_music.cpp", 625, 0);
a1[269] = v13;
if ( !v13 )
return 38;
v14 = 332;
v15 = 0;
v16 = 0;
while ( v16 < a1[201] )
{
sub_44E88((_DWORD *)(a1[269] + v15));
v17 = a1[269] + v15;
*(_DWORD *)(a1[268] + v14) = v17;
(*(void (__fastcall **)(int, int, int, _DWORD))(*(_DWORD *)v17 + 12))(v17, v16, a1[4], *(_DWORD *)(a1[4] + 1112));
v18 = a1[268];
v15 += 552;
++v16;
v19 = *(_DWORD *)(v18 + v14);
v20 = v18 + v14 - 332;
v14 += 392;
*(_DWORD *)(v19 + 12) = v20;
*(_DWORD *)(v19 + 32) |= 0x10000u;
}
return 0;
}