//
// sub_D19E54 from 0xd19e54 to 0xd1a02c (472 bytes)
//
// 2 xrefs:
// > cocos2d::extension::CCThreadPool::CCThreadPool @ 0xaac1d0
// > cocos2d::extension::CCThreadPool::CCThreadPool @ 0xaac358
//
// 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_D19E54(pthread_t *newthread, void **a2)
{
void *v4; // x19
unsigned int *v5; // x21
unsigned int *v6; // x20
unsigned int *v7; // x0
unsigned int v8; // w1
unsigned int *v9; // x0
unsigned int v10; // w1
__int64 result; // x0
int v12; // w19
unsigned int *v13; // x0
unsigned int v14; // w1
_QWORD *exception; // x20
__int64 (__fastcall **v16)(); // x22
_QWORD *v17; // x1
__int64 v18; // x0
unsigned int *v19; // [xsp+58h] [xbp+58h] BYREF
if ( !&pthread_create )
{
exception = _cxa_allocate_exception(0x20u);
v16 = sub_D1998C();
sub_D153B8(&v19, "Enable multithreading to use std::thread");
sub_D199C0(exception, 1, (__int64)v16, &v19);
if ( v19 - 6 != (unsigned int *)&qword_124B6B0 )
sub_4DEEAC(v19 - 6);
_cxa_throw(exception, (struct type_info *)&`typeinfo for'std::system_error, (void (*)(void *))sub_D19938);
}
v4 = *a2;
v5 = (unsigned int *)a2[1];
v6 = *((unsigned int **)*a2 + 2);
*((_QWORD *)*a2 + 1) = *a2;
if ( v5 != v6 )
{
if ( v5 )
{
v7 = v5 + 2;
do
v8 = __ldaxr(v7);
while ( __stlxr(v8 + 1, v7) );
v6 = *((unsigned int **)v4 + 2);
}
v9 = v6 + 2;
if ( v6 )
{
do
v10 = __ldaxr(v9);
while ( __stlxr(v10 - 1, v9) );
if ( v10 == 1 )
{
(*(void (__fastcall **)(unsigned int *))(*(_QWORD *)v6 + 16LL))(v6);
v13 = v6 + 3;
do
v14 = __ldaxr(v13);
while ( __stlxr(v14 - 1, v13) );
if ( v14 == 1 )
(*(void (__fastcall **)(unsigned int *))(*(_QWORD *)v6 + 24LL))(v6);
}
}
*((_QWORD *)v4 + 2) = v5;
}
result = pthread_create(newthread, nullptr, (void *(*)(void *))sub_D19D4C, *a2);
v12 = result;
if ( (_DWORD)result )
{
v17 = *a2;
v18 = *((_QWORD *)*a2 + 2);
v17[1] = 0;
v17[2] = 0;
if ( v18 )
sub_AABD1C(v18);
sub_D1410C(v12);
}
return result;
}