//
// FMODAudioEngine::unregisterChannel from 0x1003e4ee0 to 0x1003e50fd (541 bytes)
//
// 1 xrefs:
// > FMODAudioEngine::channelStopped @ 0x1003e55aa
//
// 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::unregisterChannel(FMODAudioEngine *a1, int a2)
{
__m128 v2; // xmm0
int v3; // esi
unsigned __int64 value; // r9
std::unordered_map *p_m_channelIDToEffectID; // r14
unsigned __int64 v6; // r11
unsigned __int64 v7; // r8
std::__hash_node_base, void *> *> *v8; // rax
std::__hash_node_base, void *> *>::__next_pointer next; // r10
unsigned __int64 v10; // r9
std::__hash_node_base, void *> *>::__next_pointer v11; // rax
unsigned __int64 v12; // rax
int *v13; // [rsp+8h] [rbp-28h] BYREF
int v14[7]; // [rsp+14h] [rbp-1Ch] BYREF
v14[0] = a2;
sub_1000569A0(&a1->m_channelIDToChannel.__table_.__bucket_list_.__ptr_.__value_, v14);
sub_1000569A0(&a1->m_stoppedChannels.__table_.__bucket_list_.__ptr_.__value_, v14);
sub_1003EE010(&a1->m_audioState.m_soundStateForChannels, v14);
v3 = v14[0];
value = a1->m_channelIDToEffectID.__table_.__bucket_list_.__ptr_.__value_.__data_.__value_;
if ( !value )
goto LABEL_29;
p_m_channelIDToEffectID = &a1->m_channelIDToEffectID;
v6 = (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 ( v6 <= 1 )
{
v7 = v14[0] & (value - 1);
v8 = p_m_channelIDToEffectID->__table_.__bucket_list_.__ptr_.__value_[v7];
if ( !v8 )
goto LABEL_29;
goto LABEL_9;
}
v7 = v14[0];
if ( value > v14[0] )
{
LABEL_8:
v8 = p_m_channelIDToEffectID->__table_.__bucket_list_.__ptr_.__value_[v7];
if ( !v8 )
goto LABEL_29;
goto LABEL_9;
}
if ( (value | v14[0]) >> 32 )
{
v7 = v14[0] % value;
goto LABEL_8;
}
v7 = v14[0] % (unsigned int)value;
v8 = p_m_channelIDToEffectID->__table_.__bucket_list_.__ptr_.__value_[v7];
if ( !v8 )
goto LABEL_29;
LABEL_9:
next = v8->__next_;
if ( v8->__next_ )
{
if ( (unsigned int)v6 < 2 )
{
v10 = value - 1;
while ( 1 )
{
v11 = next[1].__next_;
if ( v11 == (std::__hash_node_base, void *> *>::__next_pointer)v14[0] )
{
if ( LODWORD(next[2].__next_) == v14[0] )
goto LABEL_27;
}
else if ( (v10 & (unsigned __int64)v11) != v7 )
{
goto LABEL_29;
}
next = next->__next_;
if ( !next )
goto LABEL_29;
}
}
do
{
v12 = (unsigned __int64)next[1].__next_;
if ( v12 == v14[0] )
{
if ( LODWORD(next[2].__next_) == v14[0] )
{
LABEL_27:
v13 = v14;
LODWORD(v13) = *((_DWORD *)sub_100055BA0(
(float *)&a1->m_channelIDToEffectID,
v14,
v2,
(__int64)&unk_10081B0A2,
&v13)
+ 5);
sub_1000569A0(p_m_channelIDToEffectID, v14);
sub_1000569A0(&a1->m_effectIDToChannelID.__table_.__bucket_list_.__ptr_.__value_, (int *)&v13);
v3 = v14[0];
break;
}
}
else
{
if ( v12 < value )
goto LABEL_23;
if ( (value | v12) >> 32 )
{
v12 %= value;
LABEL_23:
if ( v12 != v7 )
break;
goto LABEL_18;
}
if ( (unsigned int)v12 % (unsigned int)value != v7 )
break;
}
LABEL_18:
next = next->__next_;
}
while ( next );
}
LABEL_29:
FMODAudioEngine::channelUnlinkSound(a1, v3);
}