#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 */
scalar_t__ pthread_create(int /*<<< orphan*/ *, void *, void *(*)(void *),
                          void *);
scalar_t__ pthread_detach(int /*<<< orphan*/);
int /*<<< orphan*/ sys_die(char *);
extern void sys_thread(void *(*fn)(void *arg), void *arg) {
  pthread_t t;
  if (pthread_create(&t, ((void *)0), fn, arg) != 0)
    sys_die("sys: cannot create a thread\n");
  if (pthread_detach(t) != 0)
    sys_die("sys: cannot detach from a thread\n");
}


x86 assembly (clang, -O0):
<sys_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x14(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_create@plt>
cmp    $0x0,%rax
je     116b <sys_thread+0x3b>
lea    0xe9a(%rip),%rdi
call   1030 <sys_die@plt>
mov    -0x14(%rbp),%edi
call   1040 <pthread_detach@plt>
cmp    $0x0,%rax
je     1189 <sys_thread+0x59>
lea    0xe99(%rip),%rdi
call   1030 <sys_die@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_thread>:
push   %rax
mov    %rsi,%rcx
mov    %rdi,%rdx
lea    0x4(%rsp),%rdi
xor    %esi,%esi
call   1050 <pthread_create@plt>
test   %rax,%rax
je     1154 <sys_thread+0x24>
lea    0xeb1(%rip),%rdi
call   1030 <sys_die@plt>
mov    0x4(%rsp),%edi
call   1040 <pthread_detach@plt>
test   %rax,%rax
je     116e <sys_thread+0x3e>
lea    0xeb4(%rip),%rdi
call   1030 <sys_die@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [29 x i8] c"sys: cannot create a thread\0A\00"
@.str.1 = [34 x i8] c"sys: cannot detach from a thread\0A\00"
define void @sys_thread(i8* (i8*)* %0, i8* %1) {
%3 = alloca i8* (i8*)*
%4 = alloca i8*
%5 = alloca i32
store i8* (i8*)* %0, i8* (i8*)** %3
store i8* %1, i8** %4
%6 = load i8* (i8*)*, i8* (i8*)** %3
%7 = load i8*, i8** %4
%8 = call i64 @pthread_create(i32* %5, i8* null, i8* (i8*)* %6, i8* %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @sys_die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i32, i32* %5
%14 = call i64 @pthread_detach(i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %12
%17 = call i32 @sys_die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %12
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"sys: cannot create a thread\0A\00"
@.str.1 = [34 x i8] c"sys: cannot detach from a thread\0A\00"
define void @sys_thread(i8* (i8*)* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i64 @pthread_create(i32* %3, i8* null, i8* (i8*)* %0, i8* %1)
%6 = icmp eq i64 %5, 0
br i1 %6, label %9, label %7
7: ; preds = %2
%8 = call i32 @sys_die(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %2
%10 = load i32, i32* %3
%11 = call i64 @pthread_detach(i32 %10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = call i32 @sys_die(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %9
ret void
}