Function at 0x3986056f0
Capabilities:
Allocate thread local storage
Get thread local storage value
Set thread local storage value

Disassembly:
push r13
push r12
push rbp
push rdi
push rsi
push rbx
sub rsp, 0x28
mov rsi, qword [0x398697770]
mov r11d, dword [rsi]
mov rbx, rcx
test r11d, r11d
jne 0x398605728
mov rax, qword [rcx + 0x10]
test rax, rax
je 0x398605790
add rsp, 0x28
pop rbx
pop rsi
pop rdi
pop rbp
pop r12
pop r13
ret
mov r12, qword [rcx + 0x10]
test r12, r12
je 0x3986057a0
mov esi, dword [0x3986b6188]
mov r13, qword [sym.imp.KERNEL32.dll_GetLastError]
call r13
mov edi, eax
mov ecx, esi
call qword [sym.imp.KERNEL32.dll_TlsGetValue]
mov ecx, edi
mov rsi, rax
call qword [sym.imp.KERNEL32.dll_SetLastError]
test rsi, rsi
je 0x3986057f8
mov rbp, qword [rsi]
cmp rbp, r12
jb 0x398605840
sub r12, 1
mov rax, qword [rsi + r12*8 + 8]
test rax, rax
jne 0x398605717
mov rcx, rbx
call fcn.398605650
mov qword [rsi + r12*8 + 8], rax
jmp 0x398605717
call fcn.398605650
mov qword [rbx + 0x10], rax
jmp 0x398605717
mov r10d, dword [rsi]
test r10d, r10d
je 0x3986058d1
mov r9d, dword [0x39868e230]
test r9d, r9d
je 0x3986058f9
lea rcx, [0x3986b61a0]
call qword [sym.imp.KERNEL32.dll_EnterCriticalSection]
mov r12, qword [rbx + 0x10]
test r12, r12
je 0x3986058de
mov eax, dword [rsi]
test eax, eax
je 0x398605731
lea rcx, [0x3986b61a0]
call qword [sym.imp.KERNEL32.dll_LeaveCriticalSection]
jmp 0x398605731
lea rcx, [r12 + 0x21]
mov edx, 8
call sub.msvcrt.dll_calloc
lea rdi, [r12 + 0x20]
test rax, rax
mov rsi, rax
je 0x398605934
mov qword [rax], rdi
mov ecx, dword [0x3986b6188]
mov rdx, rsi
call qword [sym.imp.KERNEL32.dll_TlsSetValue]
test eax, eax
jne 0x39860576b
call r13
jmp 0x39860576b
lea rdi, [rbp + rbp]
mov rcx, rsi
lea rax, [r12 + 0x20]
cmp rdi, r12
cmovb rdi, rax
lea rdx, [rdi*8 + 8]
call sub.msvcrt.dll_realloc
test rax, rax
mov rsi, rax
je 0x398605934
mov qword [rax], rdi
lea rcx, [rax + rbp*8 + 8]
sub rdi, rbp
xor edx, edx
lea r8, [rdi*8]
call sub.msvcrt.dll_memset
jmp 0x39860581b
lea rcx, [0x3986b61a0]
call qword [sym.imp.KERNEL32.dll_InitializeCriticalSection]
call qword [sym.imp.KERNEL32.dll_TlsAlloc]
cmp eax, 0xffffffff
je 0x39860592c
lea rdx, [0x398605600]
mov ecx, eax
mov dword [0x3986b6188], eax
call fcn.39860eca0
test eax, eax
jne 0x398605934
mov dword [0x39868e230], 1
mov edx, dword [rsi]
test edx, edx
jne 0x3986057bc
mov r12, qword [rbx + 0x10]
test r12, r12
jne 0x398605731
mov rax, qword [0x3986b6180]
lea r12, [rax + 1]
mov qword [0x3986b6180], r12
mov qword [rbx + 0x10], r12
jmp 0x3986057d6
lock add dword [0x39868e234], 1
je 0x398605889
mov r8d, dword [0x39868e230]
lea rdi, [0x39868e230]
mov rbp, qword [sym.imp.KERNEL32.dll_Sleep]
test r8d, r8d
jne 0x3986058c7
nop dword [rax]
xor ecx, ecx
call rbp
mov ecx, dword [rdi]
test ecx, ecx
je 0x398605920
jmp 0x3986058c7
call qword [sym.imp.KERNEL32.dll_GetLastError]
jmp 0x3986058b9
call sub.msvcrt.dll_abort
nop
nop word [rax + rax]
cmp qword [rcx], rdx
jae 0x398605950
mov qword [rcx], rdx
mov qword [rcx + 0x18], 0
cmp qword [rcx + 8], r8
jae 0x39860595a
mov qword [rcx + 8], r8
test r9, r9
je 0x398605964
cmp qword [rcx], rdx
je 0x398605968
ret
mov qword [rcx + 0x18], r9
ret
lea rcx, [0x398690120]
jmp 0x3986056f0