#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 */

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ set_cpu(int);
void start_process_on(void *(*fn)(void *), void *arg, int cpu) {
  int pid;
  pid = fork();
  if (pid == -1) {
    perror("fork");
    exit(1);
  }
  if (pid)
    return;
  set_cpu(cpu);
  fn(arg);
  exit(0);
}


x86 assembly (clang, -O0):
<start_process_on>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    117d <start_process_on+0x3d>
lea    0xe92(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
je     118d <start_process_on+0x4d>
add    $0x20,%rsp
pop    %rbp
ret
mov    -0x14(%rbp),%edi
call   1030 <set_cpu@plt>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdi
call   *%rax
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<start_process_on>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1161 <start_process_on+0x21>
cmp    $0xffffffff,%eax
je     1174 <start_process_on+0x34>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %ebp,%edi
call   1030 <set_cpu@plt>
mov    %r14,%rdi
call   *%rbx
xor    %edi,%edi
call   1050 <exit@plt>
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

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

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
define void @start_process_on(i8* (i8*)* nocapture %0, i8* %1, i32 %2) {
%4 = tail call i32 (...) @fork()
switch i32 %4, label %8 [
i32 -1, label %5
i32 0, label %9
]
5: ; preds = %3
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %3
ret void
9: ; preds = %3
%10 = tail call i32 @set_cpu(i32 %2)
%11 = tail call i8* %0(i8* %1)
%12 = tail call i32 @exit(i32 0)
unreachable
}