Function at 0x409ec0
Capabilities:
Get thread local storage value
Set thread local storage value

Disassembly:
sub esp, 0xc
push ebx
push ebp
push esi
mov ebx, ecx
mov dword [esp + 0x10], edx
push edi
push dword [ebx + 0xb8]
call dword [sym.imp.KERNEL32.dll_TlsGetValue]
test eax, eax
je 0x409eea
mov eax, 0xfffffffa
pop edi
pop esi
pop ebp
pop ebx
add esp, 0xc
ret
lea ebp, [ebx + 0xd8]
push ebp
call dword [sym.imp.KERNEL32.dll_EnterCriticalSection]
test byte [ebx + 0xf0], 1
je 0x409fde
push str.event_sources_modified__reallocating_event_data
push str.handle_events
push 4
push ebx
call fcn.00407e20
add esp, 0x10
mov ecx, ebx
call fcn.004091d0
cmp dword [ebx + 0x108], 0
je 0x409f3a
push str.program_assertion_failed___event_data_already_allocated
push str.usbi_alloc_event_data
push 2
jmp 0x40a0a3
mov eax, dword [ebx + 0xfc]
lea esi, [ebx + 0xf8]
mov dword [ebx + 0x10c], 0
lea edx, [eax - 8]
cmp eax, esi
je 0x40a097
xor ecx, ecx
nop dword [eax]
inc ecx
mov dword [ebx + 0x10c], ecx
mov eax, dword [edx + 0xc]
lea edx, [eax - 8]
cmp eax, esi
jne 0x409f60
mov eax, ecx
cmp ecx, 1
je 0x409f81
cmp eax, 2
jne 0x40a097
push 4
push ecx
call fcn.00420a64
mov edi, eax
add esp, 8
test edi, edi
jne 0x409fa6
push ebp
lea esi, [eax - 0xb]
call dword [sym.imp.KERNEL32.dll_LeaveCriticalSection]
mov eax, esi
pop edi
pop esi
pop ebp
pop ebx
add esp, 0xc
ret
mov eax, dword [ebx + 0xfc]
lea edx, [eax - 8]
cmp eax, esi
je 0x409fc7
mov ecx, edi
mov eax, dword [edx]
lea ecx, [ecx + 4]
mov dword [ecx - 4], eax
mov eax, dword [edx + 0xc]
lea edx, [eax - 8]
cmp eax, esi
jne 0x409fb5
and dword [ebx + 0xf0], 0xfffffffe
mov dword [ebx + 0x108], edi
jne 0x409fde
lea ecx, [ebx + 0xc]
call fcn.0040aa70
push ebp
call dword [sym.imp.KERNEL32.dll_LeaveCriticalSection]
mov ecx, dword [esp + 0x14]
mov esi, 0x3e8
push ebx
push dword [ebx + 0xb8]
mov eax, dword [ecx + 4]
cdq
idiv esi
imul ecx, dword [ecx], 0x3e8
add eax, ecx
test edx, edx
lea edi, [eax + 1]
cmove edi, eax
xor ebp, ebp
call dword [sym.imp.KERNEL32.dll_TlsSetValue]
mov esi, dword [ebx + 0x10c]
mov eax, dword [ebx + 0x108]
push edi
push esi
push str.WaitForMultipleObjects___for__lu_HANDLEs_with_timeout_in__dms
push str.usbi_wait_for_events
push 4
push ebx
mov dword [esp + 0x2c], eax
call fcn.00407e20
add esp, 0x18
push edi
mov edi, dword [esp + 0x18]
push ebp
push edi
push esi
call dword [sym.imp.KERNEL32.dll_WaitForMultipleObjects]
mov esi, eax
push esi
push str.WaitForMultipleObjects___returned__lu
push str.usbi_wait_for_events
push 4
push ebx
call fcn.00407e20
add esp, 0x14
cmp esi, 0x102
jne 0x40a0c2
xor ecx, ecx
cmp dword [ebx + 0x10], ecx
jne 0x40a136
mov eax, dword [sym.imp.KERNEL32.dll_EnterCriticalSection]
lea esi, [ebx + 0x84]
push esi
call eax
mov ecx, ebx
call fcn.00409b30
mov eax, dword [sym.imp.KERNEL32.dll_LeaveCriticalSection]
push esi
call eax
xor edi, edi
jmp 0x40a175
push str.program_assertion_failed___expected_exactly_1_or_2_HANDLEs
push str.usbi_alloc_event_data
push 1
push ebx
call fcn.00407e20
add esp, 0x10
mov esi, 0xffffff9d
push ebp
call dword [sym.imp.KERNEL32.dll_LeaveCriticalSection]
mov eax, esi
pop edi
pop esi
pop ebp
pop ebx
add esp, 0xc
ret
cmp esi, 0xffffffff
jne 0x40a0eb
xor ecx, ecx
call fcn.0040ac00
push eax
push str.WaitForMultipleObjects___failed:__s
push str.usbi_wait_for_events
push 1
push ebx
call fcn.00407e20
add esp, 0x14
or edi, esi
jmp 0x40a175
xor eax, eax
test esi, esi
sete al
mov ecx, eax
mov dword [esp + 0x14], eax
mov dword [esp + 0x18], ecx
cmp dword [ebx + 0x10], ebp
je 0x40a134
cmp esi, 1
je 0x40a127
push 0
push dword [edi + 4]
call dword [sym.imp.KERNEL32.dll_WaitForSingleObject]
test eax, eax
je 0x40a123
mov eax, dword [esp + 0x18]
mov ecx, eax
mov dword [esp + 0x14], eax
mov ebp, eax
jmp 0x40a136
mov eax, dword [esp + 0x14]
or eax, 2
mov dword [esp + 0x14], eax
mov ecx, eax
mov ebp, eax
jmp 0x40a136
mov ebp, ecx
xor edi, edi
test cl, 1
je 0x40a14a
mov ecx, ebx
call fcn.00409c10
mov edi, eax
test edi, edi
jne 0x40a175
cmp ebp, 2
jb 0x40a175
mov eax, dword [sym.imp.KERNEL32.dll_EnterCriticalSection]
lea esi, [ebx + 0x84]
push esi
call eax
mov ecx, ebx
call fcn.00409b30
mov ecx, ebx
call fcn.004093c0
mov edi, eax
mov eax, dword [sym.imp.KERNEL32.dll_LeaveCriticalSection]
push esi
call eax
push 0
push dword [ebx + 0xb8]
call dword [sym.imp.KERNEL32.dll_TlsSetValue]
mov eax, edi
pop edi
pop esi
pop ebp
pop ebx
add esp, 0xc
ret