#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*/ swap(int *, int *);
void build_heap_tree(int *array, int n) {
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      continue;
    } else {
      int parent = (i - 1) / 2;
      if (array[parent] < array[i]) {
        swap(&array[parent], &array[i]);
      }
    }
  }
}


x86 assembly (clang, -O0):
<build_heap_tree>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a9 <build_heap_tree+0x99>
cmpl   $0x0,-0x10(%rbp)
jne    1141 <build_heap_tree+0x31>
jmp    119b <build_heap_tree+0x8b>
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    -0x8(%rbp),%rcx
movslq -0x10(%rbp),%rdx
cmp    (%rcx,%rdx,4),%eax
jge    1191 <build_heap_tree+0x81>
mov    -0x8(%rbp),%rdi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
jmp    1196 <build_heap_tree+0x86>
jmp    119b <build_heap_tree+0x8b>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1126 <build_heap_tree+0x16>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_heap_tree>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1121 <build_heap_tree+0x11>
cmp    $0x1,%esi
jne    112d <build_heap_tree+0x1d>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    %rdi,%r14
mov    %esi,%r15d
lea    0x4(%rdi),%rbx
add    $0xffffffffffffffff,%r15
movabs $0x100000000,%r12
jmp    115e <build_heap_tree+0x4e>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r12
add    $0x4,%rbx
add    $0xffffffffffffffff,%r15
je     1121 <build_heap_tree+0x11>
mov    %r12d,%eax
and    $0xfffffffe,%eax
mov    (%r14,%rax,2),%ecx
cmp    (%rbx),%ecx
jge    1150 <build_heap_tree+0x40>
lea    (%r14,%rax,2),%rdi
mov    %rbx,%rsi
call   1030 <swap@plt>
jmp    1150 <build_heap_tree+0x40>

LLVM IR (-O0):
define void @build_heap_tree(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %42, %2
%8 = load i32, i32* %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %8, %9
br i1 %10, label %11, label %45
11: ; preds = %7
%12 = load i32, i32* %5
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
br label %42
15: ; preds = %11
%16 = load i32, i32* %5
%17 = sub nsw i32 %16, 1
%18 = sdiv i32 %17, 2
store i32 %18, i32* %6
%19 = load i32*, i32** %3
%20 = load i32, i32* %6
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
%24 = load i32*, i32** %3
%25 = load i32, i32* %5
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
%28 = load i32, i32* %27
%29 = icmp slt i32 %23, %28
br i1 %29, label %30, label %40
30: ; preds = %15
%31 = load i32*, i32** %3
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32*, i32** %3
%36 = load i32, i32* %5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i32, i32* %35, i64 %37
%39 = call i32 @swap(i32* %34, i32* %38)
br label %40
40: ; preds = %30, %15
br label %41
41: ; preds = %40
br label %42
42: ; preds = %41, %14
%43 = load i32, i32* %5
%44 = add nsw i32 %43, 1
store i32 %44, i32* %5
br label %7
45: ; preds = %7
ret void
}

LLVM IR (-O2):
define void @build_heap_tree(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = zext i32 %1 to i64
%6 = icmp eq i32 %1, 1
br i1 %6, label %7, label %8
7: ; preds = %20, %4, %2
ret void
8: ; preds = %4, %20
%9 = phi i64 [ %21, %20 ], [ 1, %4 ]
%10 = add nuw i64 %9, 4294967295
%11 = lshr i64 %10, 1
%12 = and i64 %11, 2147483647
%13 = getelementptr inbounds i32, i32* %0, i64 %12
%14 = load i32, i32* %13
%15 = getelementptr inbounds i32, i32* %0, i64 %9
%16 = load i32, i32* %15
%17 = icmp slt i32 %14, %16
br i1 %17, label %18, label %20
18: ; preds = %8
%19 = tail call i32 @swap(i32* %13, i32* %15)
br label %20
20: ; preds = %8, %18
%21 = add nuw nsw i64 %9, 1
%22 = icmp eq i64 %21, %5
br i1 %22, label %7, label %8
}