//
// sub_100438CA0 from 0x100438ca0 to 0x100438f99 (761 bytes)
//
// 1 xrefs:
// > sub_100438BD0 @ 0x100438c1c
//
// 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 sub_100438CA0(std::__thread_struct **a1)
{
std::__thread_specific_ptr *v1; // rax
std::__thread_struct *v2; // rsi
std::__thread_struct *v3; // rbx
__int64 v4; // rax
char p; // al
unsigned __int64 v6; // r14
_BYTE *v7; // rdi
__int64 v8; // rax
__int64 v9; // rcx
_QWORD *v10; // rax
std::__thread_struct_imp *v11; // rcx
unsigned __int64 v12; // rsi
_QWORD *v13; // rdi
__int64 v14; // rax
unsigned __int64 v15; // rcx
char v16; // r14
_QWORD *v17; // rdi
std::__thread_struct *v18; // r14
std::unique_lock __lk; // [rsp+10h] [rbp-70h] BYREF
_BYTE v22[32]; // [rsp+20h] [rbp-60h] BYREF
_QWORD v23[2]; // [rsp+40h] [rbp-40h] BYREF
v1 = std::__thread_local_data();
v2 = *a1;
*a1 = nullptr;
pthread_setspecific(v1->__key_, v2);
v3 = a1[1];
do
{
v23[0] = 0;
__lk.__m_ = (std::unique_lock::mutex_type *)&v3[9];
__lk.__owns_ = 1;
std::mutex::lock((std::mutex *)&v3[9]);
p = (char)v3[23].__p_;
if ( !p )
{
do
{
if ( v3[8].__p_ )
break;
std::condition_variable::wait((std::condition_variable *)&v3[17], &__lk);
p = (char)v3[23].__p_;
}
while ( p != 1 );
}
if ( !p || v3[8].__p_ )
{
v6 = *((_QWORD *)v3[4].__p_ + (unsigned __int64)v3[7].__p_ / 0x55) + 48 * ((unsigned __int64)v3[7].__p_ % 0x55);
v7 = (_BYTE *)v23[0];
v23[0] = 0;
if ( v7 == v22 )
{
v8 = 32;
}
else
{
v8 = 40;
if ( !v7 )
{
v9 = *(_QWORD *)(v6 + 32);
v10 = v23;
if ( !v9 )
goto LABEL_19;
LABEL_17:
v10 = (_QWORD *)(v6 + 32);
if ( v9 == v6 )
{
v23[0] = v22;
(*(void (__fastcall **)(_QWORD))(*(_QWORD *)*v10 + 24LL))(*v10);
LABEL_21:
v11 = v3[7].__p_;
v12 = *((_QWORD *)v3[4].__p_ + (unsigned __int64)v11 / 0x55) + 48 * ((unsigned __int64)v11 % 0x55);
v13 = *(_QWORD **)(v12 + 32);
if ( v13 == (_QWORD *)v12 )
{
v14 = 32;
}
else
{
v14 = 40;
if ( !v13 )
{
LABEL_26:
--v3[8].__p_;
v15 = (unsigned __int64)v11 + 1;
v3[7].__p_ = (std::__thread_struct_imp *)v15;
v16 = 1;
if ( v15 >= 0xAA )
{
operator delete(*(void **)v3[4].__p_);
v3[4].__p_ = (std::__thread_struct_imp *)((char *)v3[4].__p_ + 8);
v3[7].__p_ = (std::__thread_struct_imp *)((char *)v3[7].__p_ - 85);
if ( !__lk.__owns_ )
goto LABEL_28;
}
else if ( !__lk.__owns_ )
{
goto LABEL_28;
}
goto LABEL_34;
}
}
(*(void (__fastcall **)(_QWORD *))(*v13 + v14))(v13);
v11 = v3[7].__p_;
goto LABEL_26;
}
v23[0] = v9;
LABEL_19:
*v10 = 0;
goto LABEL_21;
}
}
(*(void (__fastcall **)(_BYTE *))(*(_QWORD *)v7 + v8))(v7);
v9 = *(_QWORD *)(v6 + 32);
v10 = v23;
if ( !v9 )
goto LABEL_19;
goto LABEL_17;
}
v16 = 0;
if ( !__lk.__owns_ )
{
LABEL_28:
if ( !v16 )
goto LABEL_29;
goto LABEL_35;
}
LABEL_34:
std::mutex::unlock(__lk.__m_);
if ( !v16 )
{
LABEL_29:
v17 = (_QWORD *)v23[0];
if ( (_BYTE *)v23[0] == v22 )
goto LABEL_2;
goto LABEL_37;
}
LABEL_35:
_InterlockedIncrement64((volatile signed __int64 *)&v3[24]);
if ( !v23[0] )
sub_100439080(0);
(*(void (__fastcall **)(_QWORD))(*(_QWORD *)v23[0] + 48LL))(v23[0]);
_InterlockedDecrement64((volatile signed __int64 *)&v3[24]);
v17 = (_QWORD *)v23[0];
if ( (_BYTE *)v23[0] == v22 )
{
LABEL_2:
v4 = 32;
LABEL_3:
(*(void (__fastcall **)(_QWORD *))(*v17 + v4))(v17);
continue;
}
LABEL_37:
v4 = 40;
if ( v17 )
goto LABEL_3;
}
while ( v16 );
v18 = *a1;
*a1 = nullptr;
if ( v18 )
{
std::__thread_struct::~__thread_struct(v18);
operator delete(v18);
}
operator delete(a1);
return nullptr;
}