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

/* Variables and functions */
int /*<<< orphan*/ inorder(struct btreenode *);
int /*<<< orphan*/ insert(struct btreenode **, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
void main() {
  struct btreenode *bt;
  int number;
  printf("Enter number of elements in array: ");
  scanf("%d", &number);
  int arr[number];
  int i;
  printf("\nEnter space seperated elements\n");
  for (i = 0; i < number; i++)
    scanf("%d", &arr[i]);
  printf("\nArray entered is:\n");
  for (i = 0; i < number; i++)
    printf("%d\t", arr[i]);
  bt = NULL;
  printf("\n");
  for (i = 0; i < number; i++)
    insert(&bt, arr[i]);
  printf("After tree sort:\n");
  inorder(bt);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    0xeb1(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec7(%rip),%rdi
lea    -0xc(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d7 <main+0x97>
mov    -0x30(%rbp),%rsi
movslq -0x24(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe60(%rip),%rdi
call   1050 <scanf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11a2 <main+0x62>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    121f <main+0xdf>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ec <main+0xac>
movq   $0x0,-0x8(%rbp)
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    126a <main+0x12a>
mov    -0x30(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    -0x8(%rbp),%rdi
call   1060 <insert@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    123c <main+0xfc>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1040 <inorder@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
lea    0xe88(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe9e(%rip),%rdi
lea    -0x2c(%rbp),%rsi
call   1070 <scanf@plt>
mov    %rsp,%r15
mov    -0x2c(%rbp),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe7a(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    11ec <main+0x8c>
xor    %r13d,%r13d
lea    0xe5e(%rip),%r14
mov    %r12,%rbx
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <scanf@plt>
add    $0x1,%r13
movslq -0x2c(%rbp),%rax
add    $0x4,%rbx
cmp    %rax,%r13
jl     11d0 <main+0x70>
lea    0xe58(%rip),%rdi
call   1040 <puts@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    122b <main+0xcb>
lea    0xe22(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1210 <main+0xb0>
movq   $0x0,-0x38(%rbp)
mov    $0xa,%edi
call   1030 <putchar@plt>
cmpl   $0x0,-0x2c(%rbp)
jle    1269 <main+0x109>
xor    %ebx,%ebx
lea    -0x38(%rbp),%r14
nopl   0x0(%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
call   1080 <insert@plt>
add    $0x1,%rbx
movslq -0x2c(%rbp),%rax
cmp    %rax,%rbx
jl     1250 <main+0xf0>
lea    0xdee(%rip),%rdi
call   1040 <puts@plt>
mov    -0x38(%rbp),%rdi
call   1060 <inorder@plt>
mov    %r15,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.btreenode = type { i32 }
@.str = [36 x i8] c"Enter number of elements in array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [33 x i8] c"\0AEnter space seperated elements\0A\00"
@.str.3 = [20 x i8] c"\0AArray entered is:\0A\00"
@.str.4 = [4 x i8] c"%d\09\00"
@.str.5 = [2 x i8] c"\0A\00"
@.str.6 = [18 x i8] c"After tree sort:\0A\00"
define void @main() {
%1 = alloca %struct.btreenode*
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 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 = load i32, i32* %2
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i32, i64 %9
store i64 %9, i64* %4
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %5
br label %13
13: ; preds = %22, %0
%14 = load i32, i32* %5
%15 = load i32, i32* %2
%16 = icmp slt i32 %14, %15
br i1 %16, label %17, label %25
17: ; preds = %13
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %11, i64 %19
%21 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %20)
br label %22
22: ; preds = %17
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
store i32 %24, i32* %5
br label %13
25: ; preds = %13
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %5
br label %27
27: ; preds = %37, %25
%28 = load i32, i32* %5
%29 = load i32, i32* %2
%30 = icmp slt i32 %28, %29
br i1 %30, label %31, label %40
31: ; preds = %27
%32 = load i32, i32* %5
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %11, i64 %33
%35 = load i32, i32* %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %35)
br label %37
37: ; preds = %31
%38 = load i32, i32* %5
%39 = add nsw i32 %38, 1
store i32 %39, i32* %5
br label %27
40: ; preds = %27
store %struct.btreenode* null, %struct.btreenode** %1
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %5
br label %42
42: ; preds = %52, %40
%43 = load i32, i32* %5
%44 = load i32, i32* %2
%45 = icmp slt i32 %43, %44
br i1 %45, label %46, label %55
46: ; preds = %42
%47 = load i32, i32* %5
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i32, i32* %11, i64 %48
%50 = load i32, i32* %49
%51 = call i32 @insert(%struct.btreenode** %1, i32 %50)
br label %52
52: ; preds = %46
%53 = load i32, i32* %5
%54 = add nsw i32 %53, 1
store i32 %54, i32* %5
br label %42
55: ; preds = %42
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
%57 = load %struct.btreenode*, %struct.btreenode** %1
%58 = call i32 @inorder(%struct.btreenode* %57)
%59 = load i8*, i8** %3
ret void
}

LLVM IR (-O2):
%struct.btreenode = type { i32 }
@.str = [36 x i8] c"Enter number of elements in array: \00"
@.str.1 = [3 x i8] c"%d\00"
@.str.4 = [4 x i8] c"%d\09\00"
@str = [32 x i8] c"\0AEnter space seperated elements\00"
@str.7 = [19 x i8] c"\0AArray entered is:\00"
@str.8 = [17 x i8] c"After tree sort:\00"
define void @main() {
%1 = alloca %struct.btreenode*
%2 = alloca i32
%3 = bitcast %struct.btreenode** %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 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* %2)
%7 = load i32, i32* %2
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
%10 = alloca i32, i64 %8
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%12 = load i32, i32* %2
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %0, %14
%15 = phi i64 [ %18, %14 ], [ 0, %0 ]
%16 = getelementptr inbounds i32, i32* %10, i64 %15
%17 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %16)
%18 = add nuw nsw i64 %15, 1
%19 = load i32, i32* %2
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %14, label %22
22: ; preds = %14, %0
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.7, i64 0, i64 0))
%24 = load i32, i32* %2
%25 = icmp sgt i32 %24, 0
br i1 %25, label %26, label %35
26: ; preds = %22, %26
%27 = phi i64 [ %31, %26 ], [ 0, %22 ]
%28 = getelementptr inbounds i32, i32* %10, i64 %27
%29 = load i32, i32* %28
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %29)
%31 = add nuw nsw i64 %27, 1
%32 = load i32, i32* %2
%33 = sext i32 %32 to i64
%34 = icmp slt i64 %31, %33
br i1 %34, label %26, label %35
35: ; preds = %26, %22
store %struct.btreenode* null, %struct.btreenode** %1
%36 = call i32 @putchar(i32 10)
%37 = load i32, i32* %2
%38 = icmp sgt i32 %37, 0
br i1 %38, label %39, label %48
39: ; preds = %35, %39
%40 = phi i64 [ %44, %39 ], [ 0, %35 ]
%41 = getelementptr inbounds i32, i32* %10, i64 %40
%42 = load i32, i32* %41
%43 = call i32 @insert(%struct.btreenode** %1, i32 %42)
%44 = add nuw nsw i64 %40, 1
%45 = load i32, i32* %2
%46 = sext i32 %45 to i64
%47 = icmp slt i64 %44, %46
br i1 %47, label %39, label %48
48: ; preds = %39, %35
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.8, i64 0, i64 0))
%50 = load %struct.btreenode*, %struct.btreenode** %1
%51 = call i32 @inorder(%struct.btreenode* %50)
ret void
}