#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 do_child(int, char **);
int do_trace(scalar_t__);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
int main(int argc, char **argv) {
  if (argc < 2) {
    fprintf(stderr, "Usage: %s prog args\n", argv[0]);
    exit(1);
  }
  pid_t child = fork();
  if (child == 0) {
    return do_child(argc - 1, argv + 1);
  } else {
    return do_trace(child);
  }
}


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    1196 <main+0x46>
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe79(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11c7 <main+0x77>
mov    -0x8(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1030 <do_child@plt>
mov    %eax,-0x4(%rbp)
jmp    11d3 <main+0x83>
mov    -0x18(%rbp),%rdi
call   1040 <do_trace@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jle    118e <main+0x3e>
mov    %edi,%ebp
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1177 <main+0x27>
mov    %rax,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <do_trace@plt>
add    $0xffffffff,%ebp
add    $0x8,%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1030 <do_child@plt>
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe5f(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s prog args\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 slt 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 @fprintf(i32 %10, i8* getelementptr inbounds ([21 x i8], [21 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 = load i64, i64* %6
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %26
20: ; preds = %16
%21 = load i32, i32* %4
%22 = sub nsw i32 %21, 1
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = call i32 @do_child(i32 %22, i8** %24)
store i32 %25, i32* %3
br label %29
26: ; preds = %16
%27 = load i64, i64* %6
%28 = call i32 @do_trace(i64 %27)
store i32 %28, i32* %3
br label %29
29: ; preds = %26, %20
%30 = load i32, i32* %3
ret i32 %30
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s prog args\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([21 x i8], [21 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 eq i64 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %9
%13 = add nsw i32 %0, -1
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = tail call i32 @do_child(i32 %13, i8** %14)
br label %18
16: ; preds = %9
%17 = tail call i32 @do_trace(i64 %10)
br label %18
18: ; preds = %16, %12
%19 = phi i32 [ %15, %12 ], [ %17, %16 ]
ret i32 %19
}