#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*/ getchar();
int /*<<< orphan*/ printf(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);
  printf("[parent] press any to quit!\n");
  getchar();
  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     11b8 <main+0x48>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe59(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,%rcx
mov    %rcx,-0x18(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jle    11f4 <main+0x84>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
lea    0xe32(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123b <main+0xcb>
cmpq   $0x0,-0x18(%rbp)
jne    1218 <main+0xa8>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <run_target@plt>
movl   $0x0,-0x4(%rbp)
jmp    123b <main+0xcb>
mov    -0x18(%rbp),%rdi
call   1080 <run_debugger@plt>
lea    0xdf8(%rip),%rdi
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getchar@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    11d3 <main+0x63>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     11a6 <main+0x36>
je     11c4 <main+0x54>
mov    %rax,%rdi
call   1080 <run_debugger@plt>
lea    0xe8a(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
jmp    11cf <main+0x5f>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    0xe5d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    11cf <main+0x5f>
mov    0x8(%rbx),%rdi
call   1060 <run_target@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe1a(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%edi
call   1070 <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"
@.str.2 = [29 x i8] c"[parent] press any to quit!\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 %35
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 %35
30: ; preds = %22
%31 = load i64, i64* %6
%32 = call i32 @run_debugger(i64 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0))
%34 = call i32 (...) @getchar()
store i32 0, i32* %3
br label %35
35: ; preds = %30, %25, %19
%36 = load i32, i32* %3
ret i32 %36
}

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"
@str = [28 x i8] c"[parent] press any to quit!\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 %25
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 %25
21: ; preds = %15
%22 = tail call i32 @run_debugger(i64 %10)
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%24 = tail call i32 (...) @getchar()
br label %25
25: ; preds = %21, %17, %12
%26 = phi i32 [ -1, %12 ], [ 0, %17 ], [ 0, %21 ]
ret i32 %26
}