#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 */

/* Variables and functions */
long *GetTls();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void *Thread1(void *unused) {
  long uninitialized;
  long *x = GetTls();
  if (*x)
    fprintf(stderr, "bar\n");
  *x = uninitialized;
  fprintf(stderr, "stack: %p dtls: %p\n", &x, x);
  return 0;
}


x86 assembly (clang, -O0):
<Thread1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <GetTls@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
je     115c <Thread1+0x3c>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rcx
lea    0xe8a(%rip),%rsi
lea    -0x18(%rbp),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Thread1>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <GetTls@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
cmpq   $0x0,(%rax)
je     1151 <Thread1+0x31>
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    0xeb6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x2e88(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [5 x i8] c"bar\0A\00"
@.str.1 = [20 x i8] c"stack: %p dtls: %p\0A\00"
define i8* @Thread1(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64*
store i8* %0, i8** %2
%5 = call i64* (...) @GetTls()
store i64* %5, i64** %4
%6 = load i64*, i64** %4
%7 = load i64, i64* %6
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %9, %1
%13 = load i64, i64* %3
%14 = load i64*, i64** %4
store i64 %13, i64* %14
%15 = load i32, i32* @stderr
%16 = load i64*, i64** %4
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64** %4, i64* %16)
ret i8* null
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [5 x i8] c"bar\0A\00"
@.str.1 = [20 x i8] c"stack: %p dtls: %p\0A\00"
define noalias i8* @Thread1(i8* nocapture readnone %0) {
%2 = alloca i64*
%3 = bitcast i64** %2 to i8*
%4 = tail call i64* (...) @GetTls()
store i64* %4, i64** %2
%5 = load i64, i64* %4
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %7, %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i64** %2, i64* %4)
ret i8* null
}