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

/* Variables and functions */
int /*<<< orphan*/ bst_add(struct bst **, int);
int bst_check_balanced_optimized(struct bst *);
int /*<<< orphan*/ bst_free(struct bst *);
int bst_height(struct bst *);
int /*<<< orphan*/ bst_in_order(struct bst *);
int /*<<< orphan*/ bst_level_order(struct bst *);
int /*<<< orphan*/ bst_post_order(struct bst *);
int /*<<< orphan*/ bst_pre_order(struct bst *);
int /*<<< orphan*/ printf(char *, ...);
int strtol(char const *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, const char *argv[]) {
  int N, n, i;
  struct bst *root;
  N = argc - 1;
  if (N < 1)
    return -1;
  root = NULL;
  argv++;
  for (i = 0; i < N; i++) {
    n = strtol(argv[i], NULL, 0);
    bst_add(&root, n);
  }
  printf("Height: %d\n", bst_height(root));
  printf("Balanced: %d\n", bst_check_balanced_optimized(root));
  bst_in_order(root);
  printf("----\n");
  bst_pre_order(root);
  printf("----\n");
  bst_post_order(root);
  printf("----\n");
  bst_level_order(root);
  printf("----\n");
  bst_free(root);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jge    11d5 <main+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ce <main+0x12e>
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
add    $0x8,%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1230 <main+0x90>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1060 <strtol@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   10c0 <bst_add@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11f0 <main+0x50>
mov    -0x28(%rbp),%rdi
call   10a0 <bst_height@plt>
mov    %eax,%esi
lea    0xdbe(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1090 <bst_check_balanced_optimized@plt>
mov    %eax,%esi
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <bst_in_order@plt>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1080 <bst_pre_order@plt>
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1070 <bst_post_order@plt>
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1050 <bst_level_order@plt>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x28(%rbp),%rdi
call   10b0 <bst_free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    $0xffffffff,%r14d
cmp    $0x2,%edi
jl     128a <main+0xda>
mov    %rsi,%r15
mov    %edi,%ebp
add    $0xffffffff,%ebp
movq   $0x0,(%rsp)
xor    %ebx,%ebx
mov    %rsp,%r14
nopl   0x0(%rax,%rax,1)
mov    0x8(%r15,%rbx,8),%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <strtol@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   10d0 <bst_add@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11e0 <main+0x30>
mov    (%rsp),%rdi
call   10b0 <bst_height@plt>
lea    0xdef(%rip),%rdi
xor    %r14d,%r14d
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rdi
call   10a0 <bst_check_balanced_optimized@plt>
lea    0xddf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    (%rsp),%rdi
call   1030 <bst_in_order@plt>
lea    0xdd4(%rip),%rbx
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
call   1090 <bst_pre_order@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
call   1080 <bst_post_order@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
call   1060 <bst_level_order@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
mov    (%rsp),%rdi
call   10c0 <bst_free@plt>
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.bst = type { i32 }
@.str = [12 x i8] c"Height: %d\0A\00"
@.str.1 = [14 x i8] c"Balanced: %d\0A\00"
@.str.2 = [6 x i8] c"----\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 i32
%9 = alloca %struct.bst*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %15
14: ; preds = %2
store i32 -1, i32* %3
br label %55
15: ; preds = %2
store %struct.bst* null, %struct.bst** %9
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
store i32 0, i32* %8
br label %18
18: ; preds = %31, %15
%19 = load i32, i32* %8
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i8**, i8*** %5
%24 = load i32, i32* %8
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8*, i8** %23, i64 %25
%27 = load i8*, i8** %26
%28 = call i32 @strtol(i8* %27, i32* null, i32 0)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = call i32 @bst_add(%struct.bst** %9, i32 %29)
br label %31
31: ; preds = %22
%32 = load i32, i32* %8
%33 = add nsw i32 %32, 1
store i32 %33, i32* %8
br label %18
34: ; preds = %18
%35 = load %struct.bst*, %struct.bst** %9
%36 = call i32 @bst_height(%struct.bst* %35)
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %36)
%38 = load %struct.bst*, %struct.bst** %9
%39 = call i32 @bst_check_balanced_optimized(%struct.bst* %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load %struct.bst*, %struct.bst** %9
%42 = call i32 @bst_in_order(%struct.bst* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%44 = load %struct.bst*, %struct.bst** %9
%45 = call i32 @bst_pre_order(%struct.bst* %44)
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%47 = load %struct.bst*, %struct.bst** %9
%48 = call i32 @bst_post_order(%struct.bst* %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%50 = load %struct.bst*, %struct.bst** %9
%51 = call i32 @bst_level_order(%struct.bst* %50)
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%53 = load %struct.bst*, %struct.bst** %9
%54 = call i32 @bst_free(%struct.bst* %53)
store i32 0, i32* %3
br label %55
55: ; preds = %34, %14
%56 = load i32, i32* %3
ret i32 %56
}

LLVM IR (-O2):
%struct.bst = type { i32 }
@.str = [12 x i8] c"Height: %d\0A\00"
@.str.1 = [14 x i8] c"Balanced: %d\0A\00"
@str.5 = [5 x i8] c"----\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.bst*
%4 = bitcast %struct.bst** %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %39, label %6
6: ; preds = %2
%7 = add i32 %0, -1
store %struct.bst* null, %struct.bst** %3
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = zext i32 %7 to i64
br label %10
10: ; preds = %6, %10
%11 = phi i64 [ 0, %6 ], [ %16, %10 ]
%12 = getelementptr inbounds i8*, i8** %8, i64 %11
%13 = load i8*, i8** %12
%14 = call i32 @strtol(i8* nocapture %13, i32* null, i32 0)
%15 = call i32 @bst_add(%struct.bst** %3, i32 %14)
%16 = add nuw nsw i64 %11, 1
%17 = icmp eq i64 %16, %9
br i1 %17, label %18, label %10
18: ; preds = %10
%19 = load %struct.bst*, %struct.bst** %3
%20 = call i32 @bst_height(%struct.bst* %19)
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %20)
%22 = load %struct.bst*, %struct.bst** %3
%23 = call i32 @bst_check_balanced_optimized(%struct.bst* %22)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = load %struct.bst*, %struct.bst** %3
%26 = call i32 @bst_in_order(%struct.bst* %25)
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
%28 = load %struct.bst*, %struct.bst** %3
%29 = call i32 @bst_pre_order(%struct.bst* %28)
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
%31 = load %struct.bst*, %struct.bst** %3
%32 = call i32 @bst_post_order(%struct.bst* %31)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
%34 = load %struct.bst*, %struct.bst** %3
%35 = call i32 @bst_level_order(%struct.bst* %34)
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.5, i64 0, i64 0))
%37 = load %struct.bst*, %struct.bst** %3
%38 = call i32 @bst_free(%struct.bst* %37)
br label %39
39: ; preds = %2, %18
%40 = phi i32 [ 0, %18 ], [ -1, %2 ]
ret i32 %40
}