#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 */
struct node *delete (struct node *, int);
int /*<<< orphan*/ deleteTree(struct node *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ inorder(struct node *);
struct node *insert(struct node *, int);
int /*<<< orphan*/ levelorder(struct node *);
int /*<<< orphan*/ postorder(struct node *);
int /*<<< orphan*/ preorder(struct node *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  int option = 0, value;
  struct node *root = NULL, *temp;
  do {
    printf("\n\n");
    printf("1. Preorder traversal\n");
    printf("2. Inorder traversal\n");
    printf("3. Postorder traversal\n");
    printf("4. Levelorder traversal\n");
    printf("5. Insert\n");
    printf("6. Delete\n");
    printf("7. Exit\n");
    printf("Enter option: ");
    scanf("%d", &option);
    printf("\n");
    switch (option) {
    case 1:
      if (root == NULL) {
        printf("Tree is empty!");
      } else {
        preorder(root);
      }
      break;
    case 2:
      if (root == NULL) {
        printf("Tree is empty!");
      } else {
        inorder(root);
      }
      break;
    case 3:
      if (root == NULL) {
        printf("Tree is empty!");
      } else {
        postorder(root);
      }
      break;
    case 4:
      if (root == NULL) {
        printf("Tree is empty!");
      } else {
        levelorder(root);
      }
      break;
    case 5:
      printf("Enter the value to add: ");
      scanf("%d", &value);
      root = insert(root, value);
      break;
    case 6:
      printf("Enter the value to delete: ");
      scanf("%d", &value);
      root = delete (root, value);
      break;
    case 7:
      exit(0);
      break;
    default:
      printf("Invalid option");
      break;
    }
  } while (option > 0);
  deleteTree(root);
  root = NULL;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xe5e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe55(%rip),%rdi
call   1050 <printf@plt>
lea    0xe60(%rip),%rdi
call   1050 <printf@plt>
lea    0xe6a(%rip),%rdi
call   1050 <printf@plt>
lea    0xe76(%rip),%rdi
call   1050 <printf@plt>
lea    0xe83(%rip),%rdi
call   1050 <printf@plt>
lea    0xe82(%rip),%rdi
call   1050 <printf@plt>
lea    0xe81(%rip),%rdi
call   1050 <printf@plt>
lea    0xe7e(%rip),%rdi
call   1050 <printf@plt>
lea    0xe81(%rip),%rdi
lea    -0x4(%rbp),%rsi
call   1090 <scanf@plt>
lea    0xde3(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x6,%eax
ja     1379 <main+0x1d9>
mov    -0x20(%rbp),%rax
lea    0xda1(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpq   $0x0,-0x10(%rbp)
jne    1284 <main+0xe4>
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
jmp    128d <main+0xed>
mov    -0x10(%rbp),%rdi
call   1030 <preorder@plt>
jmp    1385 <main+0x1e5>
cmpq   $0x0,-0x10(%rbp)
jne    12ae <main+0x10e>
lea    0xe0a(%rip),%rdi
call   1050 <printf@plt>
jmp    12b7 <main+0x117>
mov    -0x10(%rbp),%rdi
call   1080 <inorder@plt>
jmp    1385 <main+0x1e5>
cmpq   $0x0,-0x10(%rbp)
jne    12d8 <main+0x138>
lea    0xde0(%rip),%rdi
call   1050 <printf@plt>
jmp    12e1 <main+0x141>
mov    -0x10(%rbp),%rdi
call   1070 <postorder@plt>
jmp    1385 <main+0x1e5>
cmpq   $0x0,-0x10(%rbp)
jne    1302 <main+0x162>
lea    0xdb6(%rip),%rdi
call   1050 <printf@plt>
jmp    130b <main+0x16b>
mov    -0x10(%rbp),%rdi
call   1040 <levelorder@plt>
jmp    1385 <main+0x1e5>
lea    0xda6(%rip),%rdi
call   1050 <printf@plt>
lea    0xd88(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10a0 <insert@plt>
mov    %rax,-0x10(%rbp)
jmp    1385 <main+0x1e5>
lea    0xd8e(%rip),%rdi
call   1050 <printf@plt>
lea    0xd57(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1090 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   10b0 <delete@plt>
mov    %rax,-0x10(%rbp)
jmp    1385 <main+0x1e5>
xor    %edi,%edi
call   10c0 <exit@plt>
lea    0xd72(%rip),%rdi
call   1050 <printf@plt>
jmp    138a <main+0x1ea>
cmpl   $0x0,-0x4(%rbp)
jg     11b7 <main+0x17>
mov    -0x10(%rbp),%rdi
call   1060 <deleteTree@plt>
movq   $0x0,-0x10(%rbp)
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
movl   $0x0,0x4(%rsp)
xor    %ebp,%ebp
lea    0xf15(%rip),%r15
lea    0xe39(%rip),%r12
lea    0xe41(%rip),%r13
lea    0x4(%rsp),%rbx
lea    0xe0a(%rip),%r14
jmp    1219 <main+0x59>
nopl   0x0(%rax,%rax,1)
lea    0xe27(%rip),%rdi
call   1070 <printf@plt>
xor    %ebp,%ebp
cmpl   $0x0,0x4(%rsp)
jle    1364 <main+0x1a4>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
lea    0xe57(%rip),%rdi
call   1040 <puts@plt>
lea    0xe61(%rip),%rdi
call   1040 <puts@plt>
lea    0xe6a(%rip),%rdi
call   1040 <puts@plt>
lea    0xe75(%rip),%rdi
call   1040 <puts@plt>
lea    0xe81(%rip),%rdi
call   1040 <puts@plt>
lea    0xe7f(%rip),%rdi
call   1040 <puts@plt>
mov    %r15,%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10b0 <scanf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    0x4(%rsp),%eax
add    $0xffffffff,%eax
cmp    $0x6,%eax
ja     12bd <main+0xfd>
movslq (%r14,%rax,4),%rax
add    %r14,%rax
jmp    *%rax
test   %rbp,%rbp
je     1200 <main+0x40>
mov    %rbp,%rdi
call   1050 <preorder@plt>
jmp    120e <main+0x4e>
lea    0xdae(%rip),%rdi
call   1070 <printf@plt>
jmp    120e <main+0x4e>
test   %rbp,%rbp
je     1200 <main+0x40>
mov    %rbp,%rdi
call   10a0 <inorder@plt>
jmp    120e <main+0x4e>
test   %rbp,%rbp
je     1200 <main+0x40>
mov    %rbp,%rdi
call   1090 <postorder@plt>
jmp    120e <main+0x4e>
test   %rbp,%rbp
je     1200 <main+0x40>
mov    %rbp,%rdi
call   1060 <levelorder@plt>
jmp    120e <main+0x4e>
lea    0xd26(%rip),%rdi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rsp,%rsi
call   10b0 <scanf@plt>
mov    (%rsp),%esi
mov    %rbp,%rdi
call   10c0 <insert@plt>
mov    %rax,%rbp
jmp    120e <main+0x4e>
lea    0xd15(%rip),%rdi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rsp,%rsi
call   10b0 <scanf@plt>
mov    (%rsp),%esi
mov    %rbp,%rdi
call   10d0 <delete@plt>
mov    %rax,%rbp
jmp    120e <main+0x4e>
mov    %rbp,%rdi
call   1080 <deleteTree@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %edi,%edi
call   10e0 <exit@plt>

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [3 x i8] c"\0A\0A\00"
@.str.1 = [23 x i8] c"1. Preorder traversal\0A\00"
@.str.2 = [22 x i8] c"2. Inorder traversal\0A\00"
@.str.3 = [24 x i8] c"3. Postorder traversal\0A\00"
@.str.4 = [25 x i8] c"4. Levelorder traversal\0A\00"
@.str.5 = [11 x i8] c"5. Insert\0A\00"
@.str.6 = [11 x i8] c"6. Delete\0A\00"
@.str.7 = [9 x i8] c"7. Exit\0A\00"
@.str.8 = [15 x i8] c"Enter option: \00"
@.str.9 = [3 x i8] c"%d\00"
@.str.10 = [2 x i8] c"\0A\00"
@.str.11 = [15 x i8] c"Tree is empty!\00"
@.str.12 = [25 x i8] c"Enter the value to add: \00"
@.str.13 = [28 x i8] c"Enter the value to delete: \00"
@.str.14 = [15 x i8] c"Invalid option\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.node*
%4 = alloca %struct.node*
store i32 0, i32* %1
store %struct.node* null, %struct.node** %3
br label %5
5: ; preds = %71, %0
%6 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%8 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0))
%9 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.3, i64 0, i64 0))
%10 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%11 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%12 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0))
%14 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%15 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %1)
%16 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.10, i64 0, i64 0))
%17 = load i32, i32* %1
switch i32 %17, label %68 [
i32 1, label %18
i32 2, label %27
i32 3, label %36
i32 4, label %45
i32 5, label %54
i32 6, label %60
i32 7, label %66
]
18: ; preds = %5
%19 = load %struct.node*, %struct.node** %3
%20 = icmp eq %struct.node* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %26
23: ; preds = %18
%24 = load %struct.node*, %struct.node** %3
%25 = call i32 @preorder(%struct.node* %24)
br label %26
26: ; preds = %23, %21
br label %70
27: ; preds = %5
%28 = load %struct.node*, %struct.node** %3
%29 = icmp eq %struct.node* %28, null
br i1 %29, label %30, label %32
30: ; preds = %27
%31 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %35
32: ; preds = %27
%33 = load %struct.node*, %struct.node** %3
%34 = call i32 @inorder(%struct.node* %33)
br label %35
35: ; preds = %32, %30
br label %70
36: ; preds = %5
%37 = load %struct.node*, %struct.node** %3
%38 = icmp eq %struct.node* %37, null
br i1 %38, label %39, label %41
39: ; preds = %36
%40 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %44
41: ; preds = %36
%42 = load %struct.node*, %struct.node** %3
%43 = call i32 @postorder(%struct.node* %42)
br label %44
44: ; preds = %41, %39
br label %70
45: ; preds = %5
%46 = load %struct.node*, %struct.node** %3
%47 = icmp eq %struct.node* %46, null
br i1 %47, label %48, label %50
48: ; preds = %45
%49 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %53
50: ; preds = %45
%51 = load %struct.node*, %struct.node** %3
%52 = call i32 @levelorder(%struct.node* %51)
br label %53
53: ; preds = %50, %48
br label %70
54: ; preds = %5
%55 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
%56 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %2)
%57 = load %struct.node*, %struct.node** %3
%58 = load i32, i32* %2
%59 = call %struct.node* @insert(%struct.node* %57, i32 %58)
store %struct.node* %59, %struct.node** %3
br label %70
60: ; preds = %5
%61 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0))
%62 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %2)
%63 = load %struct.node*, %struct.node** %3
%64 = load i32, i32* %2
%65 = call %struct.node* @delete(%struct.node* %63, i32 %64)
store %struct.node* %65, %struct.node** %3
br label %70
66: ; preds = %5
%67 = call i32 @exit(i32 0)
unreachable
68: ; preds = %5
%69 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0))
br label %70
70: ; preds = %68, %60, %54, %53, %44, %35, %26
br label %71
71: ; preds = %70
%72 = load i32, i32* %1
%73 = icmp sgt i32 %72, 0
br i1 %73, label %5, label %74
74: ; preds = %71
%75 = load %struct.node*, %struct.node** %3
%76 = call i32 @deleteTree(%struct.node* %75)
store %struct.node* null, %struct.node** %3
ret void
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str.8 = [15 x i8] c"Enter option: \00"
@.str.9 = [3 x i8] c"%d\00"
@.str.11 = [15 x i8] c"Tree is empty!\00"
@.str.12 = [25 x i8] c"Enter the value to add: \00"
@.str.13 = [28 x i8] c"Enter the value to delete: \00"
@.str.14 = [15 x i8] c"Invalid option\00"
@str = [2 x i8] c"\0A\00"
@str.15 = [22 x i8] c"1. Preorder traversal\00"
@str.16 = [21 x i8] c"2. Inorder traversal\00"
@str.17 = [23 x i8] c"3. Postorder traversal\00"
@str.18 = [24 x i8] c"4. Levelorder traversal\00"
@str.19 = [10 x i8] c"5. Insert\00"
@str.20 = [10 x i8] c"6. Delete\00"
@str.21 = [8 x i8] c"7. Exit\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%4 = bitcast i32* %2 to i8*
br label %5
5: ; preds = %57, %0
%6 = phi %struct.node* [ null, %0 ], [ %58, %57 ]
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.15, i64 0, i64 0))
%9 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.16, i64 0, i64 0))
%10 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @str.17, i64 0, i64 0))
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.18, i64 0, i64 0))
%12 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.19, i64 0, i64 0))
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.20, i64 0, i64 0))
%14 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @str.21, i64 0, i64 0))
%15 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0))
%16 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %1)
%17 = call i32 @putchar(i32 10)
%18 = load i32, i32* %1
switch i32 %18, label %55 [
i32 1, label %19
i32 2, label %25
i32 3, label %31
i32 4, label %37
i32 5, label %43
i32 6, label %48
i32 7, label %53
]
19: ; preds = %5
%20 = icmp eq %struct.node* %6, null
br i1 %20, label %21, label %23
21: ; preds = %19
%22 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %57
23: ; preds = %19
%24 = call i32 @preorder(%struct.node* %6)
br label %57
25: ; preds = %5
%26 = icmp eq %struct.node* %6, null
br i1 %26, label %27, label %29
27: ; preds = %25
%28 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %57
29: ; preds = %25
%30 = call i32 @inorder(%struct.node* %6)
br label %57
31: ; preds = %5
%32 = icmp eq %struct.node* %6, null
br i1 %32, label %33, label %35
33: ; preds = %31
%34 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %57
35: ; preds = %31
%36 = call i32 @postorder(%struct.node* %6)
br label %57
37: ; preds = %5
%38 = icmp eq %struct.node* %6, null
br i1 %38, label %39, label %41
39: ; preds = %37
%40 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0))
br label %57
41: ; preds = %37
%42 = call i32 @levelorder(%struct.node* %6)
br label %57
43: ; preds = %5
%44 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.12, i64 0, i64 0))
%45 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %2)
%46 = load i32, i32* %2
%47 = call %struct.node* @insert(%struct.node* %6, i32 %46)
br label %57
48: ; preds = %5
%49 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0))
%50 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32* %2)
%51 = load i32, i32* %2
%52 = call %struct.node* @delete(%struct.node* %6, i32 %51)
br label %57
53: ; preds = %5
%54 = call i32 @exit(i32 0)
unreachable
55: ; preds = %5
%56 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.14, i64 0, i64 0))
br label %57
57: ; preds = %43, %48, %55, %23, %21, %29, %27, %35, %33, %41, %39
%58 = phi %struct.node* [ %6, %55 ], [ %52, %48 ], [ %47, %43 ], [ null, %39 ], [ %6, %41 ], [ null, %33 ], [ %6, %35 ], [ null, %27 ], [ %6, %29 ], [ null, %21 ], [ %6, %23 ]
%59 = load i32, i32* %1
%60 = icmp sgt i32 %59, 0
br i1 %60, label %5, label %61
61: ; preds = %57
%62 = call i32 @deleteTree(%struct.node* %58)
ret void
}