#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 */
int /*<<< orphan*/ printf(char *, ...);
int pthread_detach(int /*<<< orphan*/);
int /*<<< orphan*/ pthread_self();
void *thread_task(void *arg) {
  int ret;
  printf("thread task has been started !\n");
  ret = pthread_detach(pthread_self());
  printf("(1) call pthread_detach return %d\n", ret);
  ret = pthread_detach(pthread_self());
  printf("(2) call pthread_detach return %d\n", ret);
  ret = pthread_detach(pthread_self());
  printf("(3) call pthread_detach return %d\n", ret);
  return NULL;
}


x86 assembly (clang, -O0):
<thread_task>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%edi
call   1040 <pthread_detach@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xebb(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%edi
call   1040 <pthread_detach@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xebc(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <pthread_self@plt>
mov    %eax,%edi
call   1040 <pthread_detach@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xebd(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_task>:
push   %rax
lea    0xf21(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%edi
call   1050 <pthread_detach@plt>
lea    0xe9e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%edi
call   1050 <pthread_detach@plt>
lea    0xea3(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %eax,%edi
call   1050 <pthread_detach@plt>
lea    0xea8(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [32 x i8] c"thread task has been started !\0A\00"
@.str.1 = [35 x i8] c"(1) call pthread_detach return %d\0A\00"
@.str.2 = [35 x i8] c"(2) call pthread_detach return %d\0A\00"
@.str.3 = [35 x i8] c"(3) call pthread_detach return %d\0A\00"
define i8* @thread_task(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%5 = call i32 (...) @pthread_self()
%6 = call i32 @pthread_detach(i32 %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = call i32 (...) @pthread_self()
%10 = call i32 @pthread_detach(i32 %9)
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = call i32 (...) @pthread_self()
%14 = call i32 @pthread_detach(i32 %13)
store i32 %14, i32* %3
%15 = load i32, i32* %3
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %15)
ret i8* null
}

LLVM IR (-O2):
@.str.1 = [35 x i8] c"(1) call pthread_detach return %d\0A\00"
@.str.2 = [35 x i8] c"(2) call pthread_detach return %d\0A\00"
@.str.3 = [35 x i8] c"(3) call pthread_detach return %d\0A\00"
@str = [31 x i8] c"thread task has been started !\00"
define noalias i8* @thread_task(i8* nocapture readnone %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 (...) @pthread_self()
%4 = tail call i32 @pthread_detach(i32 %3)
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32 (...) @pthread_self()
%7 = tail call i32 @pthread_detach(i32 %6)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %7)
%9 = tail call i32 (...) @pthread_self()
%10 = tail call i32 @pthread_detach(i32 %9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i32 %10)
ret i8* null
}