#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*/ numbers;

/* Variables and functions */
int /*<<< orphan*/ destroy_binary_tree(struct tree_node **);
struct tree_node *generate_binary_tree(int *, int);
int max_depth(struct tree_node *);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  struct tree_node *root;
  int size;
  int i;
  int numbers[] = {5, 8, 1, 9, 7, 2, 3};
  size = sizeof(numbers) / sizeof(int);
  printf("%d numbers:\n", size);
  for (i = 0; i < size; ++i)
    printf("%d ", numbers[i]);
  printf("\n\n");
  root = generate_binary_tree(numbers, size);
  printf("max depth is %d\n", max_depth(root));
  destroy_binary_tree(&root);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xeaa(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    0xea7(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    0xea4(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    0xea2(%rip),%eax
mov    %eax,-0x28(%rbp)
movl   $0x7,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xe92(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11c8 <main+0x88>
movslq -0x18(%rbp),%rax
mov    -0x40(%rbp,%rax,4),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1198 <main+0x58>
lea    0xe5e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <generate_binary_tree@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <max_depth@plt>
mov    %eax,%esi
lea    0xe38(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x10(%rbp),%rdi
call   1050 <destroy_binary_tree@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movups 0xeb0(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xe98(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xea8(%rip),%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xea2(%rip),%rbx
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
lea    0x10(%rsp),%rdi
mov    $0x7,%esi
call   1070 <generate_binary_tree@plt>
mov    %rax,0x8(%rsp)
mov    %rax,%rdi
call   1050 <max_depth@plt>
lea    0xe0e(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
call   1060 <destroy_binary_tree@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@__const.main.numbers = [7 x i32] [i32 5, i32 8, i32 1, i32 9, i32 7, i32 2, i32 3]
@.str = [13 x i8] c"%d numbers:\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.2 = [3 x i8] c"\0A\0A\00"
@.str.3 = [17 x i8] c"max depth is %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.tree_node*
%3 = alloca i32
%4 = alloca i32
%5 = alloca [7 x i32]
store i32 0, i32* %1
%6 = bitcast [7 x i32]* %5 to i8*
store i32 7, i32* %3
%7 = load i32, i32* %3
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 0, i32* %4
br label %9
9: ; preds = %19, %0
%10 = load i32, i32* %4
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = load i32, i32* %4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [7 x i32], [7 x i32]* %5, i64 0, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %13
%20 = load i32, i32* %4
%21 = add nsw i32 %20, 1
store i32 %21, i32* %4
br label %9
22: ; preds = %9
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = getelementptr inbounds [7 x i32], [7 x i32]* %5, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call %struct.tree_node* @generate_binary_tree(i32* %24, i32 %25)
store %struct.tree_node* %26, %struct.tree_node** %2
%27 = load %struct.tree_node*, %struct.tree_node** %2
%28 = call i32 @max_depth(%struct.tree_node* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %28)
%30 = call i32 @destroy_binary_tree(%struct.tree_node** %2)
ret i32 0
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@__const.main.numbers = [7 x i32] [i32 5, i32 8, i32 1, i32 9, i32 7, i32 2, i32 3]
@.str = [13 x i8] c"%d numbers:\0A\00"
@.str.1 = [4 x i8] c"%d \00"
@.str.3 = [17 x i8] c"max depth is %d\0A\00"
@str = [2 x i8] c"\0A\00"
define i32 @main() {
%1 = alloca %struct.tree_node*
%2 = alloca [7 x i32]
%3 = bitcast %struct.tree_node** %1 to i8*
%4 = bitcast [7 x i32]* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 7)
%6 = getelementptr inbounds [7 x i32], [7 x i32]* %2, i64 0, i64 0
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 5)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 8)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 1)
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 9)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 7)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 2)
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%15 = call %struct.tree_node* @generate_binary_tree(i32* %6, i32 7)
store %struct.tree_node* %15, %struct.tree_node** %1
%16 = call i32 @max_depth(%struct.tree_node* %15)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0), i32 %16)
%18 = call i32 @destroy_binary_tree(%struct.tree_node** %1)
ret i32 0
}