#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*/ ASSERT(void *(*)(void *));
int /*<<< orphan*/ abort();
int /*<<< orphan*/ log_error(int, char *);
int pthread_create(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                   void *(*)(void *), void *);
pthread_t createThread(void *(*start_routine)(void *), void *arg) {
  ASSERT(start_routine);
  int retval;
  pthread_t thread;
  retval = pthread_create(&thread, NULL, start_routine, arg);
  if (retval != 0) {
    log_error(retval, "Error pthread_create()");
    abort();
  }
  return thread;
}


x86 assembly (clang, -O0):
<createThread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <ASSERT@plt>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <pthread_create@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1191 <createThread+0x51>
mov    -0x14(%rbp),%edi
lea    0xe7b(%rip),%rsi
call   1040 <log_error@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createThread>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1060 <ASSERT@plt>
lea    0x4(%rsp),%rdi
xor    %esi,%esi
mov    %rbx,%rdx
mov    %r14,%rcx
call   1050 <pthread_create@plt>
test   %eax,%eax
jne    1171 <createThread+0x31>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe88(%rip),%rsi
mov    %eax,%edi
call   1040 <log_error@plt>
xor    %eax,%eax
call   1030 <abort@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"Error pthread_create()\00"
define i32 @createThread(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 = load i8* (i8*)*, i8* (i8*)** %3
%8 = call i32 @ASSERT(i8* (i8*)* %7)
%9 = load i8* (i8*)*, i8* (i8*)** %3
%10 = load i8*, i8** %4
%11 = call i32 @pthread_create(i32* %6, i32* null, i8* (i8*)* %9, i8* %10)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %2
%15 = load i32, i32* %5
%16 = call i32 @log_error(i32 %15, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (...) @abort()
unreachable
18: ; preds = %2
%19 = load i32, i32* %6
ret i32 %19
}

LLVM IR (-O2):
@.str = [23 x i8] c"Error pthread_create()\00"
define i32 @createThread(i8* (i8*)* %0, i8* %1) {
%3 = alloca i32
%4 = tail call i32 @ASSERT(i8* (i8*)* %0)
%5 = bitcast i32* %3 to i8*
%6 = call i32 @pthread_create(i32* %3, i32* null, i8* (i8*)* %0, i8* %1)
%7 = icmp eq i32 %6, 0
br i1 %7, label %11, label %8
8: ; preds = %2
%9 = call i32 @log_error(i32 %6, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%10 = call i32 (...) @abort()
unreachable
11: ; preds = %2
%12 = load i32, i32* %3
ret i32 %12
}