#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*/ printf(char *, int);
int /*<<< orphan*/ pthread_detach(int /*<<< orphan*/);
int /*<<< orphan*/ pthread_self();
int /*<<< orphan*/ sleep(int);
void *slave_entry(void *arg) {
  int i;
  pthread_t self;
  self = pthread_self();
  pthread_detach(self);
  for (i = 0; i < 3; i++) {
    printf("slave thread: %d\n", i);
    sleep(1);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<slave_entry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%edi
call   1040 <pthread_detach@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0x3,-0xc(%rbp)
jge    1196 <slave_entry+0x56>
mov    -0xc(%rbp),%esi
lea    0xe87(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1165 <slave_entry+0x25>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<slave_entry>:
push   %rbx
xor    %eax,%eax
call   1050 <pthread_self@plt>
mov    %eax,%edi
call   1040 <pthread_detach@plt>
lea    0xeaa(%rip),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"slave thread: %d\0A\00"
define i8* @slave_entry(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = call i32 (...) @pthread_self()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = call i32 @pthread_detach(i32 %6)
store i32 0, i32* %3
br label %8
8: ; preds = %15, %1
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* %3
%13 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = call i32 @sleep(i32 1)
br label %15
15: ; preds = %11
%16 = load i32, i32* %3
%17 = add nsw i32 %16, 1
store i32 %17, i32* %3
br label %8
18: ; preds = %8
ret i8* null
}

LLVM IR (-O2):
@.str = [18 x i8] c"slave thread: %d\0A\00"
define noalias i8* @slave_entry(i8* nocapture readnone %0) {
%2 = tail call i32 (...) @pthread_self()
%3 = tail call i32 @pthread_detach(i32 %2)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 0)
%5 = tail call i32 @sleep(i32 1)
%6 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 1)
%7 = tail call i32 @sleep(i32 1)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 2)
%9 = tail call i32 @sleep(i32 1)
ret i8* null
}