#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 fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ reap();
int /*<<< orphan*/ run_child(int, char **);
int start_reaper(int argc, char **argv) {
  int pid;
  int res = 0;
  pid = fork();
  switch (pid) {
  case 0:
    run_child(argc, argv);
    break;
  case -1:
    perror("fork");
    res = 1;
    break;
  default:
    reap();
  }
  return res;
}


x86 assembly (clang, -O0):
<start_reaper>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     1195 <start_reaper+0x55>
jmp    1174 <start_reaper+0x34>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
jne    11ad <start_reaper+0x6d>
jmp    1184 <start_reaper+0x44>
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <run_child@plt>
jmp    11b4 <start_reaper+0x74>
lea    0xe64(%rip),%rdi
call   1040 <perror@plt>
movl   $0x1,-0x18(%rbp)
jmp    11b4 <start_reaper+0x74>
mov    $0x0,%al
call   1030 <reap@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<start_reaper>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
xor    %ebx,%ebx
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1166 <start_reaper+0x26>
cmp    $0xffffffff,%eax
je     1177 <start_reaper+0x37>
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <reap@plt>
jmp    1170 <start_reaper+0x30>
mov    %ebp,%edi
mov    %r14,%rsi
call   1050 <run_child@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe82(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%ebx
jmp    1170 <start_reaper+0x30>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
define i32 @start_reaper(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i32 0, i32* %6
%7 = call i32 (...) @fork()
store i32 %7, i32* %5
%8 = load i32, i32* %5
switch i32 %8, label %15 [
i32 0, label %9
i32 -1, label %13
]
9: ; preds = %2
%10 = load i32, i32* %3
%11 = load i8**, i8*** %4
%12 = call i32 @run_child(i32 %10, i8** %11)
br label %17
13: ; preds = %2
%14 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %6
br label %17
15: ; preds = %2
%16 = call i32 (...) @reap()
br label %17
17: ; preds = %15, %13, %9
%18 = load i32, i32* %6
ret i32 %18
}

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