#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 TreeNode {
  int dummy;
};
typedef int /*<<< orphan*/ arr;

/* Variables and functions */
struct TreeNode *create_minimal_bst(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ inorder_nonrecursive(struct TreeNode *);
int /*<<< orphan*/ insert(struct TreeNode **, int);
int /*<<< orphan*/ level_wise_display(struct TreeNode *);
int menu();
int /*<<< orphan*/ postorder_two_stacks(struct TreeNode *);
int /*<<< orphan*/ preorder_nonrecursive(struct TreeNode *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main(int argc, char *argv[]) {
  int choice;
  int n;
  int p;
  struct TreeNode *root = NULL;
  int arr[] = {1, 2, 3, 4, 5, 6, 7, 9, 15, 23};
  root = create_minimal_bst(arr, 0, (sizeof(arr) / sizeof(arr[0])) - 1);
  ;
  while (1) {
    choice = menu();
    switch (choice) {
    case 0:
      return 0;
    case 1:
      printf("Enter number: ");
      scanf("%d", &n);
      insert(&root, n);
      break;
    case 2:
      preorder_nonrecursive(root);
      break;
    case 3:
      inorder_nonrecursive(root);
      break;
    case 4:
      level_wise_display(root);
      break;
    case 5:
      postorder_two_stacks(root);
      break;
    default:
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
lea    -0x50(%rbp),%rdi
lea    0xe57(%rip),%rsi
mov    $0x28,%edx
call   1070 <memcpy@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1090 <create_minimal_bst@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
call   1040 <menu@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %rax,-0x58(%rbp)
sub    $0x5,%rax
ja     1287 <main+0xe7>
mov    -0x58(%rbp),%rax
lea    0xdf3(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x0,-0x4(%rbp)
jmp    1298 <main+0xf8>
lea    0xe1f(%rip),%rdi
call   1060 <printf@plt>
lea    0xe22(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   10b0 <scanf@plt>
mov    -0x18(%rbp),%esi
lea    -0x28(%rbp),%rdi
call   10c0 <insert@plt>
jmp    1293 <main+0xf3>
mov    -0x28(%rbp),%rdi
call   1030 <preorder_nonrecursive@plt>
jmp    1293 <main+0xf3>
mov    -0x28(%rbp),%rdi
call   1080 <inorder_nonrecursive@plt>
jmp    1293 <main+0xf3>
mov    -0x28(%rbp),%rdi
call   10a0 <level_wise_display@plt>
jmp    1293 <main+0xf3>
mov    -0x28(%rbp),%rdi
call   1050 <postorder_two_stacks@plt>
jmp    1293 <main+0xf3>
movl   $0x0,-0x4(%rbp)
jmp    1298 <main+0xf8>
jmp    11e7 <main+0x47>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x40,%rsp
mov    0xe9c(%rip),%rax
mov    %rax,0x30(%rsp)
movaps 0xe80(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movaps 0xe64(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1080 <create_minimal_bst@plt>
mov    %rax,(%rsp)
lea    0xe23(%rip),%rbx
lea    0xe64(%rip),%r14
lea    0xe6c(%rip),%r15
lea    0xc(%rsp),%r12
mov    %rsp,%r13
jmp    1200 <main+0x70>
mov    (%rsp),%rdi
call   1090 <level_wise_display@plt>
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <menu@plt>
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     125a <main+0xca>
movslq (%rbx,%rax,4),%rax
add    %rbx,%rax
jmp    *%rax
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   10a0 <scanf@plt>
mov    0xc(%rsp),%esi
mov    %r13,%rdi
call   10b0 <insert@plt>
jmp    1200 <main+0x70>
mov    (%rsp),%rdi
call   1030 <preorder_nonrecursive@plt>
jmp    1200 <main+0x70>
mov    (%rsp),%rdi
call   1070 <inorder_nonrecursive@plt>
jmp    1200 <main+0x70>
mov    (%rsp),%rdi
call   1050 <postorder_two_stacks@plt>
jmp    1200 <main+0x70>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.TreeNode = type { i32 }
@__const.main.arr = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 9, i32 15, i32 23]
@.str = [15 x i8] c"Enter number: \00"
@.str.1 = [3 x i8] c"%d\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.TreeNode*
%10 = alloca [10 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store %struct.TreeNode* null, %struct.TreeNode** %9
%11 = bitcast [10 x i32]* %10 to i8*
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %10, i64 0, i64 0
%13 = call %struct.TreeNode* @create_minimal_bst(i32* %12, i32 0, i32 9)
store %struct.TreeNode* %13, %struct.TreeNode** %9
br label %14
14: ; preds = %2, %36
%15 = call i32 (...) @menu()
store i32 %15, i32* %6
%16 = load i32, i32* %6
switch i32 %16, label %35 [
i32 0, label %17
i32 1, label %18
i32 2, label %23
i32 3, label %26
i32 4, label %29
i32 5, label %32
]
17: ; preds = %14
store i32 0, i32* %3
br label %37
18: ; preds = %14
%19 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %7)
%21 = load i32, i32* %7
%22 = call i32 @insert(%struct.TreeNode** %9, i32 %21)
br label %36
23: ; preds = %14
%24 = load %struct.TreeNode*, %struct.TreeNode** %9
%25 = call i32 @preorder_nonrecursive(%struct.TreeNode* %24)
br label %36
26: ; preds = %14
%27 = load %struct.TreeNode*, %struct.TreeNode** %9
%28 = call i32 @inorder_nonrecursive(%struct.TreeNode* %27)
br label %36
29: ; preds = %14
%30 = load %struct.TreeNode*, %struct.TreeNode** %9
%31 = call i32 @level_wise_display(%struct.TreeNode* %30)
br label %36
32: ; preds = %14
%33 = load %struct.TreeNode*, %struct.TreeNode** %9
%34 = call i32 @postorder_two_stacks(%struct.TreeNode* %33)
br label %36
35: ; preds = %14
store i32 0, i32* %3
br label %37
36: ; preds = %32, %29, %26, %23, %18
br label %14
37: ; preds = %35, %17
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
%struct.TreeNode = type { i32 }
@__const.main.arr = [10 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 9, i32 15, i32 23]
@.str = [15 x i8] c"Enter number: \00"
@.str.1 = [3 x i8] c"%d\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca %struct.TreeNode*
%5 = alloca [10 x i32]
%6 = bitcast i32* %3 to i8*
%7 = bitcast %struct.TreeNode** %4 to i8*
%8 = bitcast [10 x i32]* %5 to i8*
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %5, i64 0, i64 0
%10 = call %struct.TreeNode* @create_minimal_bst(i32* %9, i32 0, i32 9)
store %struct.TreeNode* %10, %struct.TreeNode** %4
br label %11
11: ; preds = %30, %2
%12 = call i32 (...) @menu()
switch i32 %12, label %31 [
i32 5, label %27
i32 1, label %13
i32 2, label %18
i32 3, label %21
i32 4, label %24
]
13: ; preds = %11
%14 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%16 = load i32, i32* %3
%17 = call i32 @insert(%struct.TreeNode** %4, i32 %16)
br label %30
18: ; preds = %11
%19 = load %struct.TreeNode*, %struct.TreeNode** %4
%20 = call i32 @preorder_nonrecursive(%struct.TreeNode* %19)
br label %30
21: ; preds = %11
%22 = load %struct.TreeNode*, %struct.TreeNode** %4
%23 = call i32 @inorder_nonrecursive(%struct.TreeNode* %22)
br label %30
24: ; preds = %11
%25 = load %struct.TreeNode*, %struct.TreeNode** %4
%26 = call i32 @level_wise_display(%struct.TreeNode* %25)
br label %30
27: ; preds = %11
%28 = load %struct.TreeNode*, %struct.TreeNode** %4
%29 = call i32 @postorder_two_stacks(%struct.TreeNode* %28)
br label %30
30: ; preds = %27, %24, %21, %18, %13
br label %11
31: ; preds = %11
ret i32 0
}