//
// sub_180112D30 from 0x180112d30 to 0x180112f03 (467 bytes)
//
// 4 xrefs:
// > sub_1801124D0 @ 0x1801124f9
// > sub_180112AC0 @ 0x180112b32
// > sub_180112AC0 @ 0x180112c8a
// > ??> @ 0x180201c88
//
// 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_180112D30(__int64 *a1, char a2, __int64 a3)
{
__int64 v6; // rbp
__int64 result; // rax
int v8; // edx
int v9; // r8d
int v10; // edx
int v11; // ecx
unsigned int v12; // ecx
__int64 v13; // rdx
void *v14; // rax
struct _RTL_CRITICAL_SECTION *v15; // r14
int v16; // edi
unsigned int v17; // esi
int v18; // ecx
__int64 v19; // [rsp+30h] [rbp-28h]
if ( *((_BYTE *)a1 + 24) )
return 0;
v6 = 0;
while ( 1 )
{
result = FMOD_OS_CriticalSection_Enter((struct _RTL_CRITICAL_SECTION *)a1[4]);
if ( (_DWORD)result )
return result;
v8 = *((_DWORD *)a1 + 2);
v9 = a1[2] & (v8 - 1);
v10 = v8 - v9;
v11 = *((_DWORD *)a1 + 3) - *((_DWORD *)a1 + 4);
if ( v11 )
{
*(_QWORD *)(a3 + 8) = *a1 + v9;
if ( v10 >= v11 )
{
*(_DWORD *)(a3 + 24) = v11;
v18 = 0;
}
else
{
*(_DWORD *)(a3 + 24) = v10;
v18 = v11 - v10;
v6 = *a1;
}
*(_QWORD *)(a3 + 16) = v6;
*(_DWORD *)(a3 + 28) = v18;
*(_QWORD *)a3 = a1[4];
return 0;
}
if ( *((_DWORD *)a1 + 5) )
{
sub_1800B6AA0(*((_QWORD *)off_1801AED20 + 52), (_DWORD *)*a1);
LOBYTE(v19) = 1;
v12 = ((((unsigned int)(*((_DWORD *)a1 + 5) - 1) >> 1) | (*((_DWORD *)a1 + 5) - 1)) >> 2)
| ((unsigned int)(*((_DWORD *)a1 + 5) - 1) >> 1)
| (*((_DWORD *)a1 + 5) - 1);
v13 = ((((v12 >> 4) | v12) >> 8) | (v12 >> 4) | v12 | (((((v12 >> 4) | v12) >> 8) | (v12 >> 4) | v12) >> 16)) + 1;
*((_DWORD *)a1 + 2) = v13;
v14 = sub_1800B6530(
*((_QWORD *)off_1801AED20 + 52),
v13,
"C:\\buildagent1\\work\\570ad728b1678096\\core_api\\src\\fmod_profile_client.cpp",
247,
0,
0,
v19);
*a1 = (__int64)v14;
if ( !v14 )
return 38;
v15 = (struct _RTL_CRITICAL_SECTION *)a1[4];
*(__int64 *)((char *)a1 + 12) = 0;
*((_DWORD *)a1 + 5) = 0;
FMOD_OS_CriticalSection_Enter(v15);
if ( *((int *)a1 + 15) > 0 )
{
v16 = 0;
while ( 1 )
{
v17 = sub_1800C14F0((void *)a1[6]);
if ( v17 )
break;
if ( ++v16 >= *((_DWORD *)a1 + 15) )
{
*((_DWORD *)a1 + 15) = 0;
goto LABEL_12;
}
}
FMOD_OS_CriticalSection_Leave(v15);
return v17;
}
LABEL_12:
FMOD_OS_CriticalSection_Leave(v15);
}
if ( a2 )
++*((_DWORD *)a1 + 14);
result = FMOD_OS_CriticalSection_Leave((struct _RTL_CRITICAL_SECTION *)a1[4]);
if ( (_DWORD)result )
return result;
if ( !a2 )
return 45;
result = sub_1800C1520((void *)a1[5]);
if ( (_DWORD)result )
return result;
if ( *((_BYTE *)a1 + 24) )
return 0;
}
}