#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
pid_t proc_start(void *(*fn)(int), int id) {
  pid_t pid;
  pid = fork();
  if (pid == (pid_t)-1) {
    fprintf(stderr, "Fork failed for id %d\n", id);
    return pid;
  }
  if (pid == 0) {
    fn(id);
    exit(0);
  }
  return pid;
}


x86 assembly (clang, -O0):
<proc_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1050 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0xffffffffffffffff,-0x20(%rbp)
jne    117a <proc_start+0x4a>
mov    0x2e84(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe98(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    119d <proc_start+0x6d>
cmpq   $0x0,-0x20(%rbp)
jne    1195 <proc_start+0x65>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%edi
call   *%rax
xor    %edi,%edi
call   1040 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<proc_start>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <fork@plt>
mov    %rax,%rbx
cmp    $0xffffffffffffffff,%rax
je     115a <proc_start+0x2a>
test   %rbx,%rbx
jne    1171 <proc_start+0x41>
mov    %ebp,%edi
call   *%r14
xor    %edi,%edi
call   1040 <exit@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
lea    0xe96(%rip),%rsi
mov    %ebp,%edx
call   1030 <fprintf@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [23 x i8] c"Fork failed for id %d\0A\00"
define i64 @proc_start(i8* (i32)* %0, i32 %1) {
%3 = alloca i64
%4 = alloca i8* (i32)*
%5 = alloca i32
%6 = alloca i64
store i8* (i32)* %0, i8* (i32)** %4
store i32 %1, i32* %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = icmp eq i64 %8, -1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* %5
%13 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i64, i64* %6
store i64 %14, i64* %3
br label %25
15: ; preds = %2
%16 = load i64, i64* %6
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %15
%19 = load i8* (i32)*, i8* (i32)** %4
%20 = load i32, i32* %5
%21 = call i8* %19(i32 %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %15
%24 = load i64, i64* %6
store i64 %24, i64* %3
br label %25
25: ; preds = %23, %10
%26 = load i64, i64* %3
ret i64 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"Fork failed for id %d\0A\00"
define i64 @proc_start(i8* (i32)* nocapture %0, i32 %1) {
%3 = tail call i64 (...) @fork()
switch i64 %3, label %10 [
i64 -1, label %4
i64 0, label %7
]
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %1)
br label %10
7: ; preds = %2
%8 = tail call i8* %0(i32 %1)
%9 = tail call i32 @exit(i32 0)
unreachable
10: ; preds = %2, %4
ret i64 %3
}