#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 *Thread2(void *unused) {
  long *x = GetTls();
  fprintf(stderr, "stack: %p dtls: %p\n", &x, x);
  if (*x)
    fprintf(stderr, "foo\n");
  return 0;
}


x86 assembly (clang, -O0):
<Thread2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1030 <GetTls@plt>
mov    %rax,-0x10(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rcx
lea    0xeb5(%rip),%rsi
lea    -0x10(%rbp),%rdx
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     117b <Thread2+0x5b>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Thread2>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1030 <GetTls@plt>
mov    %rax,0x8(%rsp)
mov    0x2ea8(%rip),%rbx
mov    (%rbx),%edi
lea    0xebf(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    0x8(%rsp),%rax
cmpq   $0x0,(%rax)
je     116b <Thread2+0x4b>
mov    (%rbx),%edi
lea    0xeb0(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [20 x i8] c"stack: %p dtls: %p\0A\00"
@.str.1 = [5 x i8] c"foo\0A\00"
define noalias i8* @Thread2(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 i32, i32* @stderr
%6 = call i32 (i32, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64** %2, i64* %4)
%7 = load i64*, i64** %2
%8 = load i64, i64* %7
%9 = icmp eq i64 %8, 0
br i1 %9, label %13, label %10
10: ; preds = %1
%11 = load i32, i32* @stderr
%12 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %13
13: ; preds = %10, %1
ret i8* null
}