#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef int /*<<< orphan*/ pthread_t;

/* Variables and functions */
int /*<<< orphan*/ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ (*)(int /*<<< orphan*/ *),
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_join(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ tls_ptr(int /*<<< orphan*/ *);
int main(void) {
  pthread_t threads[2];
  tls_ptr(NULL);
  pthread_create(&threads[0], NULL, tls_ptr, NULL);
  pthread_create(&threads[1], NULL, tls_ptr, NULL);
  pthread_join(threads[0], NULL);
  pthread_join(threads[1], NULL);
  tls_ptr(NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <tls_ptr@plt>
lea    -0xc(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    0x2e99(%rip),%rdx
mov    %rcx,%rsi
call   1030 <pthread_create@plt>
lea    -0xc(%rbp),%rdi
add    $0x4,%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    0x2e7e(%rip),%rdx
mov    %rcx,%rsi
call   1030 <pthread_create@plt>
mov    -0xc(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_join@plt>
mov    -0x8(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <pthread_join@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <tls_ptr@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
call   1050 <tls_ptr@plt>
mov    0x2ead(%rip),%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1030 <pthread_create@plt>
lea    0xc(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
xor    %ecx,%ecx
call   1030 <pthread_create@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
mov    0xc(%rsp),%edi
xor    %esi,%esi
call   1040 <pthread_join@plt>
xor    %edi,%edi
call   1050 <tls_ptr@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
store i32 0, i32* %1
%3 = call i32 @tls_ptr(i32* null)
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pthread_create(i32* %4, i32* null, i32 (i32*)* @tls_ptr, i32* null)
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%7 = call i32 @pthread_create(i32* %6, i32* null, i32 (i32*)* @tls_ptr, i32* null)
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%9 = load i32, i32* %8
%10 = call i32 @pthread_join(i32 %9, i32* null)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @pthread_join(i32 %12, i32* null)
%14 = call i32 @tls_ptr(i32* null)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = tail call i32 @tls_ptr(i32* null)
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%5 = call i32 @pthread_create(i32* %4, i32* null, i32 (i32*)* @tls_ptr, i32* null)
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%7 = call i32 @pthread_create(i32* %6, i32* null, i32 (i32*)* @tls_ptr, i32* null)
%8 = load i32, i32* %4
%9 = call i32 @pthread_join(i32 %8, i32* null)
%10 = load i32, i32* %6
%11 = call i32 @pthread_join(i32 %10, i32* null)
%12 = call i32 @tls_ptr(i32* null)
ret i32 0
}