#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 min(int, int);
void build(int *a, int *tree, int start, int end, int treenode) {
  if (start == end) {
    tree[treenode] = a[start];
    return;
  }
  int mid;
  mid = (start + end) / 2;
  build(a, tree, start, mid, 2 * treenode);
  build(a, tree, mid + 1, end, 2 * treenode + 1);
  tree[treenode] = min(tree[2 * treenode], tree[2 * treenode + 1]);
  return;
}


x86 assembly (clang, -O0):
<build>:
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    %r8d,-0x1c(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
jne    1161 <build+0x41>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
jmp    11e4 <build+0xc4>
mov    -0x14(%rbp),%eax
add    -0x18(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
shl    $0x1,%r8d
call   1030 <build@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
mov    -0x18(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
shl    $0x1,%r8d
add    $0x1,%r8d
call   1030 <build@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%edi
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%esi
call   1040 <min@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%r14d
mov    %rsi,%r15
mov    %rdi,%r12
cmp    %ecx,%edx
jne    1141 <build+0x21>
movslq %edx,%rax
mov    (%r12,%rax,4),%eax
jmp    1197 <build+0x77>
mov    %ecx,%ebx
lea    (%rbx,%rdx,1),%eax
mov    %eax,%ebp
shr    $0x1f,%ebp
add    %eax,%ebp
sar    %ebp
lea    (%r14,%r14,1),%r8d
mov    %r8d,0x4(%rsp)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%ecx
call   1030 <build@plt>
add    $0x1,%ebp
lea    (%r14,%r14,1),%r13d
add    $0x1,%r13d
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
mov    %ebx,%ecx
mov    %r13d,%r8d
call   1030 <build@plt>
movslq 0x4(%rsp),%rax
mov    (%r15,%rax,4),%edi
movslq %r13d,%rax
mov    (%r15,%rax,4),%esi
call   1040 <min@plt>
movslq %r14d,%rcx
mov    %eax,(%r15,%rcx,4)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @build(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32* %0, i32** %6
store i32* %1, i32** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%12 = load i32, i32* %8
%13 = load i32, i32* %9
%14 = icmp eq i32 %12, %13
br i1 %14, label %15, label %25
15: ; preds = %5
%16 = load i32*, i32** %6
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = load i32*, i32** %7
%22 = load i32, i32* %10
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i32, i32* %21, i64 %23
store i32 %20, i32* %24
br label %62
25: ; preds = %5
%26 = load i32, i32* %8
%27 = load i32, i32* %9
%28 = add nsw i32 %26, %27
%29 = sdiv i32 %28, 2
store i32 %29, i32* %11
%30 = load i32*, i32** %6
%31 = load i32*, i32** %7
%32 = load i32, i32* %8
%33 = load i32, i32* %11
%34 = load i32, i32* %10
%35 = mul nsw i32 2, %34
%36 = load i32*, i32** %6
%37 = load i32*, i32** %7
%38 = load i32, i32* %11
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %9
%41 = load i32, i32* %10
%42 = mul nsw i32 2, %41
%43 = add nsw i32 %42, 1
%44 = load i32*, i32** %7
%45 = load i32, i32* %10
%46 = mul nsw i32 2, %45
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i32, i32* %44, i64 %47
%49 = load i32, i32* %48
%50 = load i32*, i32** %7
%51 = load i32, i32* %10
%52 = mul nsw i32 2, %51
%53 = add nsw i32 %52, 1
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i32, i32* %50, i64 %54
%56 = load i32, i32* %55
%57 = call i32 @min(i32 %49, i32 %56)
%58 = load i32*, i32** %7
%59 = load i32, i32* %10
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds i32, i32* %58, i64 %60
store i32 %57, i32* %61
br label %62
62: ; preds = %25, %15
ret void
}

LLVM IR (-O2):
define void @build(i32* %0, i32* %1, i32 %2, i32 %3, i32 %4) {
%6 = icmp eq i32 %2, %3
br i1 %6, label %7, label %15
7: ; preds = %5
%8 = sext i32 %2 to i64
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
br label %11
11: ; preds = %7, %15
%12 = phi i32 [ %10, %7 ], [ %27, %15 ]
%13 = sext i32 %4 to i64
%14 = getelementptr inbounds i32, i32* %1, i64 %13
store i32 %12, i32* %14
ret void
15: ; preds = %5
%16 = add nsw i32 %3, %2
%17 = sdiv i32 %16, 2
%18 = shl nsw i32 %4, 1
tail call void @build(i32* %0, i32* %1, i32 %2, i32 %17, i32 %18)
%19 = add nsw i32 %17, 1
%20 = or i32 %18, 1
tail call void @build(i32* %0, i32* %1, i32 %19, i32 %3, i32 %20)
%21 = sext i32 %18 to i64
%22 = getelementptr inbounds i32, i32* %1, i64 %21
%23 = load i32, i32* %22
%24 = sext i32 %20 to i64
%25 = getelementptr inbounds i32, i32* %1, i64 %24
%26 = load i32, i32* %25
%27 = tail call i32 @min(i32 %23, i32 %26)
br label %11
}