#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 int /*<<< orphan*/ uint64_t;
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*/);
int /*<<< orphan*/ run_target(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char **argv) {
  pid_t child_pid;
  if (argc < 3) {
    fprintf(stderr, "Expected <program name> and <breakpoint address as hex "
                    "string> as argument\n");
    return -1;
  }
  child_pid = fork();
  if (child_pid == 0)
    run_target(argv[1]);
  else if (child_pid > 0) {
    uint64_t addr = (uint64_t)strtol(argv[2], NULL, 16);
    run_debugger(child_pid, addr);
  } 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   $0x3,-0x8(%rbp)
jge    11a1 <main+0x41>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <main+0xc2>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c9 <main+0x69>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <run_target@plt>
jmp    121b <main+0xbb>
cmpq   $0x0,-0x18(%rbp)
jle    11fe <main+0x9e>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <run_debugger@plt>
jmp    1216 <main+0xb6>
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1222 <main+0xc2>
jmp    121b <main+0xbb>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jg     1186 <main+0x26>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    0xe86(%rip),%rsi
call   1030 <fprintf@plt>
mov    $0xffffffff,%ebx
jmp    11c3 <main+0x63>
mov    %rsi,%r14
xor    %ebx,%ebx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ba <main+0x5a>
jle    11cb <main+0x6b>
mov    %rax,%r15
mov    0x10(%r14),%rdi
xor    %ebx,%ebx
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtol@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1070 <run_debugger@plt>
jmp    11c3 <main+0x63>
mov    0x8(%r14),%rdi
call   1050 <run_target@plt>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe7a(%rip),%rdi
call   1060 <perror@plt>
jmp    117f <main+0x1f>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [76 x i8] c"Expected <program name> and <breakpoint address as hex string> 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
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 3
br i1 %9, label %10, label %13
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %37
13: ; preds = %2
%14 = call i64 (...) @fork()
store i64 %14, i64* %6
%15 = load i64, i64* %6
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @run_target(i8* %20)
br label %36
22: ; preds = %13
%23 = load i64, i64* %6
%24 = icmp sgt i64 %23, 0
br i1 %24, label %25, label %33
25: ; preds = %22
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @strtol(i8* %28, i32* null, i32 16)
store i32 %29, i32* %7
%30 = load i64, i64* %6
%31 = load i32, i32* %7
%32 = call i32 @run_debugger(i64 %30, i32 %31)
br label %35
33: ; preds = %22
%34 = 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 %37
35: ; preds = %25
br label %36
36: ; preds = %35, %17
store i32 0, i32* %3
br label %37
37: ; preds = %36, %33, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [76 x i8] c"Expected <program name> and <breakpoint address as hex string> 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, 3
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 ([76 x i8], [76 x i8]* @.str, i64 0, i64 0))
br label %23
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 %23
14: ; preds = %7
%15 = icmp sgt i64 %8, 0
br i1 %15, label %16, label %21
16: ; preds = %14
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @strtol(i8* nocapture %18, i32* null, i32 16)
%20 = tail call i32 @run_debugger(i64 %8, i32 %19)
br label %23
21: ; preds = %14
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %10, %16, %21, %4
%24 = phi i32 [ -1, %4 ], [ -1, %21 ], [ 0, %16 ], [ 0, %10 ]
ret i32 %24
}