//
// __emutls_get_address from 0x8e3cec to 0x8e3e1c (304 bytes)
//
// 8 xrefs:
// > sub_5AB7E4 @ 0x5ab7ec
// > sub_5AB7E4 @ 0x5ab7fc
// > sub_5AC564 @ 0x5ac628
// > sub_5AC564 @ 0x5ac6ba
// > sub_5AC564 @ 0x5ac746
// > sub_5AC564 @ 0x5ac7d6
// > sub_5AC564 @ 0x5ac868
// > ??> @ 0x3fdac
//
// 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
//
_DWORD *__fastcall _emutls_get_address(size_t *a1)
{
_DWORD *result; // r0
unsigned int v3; // r4
unsigned int *v4; // r0
unsigned int *v5; // r5
unsigned int *v6; // r0
pthread_key_t v7; // r0
unsigned int v8; // r8
int v9; // r7
unsigned int *v10; // r0
if ( !sub_8E3B4C() )
{
if ( !a1[2] )
a1[2] = (size_t)sub_8E3BB0(a1);
return (_DWORD *)a1[2];
}
v3 = a1[2];
__dmb(0xFu);
if ( !v3 )
{
sub_8E3CB0();
sub_8E3C58();
v3 = a1[2];
if ( !v3 )
{
v3 = ++dword_AD4DB4;
__dmb(0xFu);
a1[2] = v3;
}
sub_8E3C34();
}
v4 = (unsigned int *)j_pthread_getspecific(dword_AD4DAC);
v5 = v4;
if ( v4 )
{
v8 = *v4;
if ( v3 <= *v4 )
goto LABEL_19;
v9 = 2 * v8;
if ( v3 > 2 * v8 )
v9 = v3 + 32;
v10 = (unsigned int *)realloc(v4, 4 * (v9 + 1));
v5 = v10;
if ( v10 )
{
*v10 = v9;
memset(&v10[v8 + 1], 0, 4 * (v9 - v8));
v7 = dword_AD4DAC;
goto LABEL_18;
}
LABEL_12:
abort();
}
v6 = (unsigned int *)calloc(v3 + 33, 4u);
v5 = v6;
if ( !v6 )
goto LABEL_12;
*v6 = v3 + 32;
v7 = dword_AD4DAC;
LABEL_18:
j_pthread_setspecific(v7, v5);
LABEL_19:
result = (_DWORD *)v5[v3];
if ( !result )
{
result = sub_8E3BB0(a1);
v5[v3] = (unsigned int)result;
}
return result;
}