#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 pthread_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SYS_gettid;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, int, int, unsigned int);
int /*<<< orphan*/ pthread_exit(void *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int syscall(int /*<<< orphan*/);
void *thr_func(void *thr_num) {
  pthread_t tid;
  if ((tid = syscall(SYS_gettid)) == -1) {
    fprintf(stderr, "Err. syscall() %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  printf("thread '%d' - TID %lu - Address 0x%x\n", (int)thr_num, tid,
         (unsigned int)tid);
  pthread_exit((void *)0);
}


x86 assembly (clang, -O0):
<thr_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11c0 <thr_func+0x60>
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x18(%rbp),%edi
mov    %rax,%rdx
lea    0xe53(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %eax,%esi
mov    -0x14(%rbp),%edx
mov    -0x14(%rbp),%ecx
lea    0xe40(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1060 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thr_func>:
push   %rbx
mov    %rdi,%rbx
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <syscall@plt>
cmp    $0xffffffff,%eax
je     1191 <thr_func+0x31>
lea    0xe95(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
mov    %eax,%ecx
call   1030 <printf@plt>
xor    %edi,%edi
pop    %rbx
jmp    1060 <pthread_exit@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%ebx
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
lea    0xe51(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SYS_gettid = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Err. syscall() %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [38 x i8] c"thread '%d' - TID %lu - Address 0x%x\0A\00"
define i8* @thr_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i32, i32* @SYS_gettid
%6 = call i32 @syscall(i32 %5)
store i32 %6, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %15
8: ; preds = %1
%9 = load i32, i32* @stderr
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %1
%16 = load i8*, i8** %3
%17 = ptrtoint i8* %16 to i32
%18 = load i32, i32* %4
%19 = load i32, i32* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18, i32 %19)
%21 = call i32 @pthread_exit(i8* null)
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@SYS_gettid = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Err. syscall() %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@.str.1 = [38 x i8] c"thread '%d' - TID %lu - Address 0x%x\0A\00"
define noalias i8* @thr_func(i8* %0) {
%2 = load i32, i32* @SYS_gettid
%3 = tail call i32 @syscall(i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %1
%13 = ptrtoint i8* %0 to i64
%14 = trunc i64 %13 to i32
%15 = tail call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %3, i32 %3)
%16 = tail call i32 @pthread_exit(i8* null)
ret i8* undef
}