#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;
typedef int /*<<< orphan*/ pthread_attr_t;

/* Variables and functions */
int /*<<< orphan*/ PTHREAD_CREATE_DETACHED;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ pthread_attr_destroy(int /*<<< orphan*/ *);
scalar_t__ pthread_attr_init(int /*<<< orphan*/ *);
scalar_t__ pthread_attr_setdetachstate(int /*<<< orphan*/ *,
                                       int /*<<< orphan*/);
scalar_t__ pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                          void *(*)(void *), void *);
int /*<<< orphan*/ stderr;
void new_thread(void *(*f)(void *), void *data) {
  pthread_t t;
  pthread_attr_t att;
  if (pthread_attr_init(&att)) {
    fprintf(stderr, "pthread_attr_init err\n");
    exit(1);
  }
  if (pthread_attr_setdetachstate(&att, PTHREAD_CREATE_DETACHED)) {
    fprintf(stderr, "pthread_attr_setdetachstate err\n");
    exit(1);
  }
  if (pthread_create(&t, &att, f, data)) {
    fprintf(stderr, "pthread_create err\n");
    exit(1);
  }
  if (pthread_attr_destroy(&att)) {
    fprintf(stderr, "pthread_attr_destroy err\n");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<new_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1030 <pthread_attr_init@plt>
cmp    $0x0,%rax
je     11a2 <new_thread+0x42>
mov    0x2e4e(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1050 <pthread_attr_setdetachstate@plt>
cmp    $0x0,%rax
je     11dd <new_thread+0x7d>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe49(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <pthread_create@plt>
cmp    $0x0,%rax
je     121b <new_thread+0xbb>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe2c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1070 <pthread_attr_destroy@plt>
cmp    $0x0,%rax
je     124d <new_thread+0xed>
mov    0x2da3(%rip),%rax
mov    (%rax),%edi
lea    0xe0e(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<new_thread>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    %rsp,%rdi
call   1030 <pthread_attr_init@plt>
test   %rax,%rax
jne    11ba <new_thread+0x5a>
mov    0x2e62(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1050 <pthread_attr_setdetachstate@plt>
test   %rax,%rax
jne    11cc <new_thread+0x6c>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <pthread_create@plt>
test   %rax,%rax
jne    11de <new_thread+0x7e>
mov    %rsp,%rdi
call   1070 <pthread_attr_destroy@plt>
test   %rax,%rax
jne    11f0 <new_thread+0x90>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e17(%rip),%rax
mov    (%rax),%edi
lea    0xe36(%rip),%rsi
jmp    1200 <new_thread+0xa0>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe3b(%rip),%rsi
jmp    1200 <new_thread+0xa0>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
jmp    1200 <new_thread+0xa0>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"pthread_attr_init err\0A\00"
@PTHREAD_CREATE_DETACHED = global i32 0
@.str.1 = [33 x i8] c"pthread_attr_setdetachstate err\0A\00"
@.str.2 = [20 x i8] c"pthread_create err\0A\00"
@.str.3 = [26 x i8] c"pthread_attr_destroy err\0A\00"
define void @new_thread(i8* (i8*)* %0, i8* %1) {
%3 = alloca i8* (i8*)*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* (i8*)* %0, i8* (i8*)** %3
store i8* %1, i8** %4
%7 = call i64 @pthread_attr_init(i32* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @PTHREAD_CREATE_DETACHED
%15 = call i64 @pthread_attr_setdetachstate(i32* %6, i32 %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = load i8* (i8*)*, i8* (i8*)** %3
%23 = load i8*, i8** %4
%24 = call i64 @pthread_create(i32* %5, i32* %6, i8* (i8*)* %22, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %30
26: ; preds = %21
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %21
%31 = call i64 @pthread_attr_destroy(i32* %6)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %30
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %30
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"pthread_attr_init err\0A\00"
@PTHREAD_CREATE_DETACHED = global i32 0
@.str.1 = [33 x i8] c"pthread_attr_setdetachstate err\0A\00"
@.str.2 = [20 x i8] c"pthread_create err\0A\00"
@.str.3 = [26 x i8] c"pthread_attr_destroy err\0A\00"
define void @new_thread(i8* (i8*)* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = bitcast i32* %3 to i8*
%6 = bitcast i32* %4 to i8*
%7 = call i64 @pthread_attr_init(i32* %4)
%8 = icmp eq i64 %7, 0
br i1 %8, label %13, label %9
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = load i32, i32* @PTHREAD_CREATE_DETACHED
%15 = call i64 @pthread_attr_setdetachstate(i32* %4, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %21, label %17
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = call i64 @pthread_create(i32* %3, i32* %4, i8* (i8*)* %0, i8* %1)
%23 = icmp eq i64 %22, 0
br i1 %23, label %28, label %24
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = call i64 @pthread_attr_destroy(i32* %4)
%30 = icmp eq i64 %29, 0
br i1 %30, label %35, label %31
31: ; preds = %28
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
ret void
}