#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*/ SIGCONT;
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*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ make_proc_tree(struct tree_node *);
int /*<<< orphan*/ show_pstree(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ wait(int *);
int /*<<< orphan*/ wait_for_ready_children(int);
int main(int argc, char *argv[]) {
  pid_t pid;
  int status;
  struct tree_node *root;
  if (argc < 2) {
    fprintf(stderr, "Please, note the proper usage: %s <input_tree_file>\n\n",
            argv[0]);
    exit(1);
  }
  root = get_tree_from_file(argv[1]);
  pid = make_proc_tree(root);
  wait_for_ready_children(1);
  show_pstree(pid);
  kill(pid, SIGCONT);
  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)
jge    11d6 <main+0x46>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <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   1050 <make_proc_tree@plt>
mov    %eax,-0x14(%rbp)
mov    $0x1,%edi
call   1040 <wait_for_ready_children@plt>
mov    -0x14(%rbp),%edi
call   1080 <show_pstree@plt>
mov    -0x14(%rbp),%edi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1070 <kill@plt>
lea    -0x18(%rbp),%rdi
call   10a0 <wait@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
call   10b0 <explain_wait_status@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x1,%edi
jle    11eb <main+0x5b>
mov    0x8(%rsi),%rdi
call   1030 <get_tree_from_file@plt>
mov    %rax,%rdi
call   1050 <make_proc_tree@plt>
mov    %eax,%ebx
mov    $0x1,%edi
call   1040 <wait_for_ready_children@plt>
mov    %ebx,%edi
call   1080 <show_pstree@plt>
mov    0x2e23(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
call   1070 <kill@plt>
lea    0xc(%rsp),%rdi
call   10a0 <wait@plt>
mov    0xc(%rsp),%esi
mov    %eax,%edi
call   10b0 <explain_wait_status@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xe02(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@stderr = global i32 0
@.str = [54 x i8] c"Please, note the proper usage: %s <input_tree_file>\0A\0A\00"
@SIGCONT = global i32 0
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 slt 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 ([54 x i8], [54 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 @wait_for_ready_children(i32 1)
%26 = load i32, i32* %6
%27 = call i32 @show_pstree(i32 %26)
%28 = load i32, i32* %6
%29 = load i32, i32* @SIGCONT
%30 = call i32 @kill(i32 %28, i32 %29)
%31 = call i32 @wait(i32* %7)
store i32 %31, i32* %6
%32 = load i32, i32* %6
%33 = load i32, i32* %7
%34 = call i32 @explain_wait_status(i32 %32, i32 %33)
ret i32 0
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@stderr = global i32 0
@.str = [54 x i8] c"Please, note the proper usage: %s <input_tree_file>\0A\0A\00"
@SIGCONT = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([54 x i8], [54 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 @wait_for_ready_children(i32 1)
%17 = tail call i32 @show_pstree(i32 %15)
%18 = load i32, i32* @SIGCONT
%19 = tail call i32 @kill(i32 %15, i32 %18)
%20 = call i32 @wait(i32* %3)
%21 = load i32, i32* %3
%22 = call i32 @explain_wait_status(i32 %20, i32 %21)
ret i32 0
}