//
// MusicDownloadManager::getAllMusicObjectsSorted from 0x10065e370 to 0x10065e574 (516 bytes)
//
// 1 xrefs:
// > MusicSearchResult::updateObjects_1 @ 0x1006684ae
//
// This function is hookable on this platform (idp: pc, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 12:34:55 +0000
//
__int64 __fastcall MusicDownloadManager::getAllMusicObjectsSorted(__int64 a1, int a2, int a3)
{
int v3; // r13d
__int64 *v4; // rbx
__int64 v5; // rcx
__int64 v6; // rax
unsigned int v7; // eax
__int64 v8; // r12
__int64 v9; // rax
__int64 v10; // r14
__int64 v11; // r15
__int64 v12; // rsi
__int64 v13; // rsi
int (__cdecl *v14)(const void *, const void *); // rcx
__int64 v15; // rax
__int64 *v16; // r15
int v17; // eax
__int64 *v18; // r14
__int64 v19; // rax
v3 = a3 + 100 * a2;
v4 = (__int64 *)(a1 + 496);
v5 = *(_QWORD *)(a1 + 496);
if ( !v5 )
goto LABEL_8;
v6 = a1 + 496;
do
{
if ( *(_DWORD *)(v5 + 32) >= v3 )
v6 = v5;
v5 = *(_QWORD *)(v5 + 8LL * (*(_DWORD *)(v5 + 32) < v3));
}
while ( v5 );
if ( (__int64 *)v6 != v4 && v3 >= *(_DWORD *)(v6 + 32) )
return *(_QWORD *)(v6 + 40);
LABEL_8:
v7 = cocos2d::CCDictionary::count(*(_QWORD *)(a1 + 440));
v8 = sub_1007FEC20(v7);
v9 = *(_QWORD *)(a1 + 440);
if ( v9 )
{
v10 = *(_QWORD *)(v9 + 56);
if ( v10 )
{
v11 = *(_QWORD *)(v10 + 288);
if ( a2 == -1 )
{
sub_1007FEBF0(v8, *(_QWORD *)(v10 + 264));
while ( v11 )
{
v13 = *(_QWORD *)(v11 + 264);
v11 = *(_QWORD *)(v11 + 288);
sub_1007FEBF0(v8, v13);
}
}
else
{
while ( 1 )
{
v12 = *(_QWORD *)(v10 + 264);
v10 = v11;
if ( *(_DWORD *)(v12 + 400) == a2 )
sub_1007FEBF0(v8, v12);
if ( !v11 )
break;
v11 = *(_QWORD *)(v11 + 288);
}
}
}
}
if ( (unsigned int)sub_1007FEF90(v8) >= 2 )
{
if ( (unsigned int)(a3 - 1) > 5 )
v14 = (int (__cdecl *)(const void *, const void *))sub_1006496A0;
else
v14 = (int (__cdecl *)(const void *, const void *))off_100B835E0[a3 - 1];
qsort(*(void **)(*(_QWORD *)(v8 + 56) + 16LL), **(unsigned int **)(v8 + 56), 8u, v14);
}
cocos2d::CCObject::retain(v8);
v15 = *v4;
v16 = (__int64 *)(a1 + 496);
LABEL_25:
if ( v15 )
{
do
{
v16 = (__int64 *)v15;
v17 = *(_DWORD *)(v15 + 32);
if ( v3 < v17 )
{
v15 = *v16;
v4 = v16;
goto LABEL_25;
}
if ( v3 <= v17 )
goto LABEL_33;
v15 = v16[1];
}
while ( v15 );
v4 = v16 + 1;
}
v18 = v16;
v16 = (__int64 *)operator new(0x30u);
*((_DWORD *)v16 + 8) = v3;
v16[5] = 0;
*(_OWORD *)v16 = 0;
v16[2] = (__int64)v18;
*v4 = (__int64)v16;
v19 = **(_QWORD **)(a1 + 488);
if ( v19 )
*(_QWORD *)(a1 + 488) = v19;
sub_10001B680(*(__int64 **)(a1 + 496), v16);
++*(_QWORD *)(a1 + 504);
LABEL_33:
v16[5] = v8;
return v8;
}