#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 tree_node {
  int dummy;
};
typedef int /*<<< orphan*/ numbers;

/* Variables and functions */
scalar_t__ delete_in_binary_tree(struct tree_node **, int);
int /*<<< orphan*/ destroy_binary_tree(struct tree_node **);
struct tree_node *generate_binary_tree(int *, int);
int /*<<< orphan*/ insert_into_binary_tree(struct tree_node **, int);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ search_in_binary_tree(struct tree_node *, int);
int /*<<< orphan*/ traverse_binary_tree(struct tree_node *);
int main(void) {
  int numbers[] = {5, 8, 1, 9, 7, 2, 3};
  int size = sizeof(numbers) / sizeof(numbers[0]);
  struct tree_node *root = generate_binary_tree(numbers, size);
  if (root == NULL)
    return 0;
  traverse_binary_tree(root);
  int target = 10;
  if (search_in_binary_tree(root, target))
    printf("Found target %d\n", target);
  else
    printf("Can out find target %d\n", target);
  if (!insert_into_binary_tree(&root, target)) {
    printf("Can not insert '%d'\n", target);
  }
  traverse_binary_tree(root);
  target = 5;
  if (delete_in_binary_tree(&root, target)) {
    printf("delete '%d'\n", target);
  }
  traverse_binary_tree(root);
  destroy_binary_tree(&root);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe7a(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0xe77(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    0xe74(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    0xe72(%rip),%eax
mov    %eax,-0x8(%rbp)
movl   $0x7,-0x24(%rbp)
lea    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1080 <generate_binary_tree@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d7 <main+0x67>
movl   $0x0,-0x4(%rbp)
jmp    1292 <main+0x122>
mov    -0x30(%rbp),%rdi
call   1050 <traverse_binary_tree@plt>
movl   $0xa,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1030 <search_in_binary_tree@plt>
cmp    $0x0,%rax
je     1211 <main+0xa1>
mov    -0x34(%rbp),%esi
lea    0xe15(%rip),%rdi
call   1040 <printf@plt>
jmp    1220 <main+0xb0>
mov    -0x34(%rbp),%esi
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    -0x34(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1060 <insert_into_binary_tree@plt>
cmp    $0x0,%eax
jne    1244 <main+0xd4>
mov    -0x34(%rbp),%esi
lea    0xe06(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <traverse_binary_tree@plt>
movl   $0x5,-0x34(%rbp)
mov    -0x34(%rbp),%esi
lea    -0x30(%rbp),%rdi
call   1090 <delete_in_binary_tree@plt>
cmp    $0x0,%rax
je     1279 <main+0x109>
mov    -0x34(%rbp),%esi
lea    0xde6(%rip),%rdi
call   1040 <printf@plt>
mov    -0x30(%rbp),%rdi
call   1050 <traverse_binary_tree@plt>
lea    -0x30(%rbp),%rdi
call   1070 <destroy_binary_tree@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
movups 0xe90(%rip),%xmm0
movups %xmm0,0x1c(%rsp)
movaps 0xe78(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rdi
mov    $0x7,%esi
call   1080 <generate_binary_tree@plt>
mov    %rax,0x8(%rsp)
test   %rax,%rax
je     1248 <main+0xd8>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <traverse_binary_tree@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <search_in_binary_tree@plt>
test   %rax,%rax
lea    0xe61(%rip),%rax
lea    0xe49(%rip),%rdi
cmove  %rax,%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
lea    0x8(%rsp),%rdi
mov    $0xa,%esi
call   1060 <insert_into_binary_tree@plt>
test   %eax,%eax
jne    1205 <main+0x95>
lea    0xe4a(%rip),%rdi
mov    $0xa,%esi
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1050 <traverse_binary_tree@plt>
lea    0x8(%rsp),%rdi
mov    $0x5,%esi
call   1090 <delete_in_binary_tree@plt>
test   %rax,%rax
je     1234 <main+0xc4>
lea    0xe30(%rip),%rdi
mov    $0x5,%esi
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1050 <traverse_binary_tree@plt>
lea    0x8(%rsp),%rdi
call   1070 <destroy_binary_tree@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.tree_node = type { i32 }
@__const.main.numbers = [7 x i32] [i32 5, i32 8, i32 1, i32 9, i32 7, i32 2, i32 3]
@.str = [17 x i8] c"Found target %d\0A\00"
@.str.1 = [24 x i8] c"Can out find target %d\0A\00"
@.str.2 = [21 x i8] c"Can not insert '%d'\0A\00"
@.str.3 = [13 x i8] c"delete '%d'\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [7 x i32]
%3 = alloca i32
%4 = alloca %struct.tree_node*
%5 = alloca i32
store i32 0, i32* %1
%6 = bitcast [7 x i32]* %2 to i8*
store i32 7, i32* %3
%7 = getelementptr inbounds [7 x i32], [7 x i32]* %2, i64 0, i64 0
%8 = load i32, i32* %3
%9 = call %struct.tree_node* @generate_binary_tree(i32* %7, i32 %8)
store %struct.tree_node* %9, %struct.tree_node** %4
%10 = load %struct.tree_node*, %struct.tree_node** %4
%11 = icmp eq %struct.tree_node* %10, null
br i1 %11, label %12, label %13
12: ; preds = %0
store i32 0, i32* %1
br label %46
13: ; preds = %0
%14 = load %struct.tree_node*, %struct.tree_node** %4
%15 = call i32 @traverse_binary_tree(%struct.tree_node* %14)
store i32 10, i32* %5
%16 = load %struct.tree_node*, %struct.tree_node** %4
%17 = load i32, i32* %5
%18 = call i64 @search_in_binary_tree(%struct.tree_node* %16, i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i32 %21)
br label %26
23: ; preds = %13
%24 = load i32, i32* %5
%25 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %24)
br label %26
26: ; preds = %23, %20
%27 = load i32, i32* %5
%28 = call i32 @insert_into_binary_tree(%struct.tree_node** %4, i32 %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %33, label %30
30: ; preds = %26
%31 = load i32, i32* %5
%32 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %31)
br label %33
33: ; preds = %30, %26
%34 = load %struct.tree_node*, %struct.tree_node** %4
%35 = call i32 @traverse_binary_tree(%struct.tree_node* %34)
store i32 5, i32* %5
%36 = load i32, i32* %5
%37 = call i64 @delete_in_binary_tree(%struct.tree_node** %4, i32 %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %42
39: ; preds = %33
%40 = load i32, i32* %5
%41 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %39, %33
%43 = load %struct.tree_node*, %struct.tree_node** %4
%44 = call i32 @traverse_binary_tree(%struct.tree_node* %43)
%45 = call i32 @destroy_binary_tree(%struct.tree_node** %4)
store i32 0, i32* %1
br label %46
46: ; preds = %42, %12
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
%struct.tree_node = type { i32 }
@__const.main.numbers = [7 x i32] [i32 5, i32 8, i32 1, i32 9, i32 7, i32 2, i32 3]
@.str = [17 x i8] c"Found target %d\0A\00"
@.str.1 = [24 x i8] c"Can out find target %d\0A\00"
@.str.2 = [21 x i8] c"Can not insert '%d'\0A\00"
@.str.3 = [13 x i8] c"delete '%d'\0A\00"
define i32 @main() {
%1 = alloca [7 x i32]
%2 = alloca %struct.tree_node*
%3 = bitcast [7 x i32]* %1 to i8*
%4 = bitcast %struct.tree_node** %2 to i8*
%5 = getelementptr inbounds [7 x i32], [7 x i32]* %1, i64 0, i64 0
%6 = call %struct.tree_node* @generate_binary_tree(i32* %5, i32 7)
store %struct.tree_node* %6, %struct.tree_node** %2
%7 = icmp eq %struct.tree_node* %6, null
br i1 %7, label %29, label %8
8: ; preds = %0
%9 = call i32 @traverse_binary_tree(%struct.tree_node* %6)
%10 = call i64 @search_in_binary_tree(%struct.tree_node* %6, i32 10)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0)
%13 = call i32 @printf(i8* %12, i32 10)
%14 = call i32 @insert_into_binary_tree(%struct.tree_node** %2, i32 10)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %8
%17 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 10)
br label %18
18: ; preds = %16, %8
%19 = load %struct.tree_node*, %struct.tree_node** %2
%20 = call i32 @traverse_binary_tree(%struct.tree_node* %19)
%21 = call i64 @delete_in_binary_tree(%struct.tree_node** %2, i32 5)
%22 = icmp eq i64 %21, 0
br i1 %22, label %25, label %23
23: ; preds = %18
%24 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0), i32 5)
br label %25
25: ; preds = %23, %18
%26 = load %struct.tree_node*, %struct.tree_node** %2
%27 = call i32 @traverse_binary_tree(%struct.tree_node* %26)
%28 = call i32 @destroy_binary_tree(%struct.tree_node** %2)
br label %29
29: ; preds = %0, %25
ret i32 0
}