//
// __emutls_get_address from 0xaf77d0 to 0xaf7900 (304 bytes)
//
// 14 xrefs:
// > sub_7B16D0 @ 0x7b16d8
// > sub_7B16D0 @ 0x7b16e8
// > sub_7B26B0 @ 0x7b2794
// > sub_7B26B0 @ 0x7b2830
// > sub_7B26B0 @ 0x7b28c0
// > sub_7B26B0 @ 0x7b2954
// > sub_7B26B0 @ 0x7b29f2
// > __cxa_thread_atexit @ 0x980c96
// > __cxa_thread_atexit @ 0x980cae
// > __cxa_thread_atexit @ 0x980cc8
// > sub_980D4C @ 0x980d56
// > sub_980D4C @ 0x980d68
// > sub_980D4C @ 0x980d86
// > ??> @ 0x522ac
//
// This function is hookable on this platform (idp: arm, 32 bit: True, 64 bit: False!
//
// 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 12:11:04 +0000
//
_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_AF7630() )
{
if ( !a1[2] )
a1[2] = (size_t)sub_AF7694(a1);
return (_DWORD *)a1[2];
}
v3 = a1[2];
__dmb(0xFu);
if ( !v3 )
{
sub_AF7794();
sub_AF773C();
v3 = a1[2];
if ( !v3 )
{
v3 = ++dword_D3603C;
__dmb(0xFu);
a1[2] = v3;
}
sub_AF7718();
}
v4 = (unsigned int *)j_pthread_getspecific(dword_D36034);
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_D36034;
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_D36034;
LABEL_18:
j_pthread_setspecific(v7, v5);
LABEL_19:
result = (_DWORD *)v5[v3];
if ( !result )
{
result = sub_AF7694(a1);
v5[v3] = (unsigned int)result;
}
return result;
}