#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 link {
  int dummy;
};

/* Variables and functions */
int atoi(char *);
int /*<<< orphan*/ destory_tree(struct link *);
int find_depth_most_left(struct link *, int /*<<< orphan*/, int, int);
int find_depth_most_right(struct link *, int /*<<< orphan*/, int, int);
int find_most_left(struct link *, int /*<<< orphan*/);
int find_most_left_val(struct link *, int);
int find_most_right(struct link *, int /*<<< orphan*/);
int find_most_right_val(struct link *, int);
int find_val_depth(struct link *, int, int);
struct link *init_tree(int);
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ show_tree_pic(struct link *);
int tree_depth(struct link *);
int /*<<< orphan*/ trim_the_tree(struct link *);
int main(int argc, char *argv[]) {
  int node_count = 10;
  struct link *r = NULL;
  int most_left;
  int most_right;
  int most_left_val;
  int most_right_val;
  int depth = 0;
  int most_left_of_depth = 0;
  int most_right_of_depth = 0;
  if (argc == 2 && atoi(argv[1]) > 0 && atoi(argv[1]) < 100) {
    node_count = atoi(argv[1]);
  }
  r = init_tree(node_count);
  depth = tree_depth(r);
  printf("tree depth is = %d\n", depth);
  most_left_of_depth = find_depth_most_left(r, 0, 1, depth);
  printf("depth(%d), the most left = %d\n", depth, most_left_of_depth);
  most_right_of_depth = find_depth_most_right(r, 0, 1, depth);
  printf("depth(%d), the most right = %d\n", depth, most_right_of_depth);
  trim_the_tree(r);
  most_left = find_most_left(r, 0);
  printf("the most left = %d\n", most_left);
  most_right = find_most_right(r, 0);
  printf("the most right = %d\n", most_right);
  most_left_val = find_most_left_val(r, most_left);
  printf("the most left val = %d\n", most_left_val);
  most_right_val = find_most_right_val(r, most_right);
  printf("the most right val = %d\n", most_right_val);
  depth = find_val_depth(r, 1, most_left_val);
  printf("value(%2d), depth(%d)\n", most_left_val, depth);
  depth = find_val_depth(r, 1, most_right_val);
  printf("value(%2d), depth(%d)\n", most_right_val, depth);
  show_tree_pic(r);
  destory_tree(r);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xa,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1260 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
cmp    $0x0,%eax
jle    1260 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
cmp    $0x64,%eax
jge    1260 <main+0x80>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10c0 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   10f0 <init_tree@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   10b0 <tree_depth@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    0xd7e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%edx
call   1100 <find_depth_most_left@plt>
mov    %eax,-0x38(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x38(%rbp),%edx
lea    0xd68(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x34(%rbp),%ecx
xor    %esi,%esi
mov    $0x1,%edx
call   1040 <find_depth_most_right@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x34(%rbp),%esi
mov    -0x3c(%rbp),%edx
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <trim_the_tree@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1090 <find_most_left@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%esi
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
xor    %esi,%esi
call   1050 <find_most_right@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%esi
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1060 <find_most_left_val@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
lea    0xd16(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%esi
call   10d0 <find_most_right_val@plt>
mov    %eax,-0x30(%rbp)
mov    -0x30(%rbp),%esi
lea    0xd0e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    $0x1,%esi
call   10a0 <find_val_depth@plt>
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xcff(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%edx
mov    $0x1,%esi
call   10a0 <find_val_depth@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%esi
mov    -0x34(%rbp),%edx
lea    0xcd7(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x20(%rbp),%rdi
call   10e0 <show_tree_pic@plt>
mov    -0x20(%rbp),%rdi
call   1080 <destory_tree@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%eax
mov    $0xa,%edi
cmp    $0x2,%eax
jne    120a <main+0x2a>
mov    0x8(%rsi),%rdi
call   10c0 <atoi@plt>
lea    -0x1(%rax),%ecx
cmp    $0x63,%ecx
mov    $0xa,%edi
cmovb  %eax,%edi
call   10f0 <init_tree@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   10b0 <tree_depth@plt>
mov    %eax,%ebp
lea    0xddd(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    %ebp,%ecx
call   1100 <find_depth_most_left@plt>
lea    0xdd0(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
mov    %ebp,%ecx
call   1040 <find_depth_most_right@plt>
lea    0xdcc(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1030 <trim_the_tree@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <find_most_left@plt>
mov    %eax,%ebp
lea    0xd92(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <find_most_right@plt>
mov    %eax,%r14d
lea    0xd94(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1060 <find_most_left_val@plt>
mov    %eax,%ebp
lea    0xd8d(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
call   10d0 <find_most_right_val@plt>
mov    %eax,%r14d
lea    0xd87(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
call   10a0 <find_val_depth@plt>
lea    0xd81(%rip),%r15
mov    %r15,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r14d,%edx
call   10a0 <find_val_depth@plt>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10e0 <show_tree_pic@plt>
mov    %rbx,%rdi
call   1080 <destory_tree@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.link = type { i32 }
@.str = [20 x i8] c"tree depth is = %d\0A\00"
@.str.1 = [31 x i8] c"depth(%d), the most left = %d\0A\00"
@.str.2 = [32 x i8] c"depth(%d), the most right = %d\0A\00"
@.str.3 = [20 x i8] c"the most left = %d\0A\00"
@.str.4 = [21 x i8] c"the most right = %d\0A\00"
@.str.5 = [24 x i8] c"the most left val = %d\0A\00"
@.str.6 = [25 x i8] c"the most right val = %d\0A\00"
@.str.7 = [23 x i8] c"value(%2d), depth(%d)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.link*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 10, i32* %6
store %struct.link* null, %struct.link** %7
store i32 0, i32* %12
store i32 0, i32* %13
store i32 0, i32* %14
%15 = load i32, i32* %4
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %34
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 @atoi(i8* %20)
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %34
23: ; preds = %17
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
%28 = icmp slt i32 %27, 100
br i1 %28, label %29, label %34
29: ; preds = %23
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 1
%32 = load i8*, i8** %31
%33 = call i32 @atoi(i8* %32)
store i32 %33, i32* %6
br label %34
34: ; preds = %29, %23, %17, %2
%35 = load i32, i32* %6
%36 = call %struct.link* @init_tree(i32 %35)
store %struct.link* %36, %struct.link** %7
%37 = load %struct.link*, %struct.link** %7
%38 = call i32 @tree_depth(%struct.link* %37)
store i32 %38, i32* %12
%39 = load i32, i32* %12
%40 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %39)
%41 = load %struct.link*, %struct.link** %7
%42 = load i32, i32* %12
%43 = call i32 @find_depth_most_left(%struct.link* %41, i32 0, i32 1, i32 %42)
store i32 %43, i32* %13
%44 = load i32, i32* %12
%45 = load i32, i32* %13
%46 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %44, i32 %45)
%47 = load %struct.link*, %struct.link** %7
%48 = load i32, i32* %12
%49 = call i32 @find_depth_most_right(%struct.link* %47, i32 0, i32 1, i32 %48)
store i32 %49, i32* %14
%50 = load i32, i32* %12
%51 = load i32, i32* %14
%52 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %50, i32 %51)
%53 = load %struct.link*, %struct.link** %7
%54 = call i32 @trim_the_tree(%struct.link* %53)
%55 = load %struct.link*, %struct.link** %7
%56 = call i32 @find_most_left(%struct.link* %55, i32 0)
store i32 %56, i32* %8
%57 = load i32, i32* %8
%58 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %57)
%59 = load %struct.link*, %struct.link** %7
%60 = call i32 @find_most_right(%struct.link* %59, i32 0)
store i32 %60, i32* %9
%61 = load i32, i32* %9
%62 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %61)
%63 = load %struct.link*, %struct.link** %7
%64 = load i32, i32* %8
%65 = call i32 @find_most_left_val(%struct.link* %63, i32 %64)
store i32 %65, i32* %10
%66 = load i32, i32* %10
%67 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %66)
%68 = load %struct.link*, %struct.link** %7
%69 = load i32, i32* %9
%70 = call i32 @find_most_right_val(%struct.link* %68, i32 %69)
store i32 %70, i32* %11
%71 = load i32, i32* %11
%72 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %71)
%73 = load %struct.link*, %struct.link** %7
%74 = load i32, i32* %10
%75 = call i32 @find_val_depth(%struct.link* %73, i32 1, i32 %74)
store i32 %75, i32* %12
%76 = load i32, i32* %10
%77 = load i32, i32* %12
%78 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %76, i32 %77)
%79 = load %struct.link*, %struct.link** %7
%80 = load i32, i32* %11
%81 = call i32 @find_val_depth(%struct.link* %79, i32 1, i32 %80)
store i32 %81, i32* %12
%82 = load i32, i32* %11
%83 = load i32, i32* %12
%84 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %82, i32 %83)
%85 = load %struct.link*, %struct.link** %7
%86 = call i32 @show_tree_pic(%struct.link* %85)
%87 = load %struct.link*, %struct.link** %7
%88 = call i32 @destory_tree(%struct.link* %87)
ret i32 0
}

LLVM IR (-O2):
%struct.link = type { i32 }
@.str = [20 x i8] c"tree depth is = %d\0A\00"
@.str.1 = [31 x i8] c"depth(%d), the most left = %d\0A\00"
@.str.2 = [32 x i8] c"depth(%d), the most right = %d\0A\00"
@.str.3 = [20 x i8] c"the most left = %d\0A\00"
@.str.4 = [21 x i8] c"the most right = %d\0A\00"
@.str.5 = [24 x i8] c"the most left val = %d\0A\00"
@.str.6 = [25 x i8] c"the most right val = %d\0A\00"
@.str.7 = [23 x i8] c"value(%2d), depth(%d)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %11
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @atoi(i8* %6)
%8 = add i32 %7, -1
%9 = icmp ult i32 %8, 99
%10 = select i1 %9, i32 %7, i32 10
br label %11
11: ; preds = %4, %2
%12 = phi i32 [ 10, %2 ], [ %10, %4 ]
%13 = tail call %struct.link* @init_tree(i32 %12)
%14 = tail call i32 @tree_depth(%struct.link* %13)
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %14)
%16 = tail call i32 @find_depth_most_left(%struct.link* %13, i32 0, i32 1, i32 %14)
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i32 %14, i32 %16)
%18 = tail call i32 @find_depth_most_right(%struct.link* %13, i32 0, i32 1, i32 %14)
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %18)
%20 = tail call i32 @trim_the_tree(%struct.link* %13)
%21 = tail call i32 @find_most_left(%struct.link* %13, i32 0)
%22 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %21)
%23 = tail call i32 @find_most_right(%struct.link* %13, i32 0)
%24 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = tail call i32 @find_most_left_val(%struct.link* %13, i32 %21)
%26 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %25)
%27 = tail call i32 @find_most_right_val(%struct.link* %13, i32 %23)
%28 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0), i32 %27)
%29 = tail call i32 @find_val_depth(%struct.link* %13, i32 1, i32 %25)
%30 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %25, i32 %29)
%31 = tail call i32 @find_val_depth(%struct.link* %13, i32 1, i32 %27)
%32 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i32 %27, i32 %31)
%33 = tail call i32 @show_tree_pic(%struct.link* %13)
%34 = tail call i32 @destory_tree(%struct.link* %13)
ret i32 0
}