#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*/ printf(char *, int);
int /*<<< orphan*/ tree_insert(struct node **, int);
void sorted_array_to_tree(struct node **leaf, int arr[], int start, int end) {
  if (end < start)
    return;
  int middle = (start + end) / 2;
  printf("%d: ", arr[middle]);
  tree_insert(leaf, arr[middle]);
  sorted_array_to_tree(leaf, arr, start, middle - 1);
  sorted_array_to_tree(leaf, arr, middle + 1, end);
}


x86 assembly (clang, -O0):
<sorted_array_to_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1157 <sorted_array_to_tree+0x27>
jmp    11bf <sorted_array_to_tree+0x8f>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe86(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <tree_insert@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
call   1030 <sorted_array_to_tree@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
call   1030 <sorted_array_to_tree@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorted_array_to_tree>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    %edx,%ecx
jl     11a0 <sorted_array_to_tree+0x70>
mov    %ecx,%r14d
mov    %edx,%ebx
mov    %rsi,%r12
mov    %rdi,%r15
lea    0xeaf(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%rbx,%r14,1),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rbp
mov    (%r12,%rbp,4),%esi
mov    %r13,%rdi
call   1040 <printf@plt>
mov    (%r12,%rbp,4),%esi
mov    %r15,%rdi
call   1050 <tree_insert@plt>
lea    -0x1(%rbp),%ecx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
call   1030 <sorted_array_to_tree@plt>
lea    0x1(%rbp),%ebx
cmp    %r14d,%ebp
jl     1160 <sorted_array_to_tree+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.node = type { i32 }
@.str = [5 x i8] c"%d: \00"
define void @sorted_array_to_tree(%struct.node** %0, i32* %1, i32 %2, i32 %3) {
%5 = alloca %struct.node**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.node** %0, %struct.node*** %5
store i32* %1, i32** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = load i32, i32* %7
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %14
13: ; preds = %4
br label %42
14: ; preds = %4
%15 = load i32, i32* %7
%16 = load i32, i32* %8
%17 = add nsw i32 %15, %16
%18 = sdiv i32 %17, 2
store i32 %18, i32* %9
%19 = load i32*, i32** %6
%20 = load i32, i32* %9
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %23)
%25 = load %struct.node**, %struct.node*** %5
%26 = load i32*, i32** %6
%27 = load i32, i32* %9
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i32, i32* %26, i64 %28
%30 = load i32, i32* %29
%31 = call i32 @tree_insert(%struct.node** %25, i32 %30)
%32 = load %struct.node**, %struct.node*** %5
%33 = load i32*, i32** %6
%34 = load i32, i32* %7
%35 = load i32, i32* %9
%36 = sub nsw i32 %35, 1
%37 = load %struct.node**, %struct.node*** %5
%38 = load i32*, i32** %6
%39 = load i32, i32* %9
%40 = add nsw i32 %39, 1
%41 = load i32, i32* %8
br label %42
42: ; preds = %14, %13
ret void
}

LLVM IR (-O2):
%struct.node = type { i32 }
@.str = [5 x i8] c"%d: \00"
define void @sorted_array_to_tree(%struct.node** %0, i32* %1, i32 %2, i32 %3) {
%5 = icmp slt i32 %3, %2
br i1 %5, label %19, label %6
6: ; preds = %4, %6
%7 = phi i32 [ %17, %6 ], [ %2, %4 ]
%8 = add nsw i32 %7, %3
%9 = sdiv i32 %8, 2
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i32, i32* %1, i64 %10
%12 = load i32, i32* %11
%13 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i32, i32* %11
%15 = tail call i32 @tree_insert(%struct.node** %0, i32 %14)
%16 = add nsw i32 %9, -1
tail call void @sorted_array_to_tree(%struct.node** %0, i32* %1, i32 %7, i32 %16)
%17 = add nsw i32 %9, 1
%18 = icmp slt i32 %9, %3
br i1 %18, label %6, label %19
19: ; preds = %6, %4
ret void
}