//
// __emutls_get_address from 0xe8d5c4 to 0xe8d714 (336 bytes)
//
// 8 xrefs:
// > sub_AAAF54 @ 0xaaaf6c
// > sub_AAAF54 @ 0xaaaf94
// > sub_AAC850 @ 0xaaca10
// > sub_AAC850 @ 0xaacaf0
// > sub_AAC850 @ 0xaacb90
// > sub_AAC850 @ 0xaacc58
// > sub_AAC850 @ 0xaaccdc
// > ??> @ 0xa5a68
//
// 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
//
_QWORD *__fastcall _emutls_get_address(size_t *a1)
{
_QWORD *result; // x0
unsigned __int64 v3; // x19
unsigned __int64 *v4; // x0
unsigned __int64 *v5; // x20
unsigned __int64 *v6; // x0
pthread_key_t v7; // w0
unsigned __int64 v8; // x23
__int64 v9; // x21
unsigned __int64 *v10; // x0
__int64 v11; // x19
if ( !&pthread_create )
{
if ( !a1[2] )
a1[2] = (size_t)sub_E8D52C(a1);
return (_QWORD *)a1[2];
}
v3 = atomic_load(a1 + 2);
if ( !v3 )
{
pthread_once(dword_126007C, (void (*)(void))sub_E8D4AC);
pthread_mutex_lock((pthread_mutex_t *)&dword_126007C[1]);
v3 = a1[2];
if ( !v3 )
{
v3 = qword_12600A8 + 1;
qword_12600A8 = v3;
atomic_store(v3, a1 + 2);
}
pthread_mutex_unlock((pthread_mutex_t *)&dword_126007C[1]);
}
v4 = (unsigned __int64 *)pthread_getspecific(dword_1260078[0]);
v5 = v4;
if ( v4 )
{
v8 = *v4;
if ( v3 <= *v4 )
goto LABEL_19;
v9 = 2 * v8;
if ( v3 > 2 * v8 )
v9 = v3 + 32;
v10 = (unsigned __int64 *)realloc(v4, 8 * (v9 + 1));
v5 = v10;
if ( !v10 )
LABEL_11:
abort();
*v10 = v9;
memset(&v10[v8 + 1], 0, 8 * (v9 - v8));
v7 = dword_1260078[0];
}
else
{
v6 = (unsigned __int64 *)calloc(v3 + 33, 8u);
v5 = v6;
if ( !v6 )
goto LABEL_11;
*v6 = v3 + 32;
v7 = dword_1260078[0];
}
pthread_setspecific(v7, v5);
LABEL_19:
v11 = v3;
result = (_QWORD *)v5[v11];
if ( !result )
{
result = sub_E8D52C(a1);
v5[v11] = (unsigned __int64)result;
}
return result;
}