#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);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ run_debugger(scalar_t__);
int /*<<< orphan*/ run_target(char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  pid_t pid;
  if (argc != 2) {
    fprintf(stderr, "usage: %s program\n", argv[0]);
    exit(-1);
  }
  if (0 > (pid = fork())) {
    fprintf(stderr, "fork error!\n");
    return -1;
  }
  if (pid == 0) {
    run_target(argv[1]);
    return 0;
  }
  run_debugger(pid);
  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)
je     1198 <main+0x48>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jle    11d4 <main+0x84>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1208 <main+0xb8>
cmpq   $0x0,-0x18(%rbp)
jne    11f8 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <run_target@plt>
movl   $0x0,-0x4(%rbp)
jmp    1208 <main+0xb8>
mov    -0x18(%rbp),%rdi
call   1060 <run_debugger@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    119c <main+0x4c>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1171 <main+0x21>
je     118f <main+0x3f>
mov    %rax,%rdi
call   1060 <run_debugger@plt>
jmp    1198 <main+0x48>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret
mov    0x8(%rbx),%rdi
call   1040 <run_target@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    0x2e3d(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe51(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0xffffffff,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"usage: %s program\0A\00"
@.str.1 = [13 x i8] c"fork error!\0A\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 ne i32 %7, 2
br i1 %8, label %9, label %16
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %2
%17 = call i64 (...) @fork()
store i64 %17, i64* %6
%18 = icmp sgt i64 0, %17
br i1 %18, label %19, label %22
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %3
br label %33
22: ; preds = %16
%23 = load i64, i64* %6
%24 = icmp eq i64 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @run_target(i8* %28)
store i32 0, i32* %3
br label %33
30: ; preds = %22
%31 = load i64, i64* %6
%32 = call i32 @run_debugger(i64 %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %25, %19
%34 = load i32, i32* %3
ret i32 %34
}

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