//
// sub_D1D888 from 0xd1d888 to 0xd1dbd0 (840 bytes)
//
// 2 xrefs:
// > sub_D1CDF0 @ 0xd1ce28
// > sub_D1CDF0 @ 0xd1ce34
//
// This function is hookable on this platform (idp: arm, 32 bit: False, 64 bit: True!
//
// Using BromaIDA 8.3.0 @ https://github.com/Stazzical/BromaIDA
// Using bindings at commit 1c6ec395 at Thu Nov 26 21:29:22 2026 from https://github.com/geode-sdk/bindings
// Generated at Fri, 27 Nov 2026 13:07:10 +0000
//
__int64 __fastcall sub_D1D888(std::__thread_struct **a1)
{
pthread_key_t *v2; // x0
std::__thread_struct *v3; // x22
pthread_key_t *v4; // x20
std::__thread_struct *v5; // x19
std::__thread_struct *v6; // x1
std::__thread_struct *v7; // x19
unsigned __int64 v8; // x19
__int64 v9; // x0
std::__thread_struct *v10; // x19
unsigned __int64 v11; // x0
unsigned __int64 *v12; // x0
unsigned __int64 v13; // x1
unsigned __int64 *v14; // x0
unsigned __int64 v15; // x1
std::__thread_struct *v16; // x19
_QWORD *exception; // x0
std::mutex *v19; // [xsp+50h] [xbp+50h]
_QWORD v20[4]; // [xsp+60h] [xbp+60h] BYREF
_QWORD *v21; // [xsp+80h] [xbp+80h]
v2 = (pthread_key_t *)std::__thread_local_data();
v3 = *a1;
v4 = v2;
*a1 = nullptr;
v5 = (std::__thread_struct *)pthread_getspecific(*v2);
pthread_setspecific(*v4, v3);
if ( v5 )
{
std::__thread_struct::~__thread_struct(v5);
operator delete(v5);
}
while ( 1 )
{
v6 = a1[1];
v21 = nullptr;
v19 = (std::__thread_struct *)((char *)v6 + 72);
std::mutex::lock((std::__thread_struct *)((char *)v6 + 72));
v7 = a1[1];
if ( *((_BYTE *)v7 + 160) )
goto LABEL_32;
if ( !*((_QWORD *)v7 + 8) )
{
do
std::condition_variable::wait((pthread_cond_t *)((char *)v7 + 112));
while ( !*((_BYTE *)v7 + 160) && !*((_QWORD *)v7 + 8) );
v7 = a1[1];
if ( *((_BYTE *)v7 + 160) )
{
LABEL_32:
if ( !*((_QWORD *)v7 + 8) )
break;
}
}
v8 = *(_QWORD *)(*((_QWORD *)v7 + 4) + 8 * (*((_QWORD *)v7 + 7) / 0x55uLL)) + 48 * (*((_QWORD *)v7 + 7) % 0x55uLL);
if ( v21 == v20 )
{
(*(void (__fastcall **)(_QWORD *))(v20[0] + 32LL))(v20);
}
else if ( v21 )
{
(*(void (__fastcall **)(_QWORD *))(*v21 + 40LL))(v21);
}
v21 = nullptr;
v9 = *(_QWORD *)(v8 + 32);
if ( v9 )
{
if ( v9 == v8 )
{
v21 = v20;
(*(void (__fastcall **)(_QWORD, _QWORD *))(**(_QWORD **)(v8 + 32) + 24LL))(*(_QWORD *)(v8 + 32), v20);
}
else
{
v21 = *(_QWORD **)(v8 + 32);
*(_QWORD *)(v8 + 32) = 0;
}
}
v10 = a1[1];
std::function::~function(*(_QWORD *)(*((_QWORD *)v10 + 4) + 8 * (*((_QWORD *)v10 + 7) / 0x55uLL)) + 48 * (*((_QWORD *)v10 + 7) % 0x55uLL));
--*((_QWORD *)v10 + 8);
v11 = *((_QWORD *)v10 + 7) + 1LL;
*((_QWORD *)v10 + 7) = v11;
if ( v11 > 0xA9 )
{
operator delete(**((void ***)v10 + 4));
*((_QWORD *)v10 + 4) += 8LL;
*((_QWORD *)v10 + 7) -= 85LL;
}
std::mutex::unlock(v19);
v12 = (unsigned __int64 *)((char *)a1[1] + 168);
do
v13 = __ldxr(v12);
while ( __stxr(v13 + 1, v12) );
if ( !v21 )
{
exception = _cxa_allocate_exception(8u);
*exception = off_15106A0;
_cxa_throw(
exception,
(struct type_info *)&`typeinfo for'std::bad_function_call,
(void (*)(void *))std::bad_function_call::~bad_function_call);
}
(*(void (__fastcall **)(_QWORD *))(*v21 + 48LL))(v21);
v14 = (unsigned __int64 *)((char *)a1[1] + 168);
do
v15 = __ldxr(v14);
while ( __stxr(v15 - 1, v14) );
std::function::~function((__int64)v20);
}
std::mutex::unlock(v19);
std::function::~function((__int64)v20);
v16 = *a1;
*a1 = nullptr;
if ( v16 )
{
std::__thread_struct::~__thread_struct(v16);
operator delete(v16);
}
operator delete(a1);
return 0;
}