#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*/ 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 n, elem;
  struct node *root = NULL;
  printf("Enter the number of elements to input:\n");
  scanf("%d", &n);
  printf("Enter the elements:\n");
  for (int i = 0; i < n; i++) {
    scanf("%d", &elem);
    root = insert(root, elem);
  }
  printf("\n");
  printf("Pre-order:\n");
  preOrder(root);
  printf("\n");
  printf("In-order:\n");
  inOrder(root);
  printf("\n");
  printf("Post-order:\n");
  postOrder(root);
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe82(%rip),%rdi
call   1030 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1060 <scanf@plt>
lea    0xe91(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11e0 <main+0x80>
lea    0xe6f(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1070 <insert@plt>
mov    %rax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a6 <main+0x46>
lea    0xe63(%rip),%rdi
call   1030 <printf@plt>
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <preOrder@plt>
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <inOrder@plt>
lea    0xe21(%rip),%rdi
call   1030 <printf@plt>
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <postOrder@plt>
lea    0xe00(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe84(%rip),%rdi
call   1040 <puts@plt>
lea    0xe75(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
lea    0xe90(%rip),%rdi
call   1040 <puts@plt>
xor    %ebx,%ebx
cmpl   $0x0,(%rsp)
jle    11e4 <main+0x74>
lea    0xe52(%rip),%r14
lea    0x4(%rsp),%r15
xor    %r12d,%r12d
cs nopw 0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%esi
mov    %r12,%rdi
call   1080 <insert@plt>
mov    %rax,%r12
add    $0x1,%ebx
cmp    (%rsp),%ebx
jl     11c0 <main+0x50>
jmp    11e7 <main+0x77>
xor    %r12d,%r12d
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe46(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1090 <preOrder@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe33(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1060 <inOrder@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xe1f(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1050 <postOrder@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [40 x i8] c"Enter the number of elements to input:\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [21 x i8] c"Enter the elements:\0A\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [12 x i8] c"Pre-order:\0A\00"
@.str.5 = [11 x i8] c"In-order:\0A\00"
@.str.6 = [13 x i8] c"Post-order:\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.node*
%5 = alloca i32
store i32 0, i32* %1
store %struct.node* null, %struct.node** %4
%6 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%8 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %9
9: ; preds = %18, %0
%10 = load i32, i32* %5
%11 = load i32, i32* %2
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%15 = load %struct.node*, %struct.node** %4
%16 = load i32, i32* %3
%17 = call %struct.node* @insert(%struct.node* %15, i32 %16)
store %struct.node* %17, %struct.node** %4
br label %18
18: ; preds = %13
%19 = load i32, i32* %5
%20 = add nsw i32 %19, 1
store i32 %20, i32* %5
br label %9
21: ; preds = %9
%22 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%23 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%24 = load %struct.node*, %struct.node** %4
%25 = call i32 @preOrder(%struct.node* %24)
%26 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%28 = load %struct.node*, %struct.node** %4
%29 = call i32 @inOrder(%struct.node* %28)
%30 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0))
%32 = load %struct.node*, %struct.node** %4
%33 = call i32 @postOrder(%struct.node* %32)
%34 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str.1 = [3 x i8] c"%d\00"
@str = [39 x i8] c"Enter the number of elements to input:\00"
@str.7 = [20 x i8] c"Enter the elements:\00"
@str.8 = [11 x i8] c"Pre-order:\00"
@str.9 = [10 x i8] c"In-order:\00"
@str.10 = [12 x i8] c"Post-order:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
%6 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %1)
%7 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.7, i64 0, i64 0))
%8 = load i32, i32* %1
%9 = icmp sgt i32 %8, 0
br i1 %9, label %22, label %10
10: ; preds = %22, %0
%11 = phi %struct.node* [ null, %0 ], [ %27, %22 ]
%12 = call i32 @putchar(i32 10)
%13 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str.8, i64 0, i64 0))
%14 = call i32 @preOrder(%struct.node* %11)
%15 = call i32 @putchar(i32 10)
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.9, i64 0, i64 0))
%17 = call i32 @inOrder(%struct.node* %11)
%18 = call i32 @putchar(i32 10)
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.10, i64 0, i64 0))
%20 = call i32 @postOrder(%struct.node* %11)
%21 = call i32 @putchar(i32 10)
ret i32 0
22: ; preds = %0, %22
%23 = phi i32 [ %28, %22 ], [ 0, %0 ]
%24 = phi %struct.node* [ %27, %22 ], [ null, %0 ]
%25 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%26 = load i32, i32* %2
%27 = call %struct.node* @insert(%struct.node* %24, i32 %26)
%28 = add nuw nsw i32 %23, 1
%29 = load i32, i32* %1
%30 = icmp slt i32 %28, %29
br i1 %30, label %22, label %10
}