//
// sub_180113720 from 0x180113720 to 0x180113945 (549 bytes)
//
// 2 xrefs:
// > ??> @ 0x18016f5a8
// > ??> @ 0x180201d3c
//
// 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_180113720(__int64 a1)
{
struct _RTL_CRITICAL_SECTION *v1; // r12
int v4; // ebx
__int64 v5; // rcx
_DWORD *v6; // rax
int i; // ecx
__int64 v8; // rdi
__int64 v9; // rcx
__int64 v10; // rdx
int v11; // ecx
int v12; // eax
__int64 v13; // rcx
__int64 v14; // rax
__int64 *v15; // r14
int v16; // ebx
__int64 v17; // rcx
_DWORD *v18; // rax
int v19; // edi
__int64 v20; // r15
void *v21; // rcx
unsigned int v22; // esi
__int64 v23; // rdx
int v24; // ecx
int v25; // eax
_DWORD *v26; // rcx
__int64 v27; // rax
v1 = *(struct _RTL_CRITICAL_SECTION **)(a1 + 56);
FMOD_OS_CriticalSection_Enter(v1);
if ( (*(_DWORD *)(a1 + 68))-- != 1 )
goto LABEL_38;
if ( *(_DWORD *)(a1 + 88) )
{
v4 = 0;
v5 = 0;
v6 = *(_DWORD **)(a1 + 80);
while ( *v6 == -1 )
{
++v4;
++v5;
++v6;
if ( v5 == *(_DWORD *)(a1 + 88) )
goto LABEL_17;
}
for ( i = *(_DWORD *)(*(_QWORD *)(a1 + 80) + 4LL * v4); i != -1; i = *(_DWORD *)(v13 + 4LL * v4) )
{
do
{
v8 = 2LL * i;
v9 = *(_QWORD *)(*(_QWORD *)(a1 + 96) + 16LL * i + 8);
*(_DWORD *)(v9 + 24) = 1;
sub_1800C14F0(*(void **)(v9 + 8));
i = *(_DWORD *)(*(_QWORD *)(a1 + 96) + 8 * v8 + 4);
}
while ( i != -1 );
v10 = *(int *)(a1 + 88);
v11 = v4 + 1;
v12 = v4;
v4 = 0;
if ( v12 != -1 )
v4 = v11;
if ( v4 == (_DWORD)v10 )
break;
v13 = *(_QWORD *)(a1 + 80);
v14 = v4;
while ( *(_DWORD *)(v13 + 4 * v14) == -1 )
{
++v4;
if ( ++v14 == v10 )
goto LABEL_17;
}
}
}
LABEL_17:
v15 = (__int64 *)(a1 + 120);
if ( !*(_DWORD *)(a1 + 128) )
goto LABEL_35;
v16 = 0;
v17 = 0;
v18 = (_DWORD *)*v15;
while ( *v18 == -1 )
{
++v16;
++v17;
++v18;
if ( v17 == *(_DWORD *)(a1 + 128) )
goto LABEL_35;
}
v19 = *(_DWORD *)(*v15 + 4LL * v16);
if ( v19 == -1 )
{
LABEL_35:
v22 = sub_180087CB0(v15);
if ( v22 )
goto LABEL_39;
v22 = sub_1801135C0((_DWORD **)v15 + 2);
if ( v22 )
goto LABEL_39;
*((_DWORD *)v15 + 8) = -1;
*((_DWORD *)v15 + 9) = 0;
LABEL_38:
v22 = 0;
goto LABEL_39;
}
while ( 1 )
{
v20 = *(_QWORD *)(v15[2] + 16LL * v19 + 8);
v21 = *(void **)(v20 + 16);
if ( v21 )
{
v22 = FMOD_OS_File_Close(v21);
if ( v22 )
break;
}
sub_1800B6AA0(*((_QWORD *)off_1801AED20 + 52), (_DWORD *)v20);
v19 = *(_DWORD *)(v15[2] + 16LL * v19 + 4);
if ( v19 == -1 )
{
v23 = *((int *)v15 + 2);
v24 = v16 + 1;
v25 = v16;
v16 = 0;
if ( v25 != -1 )
v16 = v24;
if ( v16 == (_DWORD)v23 )
goto LABEL_35;
v26 = (_DWORD *)*v15;
v27 = v16;
while ( v26[v27] == -1 )
{
++v16;
if ( ++v27 == v23 )
goto LABEL_35;
}
v19 = v26[v16];
if ( v19 == -1 )
goto LABEL_35;
}
}
LABEL_39:
FMOD_OS_CriticalSection_Leave(v1);
return v22;
}