//
// FMODAudioEngine::channelUnlinkSound from 0x1003e5100 to 0x1003e533e (574 bytes)
//
// 1 xrefs:
// > FMODAudioEngine::unregisterChannel @ 0x1003e50ed
//
// 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
//
void __fastcall FMODAudioEngine::channelUnlinkSound(FMODAudioEngine *a1, int a2)
{
double v2; // xmm0_8
unsigned __int64 value; // r9
std::unordered_map *p_m_channelIDToSoundPath; // rbx
unsigned __int64 v5; // r11
unsigned __int64 v6; // r8
std::__hash_node_base, void *> *> *v7; // rax
std::__hash_node_base, void *> *>::__next_pointer next; // r10
unsigned __int64 v9; // r9
std::__hash_node_base, void *> *>::__next_pointer v10; // rax
unsigned __int64 v11; // rax
char *v13; // rax
char *v14; // rax
std::unordered_map *p_m_fmodSounds; // rdi
__int64 v16; // rax
__int128 v17; // [rsp+0h] [rbp-40h] BYREF
void *__p; // [rsp+10h] [rbp-30h]
int *v19; // [rsp+18h] [rbp-28h] BYREF
int v20; // [rsp+20h] [rbp-20h] BYREF
char v21[25]; // [rsp+27h] [rbp-19h] BYREF
v20 = a2;
value = a1->m_channelIDToSoundPath.__table_.__bucket_list_.__ptr_.__value_.__data_.__value_;
if ( !value )
return;
p_m_channelIDToSoundPath = &a1->m_channelIDToSoundPath;
v5 = (0x101010101010101LL
* ((((value - ((value >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((value - ((value >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)
+ ((((value - ((value >> 1) & 0x5555555555555555LL)) & 0x3333333333333333LL)
+ (((value - ((value >> 1) & 0x5555555555555555LL)) >> 2) & 0x3333333333333333LL)) >> 4))
& 0xF0F0F0F0F0F0F0FLL)) >> 56;
if ( v5 > 1 )
{
v6 = a2;
if ( value <= a2 )
{
if ( !((value | a2) >> 32) )
{
v6 = a2 % (unsigned int)value;
v7 = p_m_channelIDToSoundPath->__table_.__bucket_list_.__ptr_.__value_[v6];
if ( !v7 )
return;
goto LABEL_9;
}
v6 = a2 % value;
}
v7 = p_m_channelIDToSoundPath->__table_.__bucket_list_.__ptr_.__value_[v6];
if ( !v7 )
return;
}
else
{
v6 = a2 & (value - 1);
v7 = p_m_channelIDToSoundPath->__table_.__bucket_list_.__ptr_.__value_[v6];
if ( !v7 )
return;
}
LABEL_9:
next = v7->__next_;
if ( !v7->__next_ )
return;
if ( (unsigned int)v5 < 2 )
{
v9 = value - 1;
while ( 1 )
{
v10 = next[1].__next_;
if ( v10 == (std::__hash_node_base, void *> *>::__next_pointer)a2 )
{
if ( LODWORD(next[2].__next_) == a2 )
goto LABEL_27;
}
else if ( (v9 & (unsigned __int64)v10) != v6 )
{
return;
}
next = next->__next_;
if ( !next )
return;
}
}
while ( 1 )
{
v11 = (unsigned __int64)next[1].__next_;
if ( v11 == a2 )
break;
if ( v11 < value )
goto LABEL_23;
if ( (value | v11) >> 32 )
{
v11 %= value;
LABEL_23:
if ( v11 != v6 )
return;
goto LABEL_18;
}
if ( (unsigned int)v11 % (unsigned int)value != v6 )
return;
LABEL_18:
next = next->__next_;
if ( !next )
return;
}
if ( LODWORD(next[2].__next_) != a2 )
goto LABEL_18;
LABEL_27:
v19 = &v20;
v13 = sub_100172F30((float *)&a1->m_channelIDToSoundPath, &v20, (__int64)&unk_10081B0A2, &v19);
if ( (v13[24] & 1) != 0 )
{
sub_100006B70(&v17, *((const void **)v13 + 5), *((_QWORD *)v13 + 4), v2);
}
else
{
v14 = v13 + 24;
__p = *((void **)v14 + 2);
v17 = *(_OWORD *)v14;
}
p_m_fmodSounds = &a1->m_fmodSounds;
if ( sub_1003EC6B0(&a1->m_fmodSounds) )
{
v19 = (int *)&v17;
v16 = sub_1003EC940(p_m_fmodSounds, &v17, &unk_10081B0A2, &v19, v21);
--*(_DWORD *)(v16 + 76);
sub_1003EE010(p_m_channelIDToSoundPath, &v20);
}
if ( (v17 & 1) != 0 )
operator delete(__p);
}