#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 */

/* Variables and functions */
int /*<<< orphan*/ delete (size_t, int *, size_t);
int /*<<< orphan*/ display(int *, size_t, int, int /*<<< orphan*/);
int /*<<< orphan*/ insert(int, size_t, int *, size_t);
int /*<<< orphan*/ puts(char *);
int *rand_array(size_t);
int /*<<< orphan*/ scanf(char *, ...);
size_t search(int, int *, size_t, int);
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int *tree(int *, size_t *);
int main() {
  size_t n;
  puts("Array length:");
  scanf("%zu", &n);
  srand(time(NULL));
  int *a = rand_array(n);
  a = tree(a, &n);
  display(a, n, 1, 0);
  int x;
  puts("Value to search for:");
  scanf("%d", &x);
  size_t i = search(x, a, n, 1);
  if (i)
    display(a, n, i, 0);
  else
    puts("Not found");
  puts("Value to insert:");
  scanf("%d", &x);
  puts("Leaf index to insert to:");
  scanf("%zu", &i);
  insert(x, i, a, n);
  display(a, n, 1, 0);
  puts("Node to be deleted:");
  scanf("%zu", &i);
  delete (i, a, n);
  display(a, n, 1, 0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
call   1030 <puts@plt>
lea    0xe4c(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    -0x10(%rbp),%rdi
call   1080 <rand_array@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x10(%rbp),%rsi
call   10b0 <tree@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
lea    0xdfc(%rip),%rdi
call   1030 <puts@plt>
lea    0xe05(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    $0x1,%ecx
call   1050 <search@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     126b <main+0xcb>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x28(%rbp),%rax
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
jmp    1277 <main+0xd7>
lea    0xdb8(%rip),%rdi
call   1030 <puts@plt>
lea    0xdb6(%rip),%rdi
call   1030 <puts@plt>
lea    0xd9d(%rip),%rdi
lea    -0x1c(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
lea    0xda9(%rip),%rdi
call   1030 <puts@plt>
lea    0xd66(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    -0x1c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x10(%rbp),%rcx
call   10a0 <insert@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
lea    0xd7c(%rip),%rdi
call   1030 <puts@plt>
lea    0xd20(%rip),%rdi
lea    -0x28(%rbp),%rsi
mov    $0x0,%al
call   1090 <scanf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rdx
call   10c0 <delete@plt>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
lea    0xe52(%rip),%rdi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
xor    %edi,%edi
call   1070 <time@plt>
mov    %eax,%edi
call   1060 <srand@plt>
mov    0x8(%rsp),%rdi
call   1080 <rand_array@plt>
mov    %rax,%rdi
mov    %rbx,%rsi
call   10b0 <tree@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%rsi
mov    %rax,%rdi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
lea    0xe06(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0f(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x14(%rsp),%edi
mov    0x8(%rsp),%rdx
mov    %rbx,%rsi
mov    $0x1,%ecx
call   1050 <search@plt>
mov    %rax,0x18(%rsp)
test   %rax,%rax
je     1257 <main+0xb7>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
jmp    1263 <main+0xc3>
lea    0xdcc(%rip),%rdi
call   1030 <puts@plt>
lea    0xdca(%rip),%rdi
call   1030 <puts@plt>
lea    0xdb1(%rip),%rdi
lea    0x14(%rsp),%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
lea    0xdbc(%rip),%rdi
call   1030 <puts@plt>
lea    0xd79(%rip),%r14
lea    0x18(%rsp),%r15
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x14(%rsp),%edi
mov    0x18(%rsp),%rsi
mov    0x8(%rsp),%rcx
mov    %rbx,%rdx
call   10a0 <insert@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
lea    0xd86(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1090 <scanf@plt>
mov    0x18(%rsp),%rdi
mov    0x8(%rsp),%rdx
mov    %rbx,%rsi
call   10c0 <delete@plt>
mov    0x8(%rsp),%rsi
mov    %rbx,%rdi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1040 <display@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Array length:\00"
@.str.1 = [4 x i8] c"%zu\00"
@.str.2 = [21 x i8] c"Value to search for:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [10 x i8] c"Not found\00"
@.str.5 = [17 x i8] c"Value to insert:\00"
@.str.6 = [25 x i8] c"Leaf index to insert to:\00"
@.str.7 = [20 x i8] c"Node to be deleted:\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %2)
%8 = call i32 @time(i32* null)
%9 = call i32 @srand(i32 %8)
%10 = load i64, i64* %2
%11 = call i32* @rand_array(i64 %10)
store i32* %11, i32** %3
%12 = load i32*, i32** %3
%13 = call i32* @tree(i32* %12, i64* %2)
store i32* %13, i32** %3
%14 = load i32*, i32** %3
%15 = load i64, i64* %2
%16 = call i32 @display(i32* %14, i64 %15, i32 1, i32 0)
%17 = call i32 @puts(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%19 = load i32, i32* %4
%20 = load i32*, i32** %3
%21 = load i64, i64* %2
%22 = call i64 @search(i32 %19, i32* %20, i64 %21, i32 1)
store i64 %22, i64* %5
%23 = load i64, i64* %5
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %0
%26 = load i32*, i32** %3
%27 = load i64, i64* %2
%28 = load i64, i64* %5
%29 = trunc i64 %28 to i32
%30 = call i32 @display(i32* %26, i64 %27, i32 %29, i32 0)
br label %33
31: ; preds = %0
%32 = call i32 @puts(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
%34 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%35 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%36 = call i32 @puts(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%37 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%38 = load i32, i32* %4
%39 = load i64, i64* %5
%40 = load i32*, i32** %3
%41 = load i64, i64* %2
%42 = call i32 @insert(i32 %38, i64 %39, i32* %40, i64 %41)
%43 = load i32*, i32** %3
%44 = load i64, i64* %2
%45 = call i32 @display(i32* %43, i64 %44, i32 1, i32 0)
%46 = call i32 @puts(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%47 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%48 = load i64, i64* %5
%49 = load i32*, i32** %3
%50 = load i64, i64* %2
%51 = call i32 @delete(i64 %48, i32* %49, i64 %50)
%52 = load i32*, i32** %3
%53 = load i64, i64* %2
%54 = call i32 @display(i32* %52, i64 %53, i32 1, i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [14 x i8] c"Array length:\00"
@.str.1 = [4 x i8] c"%zu\00"
@.str.2 = [21 x i8] c"Value to search for:\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [10 x i8] c"Not found\00"
@.str.5 = [17 x i8] c"Value to insert:\00"
@.str.6 = [25 x i8] c"Leaf index to insert to:\00"
@.str.7 = [20 x i8] c"Node to be deleted:\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i64
%4 = bitcast i64* %1 to i8*
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %1)
%7 = call i32 @time(i32* null)
%8 = call i32 @srand(i32 %7)
%9 = load i64, i64* %1
%10 = call i32* @rand_array(i64 %9)
%11 = call i32* @tree(i32* %10, i64* %1)
%12 = load i64, i64* %1
%13 = call i32 @display(i32* %11, i64 %12, i32 1, i32 0)
%14 = bitcast i32* %2 to i8*
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
%16 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%17 = bitcast i64* %3 to i8*
%18 = load i32, i32* %2
%19 = load i64, i64* %1
%20 = call i64 @search(i32 %18, i32* %11, i64 %19, i32 1)
store i64 %20, i64* %3
%21 = icmp eq i64 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %0
%23 = load i64, i64* %1
%24 = trunc i64 %20 to i32
%25 = call i32 @display(i32* %11, i64 %23, i32 %24, i32 0)
br label %28
26: ; preds = %0
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %28
28: ; preds = %26, %22
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%30 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @.str.6, i64 0, i64 0))
%32 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%33 = load i32, i32* %2
%34 = load i64, i64* %3
%35 = load i64, i64* %1
%36 = call i32 @insert(i32 %33, i64 %34, i32* %11, i64 %35)
%37 = load i64, i64* %1
%38 = call i32 @display(i32* %11, i64 %37, i32 1, i32 0)
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%41 = load i64, i64* %3
%42 = load i64, i64* %1
%43 = call i32 @delete(i64 %41, i32* %11, i64 %42)
%44 = load i64, i64* %1
%45 = call i32 @display(i32* %11, i64 %44, i32 1, i32 0)
ret i32 0
}