#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 calParentIndex(size_t);
int /*<<< orphan*/ siftDown(void *, int, size_t, size_t,
                            int (*)(void const *, void const *));
void buildHeap(void *base, size_t nitems, size_t memSize,
               int (*cmp)(const void *, const void *)) {
  int start = calParentIndex(nitems - 1);
  while (start >= 0) {
    siftDown(base, start, nitems - 1, memSize, cmp);
    start--;
  }
}


x86 assembly (clang, -O0):
<buildHeap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
sub    $0x1,%rdi
call   1040 <calParentIndex@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     117c <buildHeap+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x10(%rbp),%rdx
sub    $0x1,%rdx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
call   1030 <siftDown@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1148 <buildHeap+0x28>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildHeap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r12
add    $0xffffffffffffffff,%rbx
mov    %rbx,%rdi
call   1040 <calParentIndex@plt>
test   %eax,%eax
js     1168 <buildHeap+0x48>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %ebp,%esi
mov    %rbx,%rdx
mov    %r15,%rcx
mov    %r14,%r8
call   1030 <siftDown@plt>
add    $0xffffffff,%ebp
jb     1150 <buildHeap+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @buildHeap(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32 (i8*, i8*)*
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32 (i8*, i8*)* %3, i32 (i8*, i8*)** %8
%10 = load i64, i64* %6
%11 = sub i64 %10, 1
%12 = call i32 @calParentIndex(i64 %11)
store i32 %12, i32* %9
br label %13
13: ; preds = %16, %4
%14 = load i32, i32* %9
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = load i8*, i8** %5
%18 = load i32, i32* %9
%19 = load i64, i64* %6
%20 = sub i64 %19, 1
%21 = load i64, i64* %7
%22 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %8
%23 = call i32 @siftDown(i8* %17, i32 %18, i64 %20, i64 %21, i32 (i8*, i8*)* %22)
%24 = load i32, i32* %9
%25 = add nsw i32 %24, -1
store i32 %25, i32* %9
br label %13
26: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @buildHeap(i8* %0, i64 %1, i64 %2, i32 (i8*, i8*)* %3) {
%5 = add i64 %1, -1
%6 = tail call i32 @calParentIndex(i64 %5)
%7 = icmp sgt i32 %6, -1
br i1 %7, label %8, label %13
8: ; preds = %4, %8
%9 = phi i32 [ %11, %8 ], [ %6, %4 ]
%10 = tail call i32 @siftDown(i8* %0, i32 %9, i64 %5, i64 %2, i32 (i8*, i8*)* %3)
%11 = add nsw i32 %9, -1
%12 = icmp eq i32 %9, 0
br i1 %12, label %13, label %8
13: ; preds = %8, %4
ret void
}