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

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ inorder(struct node *);
struct node *insert(struct node *, int);
int /*<<< orphan*/ postorder(struct node *);
int /*<<< orphan*/ preorder(struct node *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int choice, val;
  struct node *root = NULL;
  while (choice != 5) {
    printf("\nMenu --Binary search tree ");
    printf("\n 1. Insert\t 2. Preorder Traversal \t 3.Inorder Traversal "
           "\t4.Postorder traversal\n");
    scanf("%d", &choice);
    switch (choice) {
    case 1:
      printf("\nEnter the number to insert:");
      scanf("%d", &val);
      root = insert(root, val);
      printf("\tinserted successfully\n");
      break;
    case 2:
      printf("\npreorder:");
      preorder(root);
      break;
    case 4:
      printf("\n postorder:");
      postorder(root);
      break;
    case 3:
      printf("\n inorder:");
      inorder(root);
      break;
    case 5:
      exit(0);
    default:
      printf("\nEnter valid choice\n");
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     1285 <main+0x115>
lea    0xe7c(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
lea    0xed1(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x4,%eax
ja     1274 <main+0x104>
mov    -0x20(%rbp),%rax
lea    0xe27(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe9b(%rip),%rdi
call   1040 <printf@plt>
lea    0xe8c(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1080 <insert@plt>
mov    %rax,-0x18(%rbp)
lea    0xe8c(%rip),%rdi
call   1040 <printf@plt>
jmp    1280 <main+0x110>
lea    0xe93(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <preorder@plt>
jmp    1280 <main+0x110>
lea    0xe84(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <postorder@plt>
jmp    1280 <main+0x110>
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1060 <inorder@plt>
jmp    1280 <main+0x110>
xor    %edi,%edi
call   1090 <exit@plt>
lea    0xe61(%rip),%rdi
call   1040 <printf@plt>
jmp    1187 <main+0x17>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
xor    %ebx,%ebx
lea    0xe80(%rip),%r14
lea    0xed8(%rip),%r15
lea    0xe8e(%rip),%r12
mov    %rsp,%r13
lea    0xe54(%rip),%rbp
jmp    11c4 <main+0x44>
lea    0xf25(%rip),%rdi
call   1030 <puts@plt>
cmpl   $0x5,(%rsp)
je     1270 <main+0xf0>
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   1080 <scanf@plt>
mov    (%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x4,%eax
ja     11ae <main+0x2e>
movslq 0x0(%rbp,%rax,4),%rax
add    %rbp,%rax
jmp    *%rax
lea    0xe38(%rip),%rdi
call   1050 <printf@plt>
mov    %r12,%rdi
lea    0x4(%rsp),%rsi
call   1080 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
call   1090 <insert@plt>
mov    %rax,%rbx
lea    0xea0(%rip),%rdi
jmp    11b5 <main+0x35>
lea    0xe24(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1040 <preorder@plt>
jmp    11ba <main+0x3a>
lea    0xe23(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1070 <inorder@plt>
jmp    11ba <main+0x3a>
lea    0xdfd(%rip),%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <postorder@plt>
jmp    11ba <main+0x3a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [28 x i8] c"\0AMenu --Binary search tree \00"
@.str.1 = [81 x i8] c"\0A 1. Insert\09 2. Preorder Traversal \09 3.Inorder Traversal \094.Postorder traversal\0A\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [29 x i8] c"\0AEnter the number to insert:\00"
@.str.4 = [24 x i8] c"\09inserted successfully\0A\00"
@.str.5 = [11 x i8] c"\0Apreorder:\00"
@.str.6 = [13 x i8] c"\0A postorder:\00"
@.str.7 = [11 x i8] c"\0A inorder:\00"
@.str.8 = [21 x i8] c"\0AEnter valid choice\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.node*
store i32 0, i32* %1
store %struct.node* null, %struct.node** %4
br label %5
5: ; preds = %36, %0
%6 = load i32, i32* %2
%7 = icmp ne i32 %6, 5
br i1 %7, label %8, label %37
8: ; preds = %5
%9 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%12 = load i32, i32* %2
switch i32 %12, label %34 [
i32 1, label %13
i32 2, label %20
i32 4, label %24
i32 3, label %28
i32 5, label %32
]
13: ; preds = %8
%14 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %3)
%16 = load %struct.node*, %struct.node** %4
%17 = load i32, i32* %3
%18 = call %struct.node* @insert(%struct.node* %16, i32 %17)
store %struct.node* %18, %struct.node** %4
%19 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
br label %36
20: ; preds = %8
%21 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%22 = load %struct.node*, %struct.node** %4
%23 = call i32 @preorder(%struct.node* %22)
br label %36
24: ; preds = %8
%25 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%26 = load %struct.node*, %struct.node** %4
%27 = call i32 @postorder(%struct.node* %26)
br label %36
28: ; preds = %8
%29 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%30 = load %struct.node*, %struct.node** %4
%31 = call i32 @inorder(%struct.node* %30)
br label %36
32: ; preds = %8
%33 = call i32 @exit(i32 0)
unreachable
34: ; preds = %8
%35 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0))
br label %36
36: ; preds = %34, %28, %24, %20, %13
br label %5
37: ; preds = %5
%38 = load i32, i32* %1
ret i32 %38
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [28 x i8] c"\0AMenu --Binary search tree \00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [29 x i8] c"\0AEnter the number to insert:\00"
@.str.5 = [11 x i8] c"\0Apreorder:\00"
@.str.6 = [13 x i8] c"\0A postorder:\00"
@.str.7 = [11 x i8] c"\0A inorder:\00"
@str = [80 x i8] c"\0A 1. Insert\09 2. Preorder Traversal \09 3.Inorder Traversal \094.Postorder traversal\00"
@str.9 = [23 x i8] c"\09inserted successfully\00"
@str.10 = [20 x i8] c"\0AEnter valid choice\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %0, %30
%6 = phi %struct.node* [ %31, %30 ], [ null, %0 ]
%7 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([80 x i8], [80 x i8]* @str, i64 0, i64 0))
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%10 = load i32, i32* %1
switch i32 %10, label %28 [
i32 1, label %11
i32 2, label %17
i32 4, label %20
i32 3, label %23
i32 5, label %26
]
11: ; preds = %5
%12 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0))
%13 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%14 = load i32, i32* %2
%15 = call %struct.node* @insert(%struct.node* %6, i32 %14)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.9, i64 0, i64 0))
br label %30
17: ; preds = %5
%18 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @preorder(%struct.node* %6)
br label %30
20: ; preds = %5
%21 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%22 = call i32 @postorder(%struct.node* %6)
br label %30
23: ; preds = %5
%24 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0))
%25 = call i32 @inorder(%struct.node* %6)
br label %30
26: ; preds = %5
%27 = call i32 @exit(i32 0)
unreachable
28: ; preds = %5
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.10, i64 0, i64 0))
br label %30
30: ; preds = %28, %23, %20, %17, %11
%31 = phi %struct.node* [ %6, %28 ], [ %6, %23 ], [ %6, %20 ], [ %6, %17 ], [ %15, %11 ]
%32 = load i32, i32* %1
%33 = icmp eq i32 %32, 5
br i1 %33, label %34, label %5
34: ; preds = %30
ret i32 0
}