#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 */
struct tree_node {
  int dummy;
};
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ explain_wait_status(int /*<<< orphan*/, int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct tree_node *get_tree_from_file(char *);
int /*<<< orphan*/ make_proc_tree(struct tree_node *);
int /*<<< orphan*/ show_pstree(int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int main(int argc, char *argv[]) {
  pid_t pid;
  int status;
  struct tree_node *root;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <input_tree_file>\n\n", argv[0]);
    exit(1);
  }
  root = get_tree_from_file(argv[1]);
  pid = make_proc_tree(root);
  sleep(3);
  show_pstree(pid);
  pid = wait(&status);
  explain_wait_status(pid, status);
  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     11c6 <main+0x46>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe49(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1030 <get_tree_from_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <make_proc_tree@plt>
mov    %eax,-0x14(%rbp)
mov    $0x3,%edi
call   1080 <sleep@plt>
mov    -0x14(%rbp),%edi
call   1060 <show_pstree@plt>
lea    -0x18(%rbp),%rdi
call   1090 <wait@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10a0 <explain_wait_status@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11cb <main+0x4b>
mov    0x8(%rsi),%rdi
call   1030 <get_tree_from_file@plt>
mov    %rax,%rdi
call   1040 <make_proc_tree@plt>
mov    %eax,%ebx
mov    $0x3,%edi
call   1080 <sleep@plt>
mov    %ebx,%edi
call   1060 <show_pstree@plt>
lea    0xc(%rsp),%rdi
call   1090 <wait@plt>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   10a0 <explain_wait_status@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e0e(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe22(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s <input_tree_file>\0A\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.tree_node*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 2
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call %struct.tree_node* @get_tree_from_file(i8* %21)
store %struct.tree_node* %22, %struct.tree_node** %8
%23 = load %struct.tree_node*, %struct.tree_node** %8
%24 = call i32 @make_proc_tree(%struct.tree_node* %23)
store i32 %24, i32* %6
%25 = call i32 @sleep(i32 3)
%26 = load i32, i32* %6
%27 = call i32 @show_pstree(i32 %26)
%28 = call i32 @wait(i32* %7)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = load i32, i32* %7
%31 = call i32 @explain_wait_status(i32 %29, i32 %30)
ret i32 0
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@stderr = global i32 0
@.str = [30 x i8] c"Usage: %s <input_tree_file>\0A\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = tail call %struct.tree_node* @get_tree_from_file(i8* %13)
%15 = tail call i32 @make_proc_tree(%struct.tree_node* %14)
%16 = tail call i32 @sleep(i32 3)
%17 = tail call i32 @show_pstree(i32 %15)
%18 = call i32 @wait(i32* %3)
%19 = load i32, i32* %3
%20 = call i32 @explain_wait_status(i32 %18, i32 %19)
ret i32 0
}