#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*/ fprintf(int /*<<< orphan*/, char *, int, int);
int /*<<< orphan*/ pthread_detach(int);
int /*<<< orphan*/ pthread_exit(int /*<<< orphan*/);
int pthread_self();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void *work(void *data) {
  pthread_t tid;
  tid = pthread_self();
  pthread_detach(tid);
  fprintf(stderr, "[%d] thread 0x%08x start...\n", *(int *)data, tid);
  sleep(3);
  fprintf(stderr, "[%d] thread 0x%08x exit...\n", *(int *)data, tid);
  pthread_exit(0);
}


x86 assembly (clang, -O0):
<work>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1050 <pthread_detach@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%ecx
lea    0xe79(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x14(%rbp),%ecx
lea    0xe6e(%rip),%rsi
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<work>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1050 <pthread_detach@plt>
mov    0x2e72(%rip),%r14
mov    (%r14),%edi
mov    (%rbx),%edx
lea    0xe86(%rip),%rsi
mov    %ebp,%ecx
call   1030 <fprintf@plt>
mov    $0x3,%edi
call   1070 <sleep@plt>
mov    (%r14),%edi
mov    (%rbx),%edx
lea    0xe86(%rip),%rsi
mov    %ebp,%ecx
call   1030 <fprintf@plt>
xor    %edi,%edi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <pthread_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"[%d] thread 0x%08x start...\0A\00"
@.str.1 = [28 x i8] c"[%d] thread 0x%08x exit...\0A\00"
define i8* @work(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = call i32 (...) @pthread_self()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = call i32 @pthread_detach(i32 %6)
%8 = load i32, i32* @stderr
%9 = load i8*, i8** %3
%10 = bitcast i8* %9 to i32*
%11 = load i32, i32* %10
%12 = load i32, i32* %4
%13 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %11, i32 %12)
%14 = call i32 @sleep(i32 3)
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = bitcast i8* %16 to i32*
%18 = load i32, i32* %17
%19 = load i32, i32* %4
%20 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %19)
%21 = call i32 @pthread_exit(i32 0)
%22 = load i8*, i8** %2
ret i8* %22
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"[%d] thread 0x%08x start...\0A\00"
@.str.1 = [28 x i8] c"[%d] thread 0x%08x exit...\0A\00"
define noalias i8* @work(i8* nocapture %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 @pthread_detach(i32 %2)
%4 = load i32, i32* @stderr
%5 = bitcast i8* %0 to i32*
%6 = load i32, i32* %5
%7 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i32 %6, i32 %2)
%8 = tail call i32 @sleep(i32 3)
%9 = load i32, i32* @stderr
%10 = load i32, i32* %5
%11 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i32 %10, i32 %2)
%12 = tail call i32 @pthread_exit(i32 0)
ret i8* undef
}