#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, int);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
void create_thread(void *(*thread_func)(void *)) {
  pthread_t thread;
  int ret = pthread_create(&thread, NULL, thread_func, NULL);
  if (ret != 0) {
    fprintf(stderr, "pthread_create: %s (%d)\n", strerror(ret), ret);
    exit(1);
  }
}


x86 assembly (clang, -O0):
<create_thread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0xc(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
call   1040 <pthread_create@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     11a0 <create_thread+0x60>
mov    0x2e6c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
mov    -0x10(%rbp),%ecx
lea    0xe6f(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_thread>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rdx
lea    0x4(%rsp),%rdi
xor    %esi,%esi
xor    %ecx,%ecx
call   1040 <pthread_create@plt>
test   %eax,%eax
jne    115f <create_thread+0x1f>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    %eax,%ebx
mov    0x2e78(%rip),%rax
mov    (%rax),%ebp
mov    %ebx,%edi
call   1060 <strerror@plt>
lea    0xe88(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
mov    %ebx,%ecx
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [25 x i8] c"pthread_create: %s (%d)\0A\00"
define void @create_thread(i8* (i8*)* %0) {
%2 = alloca i8* (i8*)*
%3 = alloca i32
%4 = alloca i32
store i8* (i8*)* %0, i8* (i8*)** %2
%5 = load i8* (i8*)*, i8* (i8*)** %2
%6 = call i32 @pthread_create(i32* %3, i32* null, i8* (i8*)* %5, i32* null)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i32, i32* %4
%12 = call i8* @strerror(i32 %11)
%13 = load i32, i32* %4
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %12, i32 %13)
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %1
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [25 x i8] c"pthread_create: %s (%d)\0A\00"
define void @create_thread(i8* (i8*)* %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = call i32 @pthread_create(i32* %2, i32* null, i8* (i8*)* %0, i32* null)
%5 = icmp eq i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i8* @strerror(i32 %4)
%9 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %8, i32 %4)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %1
ret void
}