#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_attr_setstacksize(int /*<<< orphan*/ *, int);
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_attr_setstacksize(&att, 10000000)) {
    fprintf(stderr, "pthread_attr_setstacksize 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     11b2 <new_thread+0x42>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdi
call   1050 <pthread_attr_setdetachstate@plt>
cmp    $0x0,%rax
je     11ed <new_thread+0x7d>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe39(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
lea    -0x18(%rbp),%rdi
mov    $0x989680,%esi
call   1090 <pthread_attr_setstacksize@plt>
cmp    $0x0,%rax
je     1224 <new_thread+0xb4>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe23(%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     1262 <new_thread+0xf2>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%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     1294 <new_thread+0x124>
mov    0x2d5c(%rip),%rax
mov    (%rax),%edi
lea    0xde6(%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    11dc <new_thread+0x6c>
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdi
call   1050 <pthread_attr_setdetachstate@plt>
test   %rax,%rax
jne    11ee <new_thread+0x7e>
mov    %rsp,%rdi
mov    $0x989680,%esi
call   1090 <pthread_attr_setstacksize@plt>
test   %rax,%rax
jne    1200 <new_thread+0x90>
lea    0x4(%rsp),%rdi
mov    %rsp,%rsi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1060 <pthread_create@plt>
test   %rax,%rax
jne    1212 <new_thread+0xa2>
mov    %rsp,%rdi
call   1070 <pthread_attr_destroy@plt>
test   %rax,%rax
jne    1224 <new_thread+0xb4>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2df5(%rip),%rax
mov    (%rax),%edi
lea    0xe14(%rip),%rsi
jmp    1234 <new_thread+0xc4>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
lea    0xe19(%rip),%rsi
jmp    1234 <new_thread+0xc4>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
jmp    1234 <new_thread+0xc4>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
jmp    1234 <new_thread+0xc4>
mov    0x2dad(%rip),%rax
mov    (%rax),%edi
lea    0xe37(%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 = [31 x i8] c"pthread_attr_setstacksize err\0A\00"
@.str.3 = [20 x i8] c"pthread_create err\0A\00"
@.str.4 = [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 = call i64 @pthread_attr_setstacksize(i32* %6, i32 10000000)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = load i8* (i8*)*, i8* (i8*)** %3
%30 = load i8*, i8** %4
%31 = call i64 @pthread_create(i32* %5, i32* %6, i8* (i8*)* %29, i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %28
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = call i64 @pthread_attr_destroy(i32* %6)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
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 = [31 x i8] c"pthread_attr_setstacksize err\0A\00"
@.str.3 = [20 x i8] c"pthread_create err\0A\00"
@.str.4 = [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_attr_setstacksize(i32* %4, i32 10000000)
%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 ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %21
%29 = call i64 @pthread_create(i32* %3, i32* %4, i8* (i8*)* %0, i8* %1)
%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 ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 1)
unreachable
35: ; preds = %28
%36 = call i64 @pthread_attr_destroy(i32* %4)
%37 = icmp eq i64 %36, 0
br i1 %37, label %42, label %38
38: ; preds = %35
%39 = load i32, i32* @stderr
%40 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %35
ret void
}