#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 */
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ run_debugger(scalar_t__);
int /*<<< orphan*/ run_target(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  pid_t child_pid;
  if (argc < 2) {
    fprintf(stderr, "Expected a program name as argument\n");
    return -1;
  }
  child_pid = fork();
  if (child_pid == 0)
    run_target(argv[1]);
  else if (child_pid > 0)
    run_debugger(child_pid);
  else {
    perror("fork");
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1191 <main+0x41>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <main+0xa6>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b9 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <run_target@plt>
jmp    11ef <main+0x9f>
cmpq   $0x0,-0x18(%rbp)
jle    11d2 <main+0x82>
mov    -0x18(%rbp),%rdi
call   1060 <run_debugger@plt>
jmp    11ea <main+0x9a>
lea    0xe4c(%rip),%rdi
call   1050 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f6 <main+0xa6>
jmp    11ef <main+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x1,%edi
jg     1175 <main+0x25>
mov    0x2e80(%rip),%rax
mov    (%rax),%edi
lea    0xe97(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    119d <main+0x4d>
mov    %rsi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1194 <main+0x44>
jle    11a7 <main+0x57>
mov    %rax,%rdi
call   1060 <run_debugger@plt>
xor    %ebx,%ebx
jmp    119d <main+0x4d>
mov    0x8(%r14),%rdi
call   1040 <run_target@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe77(%rip),%rdi
call   1050 <perror@plt>
jmp    116e <main+0x1e>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [37 x i8] c"Expected a program name as argument\0A\00"
@.str.1 = [5 x i8] c"fork\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %31
12: ; preds = %2
%13 = call i64 (...) @fork()
store i64 %13, i64* %6
%14 = load i64, i64* %6
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %12
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @run_target(i8* %19)
br label %30
21: ; preds = %12
%22 = load i64, i64* %6
%23 = icmp sgt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i64, i64* %6
%26 = call i32 @run_debugger(i64 %25)
br label %29
27: ; preds = %21
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %31
29: ; preds = %24
br label %30
30: ; preds = %29, %16
store i32 0, i32* %3
br label %31
31: ; preds = %30, %27, %9
%32 = load i32, i32* %3
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [37 x i8] c"Expected a program name as argument\0A\00"
@.str.1 = [5 x i8] c"fork\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
br label %20
7: ; preds = %2
%8 = tail call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %14
10: ; preds = %7
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @run_target(i8* %12)
br label %20
14: ; preds = %7
%15 = icmp sgt i64 %8, 0
br i1 %15, label %16, label %18
16: ; preds = %14
%17 = tail call i32 @run_debugger(i64 %8)
br label %20
18: ; preds = %14
%19 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %20
20: ; preds = %10, %16, %18, %4
%21 = phi i32 [ -1, %4 ], [ -1, %18 ], [ 0, %16 ], [ 0, %10 ]
ret i32 %21
}