#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*/ siftdown(void *, size_t, int (*)(void const *, void const *),
                            int, int);
void heapify(void *base, size_t size,
             int (*compare)(const void *, const void *), int count) {
  int start = (count - 2) / 2;
  while (start >= 0) {
    siftdown(base, size, compare, start, count - 1);
    start--;
  }
}


x86 assembly (clang, -O0):
<heapify>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x20(%rbp)
jl     116c <heapify+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
sub    $0x1,%r8d
call   1030 <siftdown@plt>
mov    -0x20(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x20(%rbp)
jmp    1138 <heapify+0x28>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapify>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %ecx,%ecx
jle    1158 <heapify+0x48>
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
lea    -0x2(%rbx),%eax
shr    $0x1f,%eax
lea    (%rbx,%rax,1),%ebp
add    $0xfffffffe,%ebp
sar    %ebp
add    $0xffffffff,%ebx
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %ebx,%r8d
call   1030 <siftdown@plt>
add    $0xffffffff,%ebp
jb     1140 <heapify+0x30>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @heapify(i8* %0, i64 %1, i32 (i8*, i8*)* %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i32 (i8*, i8*)*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %5
store i64 %1, i64* %6
store i32 (i8*, i8*)* %2, i32 (i8*, i8*)** %7
store i32 %3, i32* %8
%10 = load i32, i32* %8
%11 = sub nsw i32 %10, 2
%12 = sdiv i32 %11, 2
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 i64, i64* %6
%19 = load i32 (i8*, i8*)*, i32 (i8*, i8*)** %7
%20 = load i32, i32* %9
%21 = load i32, i32* %8
%22 = sub nsw i32 %21, 1
%23 = call i32 @siftdown(i8* %17, i64 %18, i32 (i8*, i8*)* %19, i32 %20, i32 %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 @heapify(i8* %0, i64 %1, i32 (i8*, i8*)* %2, i32 %3) {
%5 = icmp sgt i32 %3, 0
br i1 %5, label %6, label %15
6: ; preds = %4
%7 = add nsw i32 %3, -2
%8 = sdiv i32 %7, 2
%9 = add nsw i32 %3, -1
br label %10
10: ; preds = %6, %10
%11 = phi i32 [ %8, %6 ], [ %13, %10 ]
%12 = tail call i32 @siftdown(i8* %0, i64 %1, i32 (i8*, i8*)* %2, i32 %11, i32 %9)
%13 = add nsw i32 %11, -1
%14 = icmp eq i32 %11, 0
br i1 %14, label %15, label %10
15: ; preds = %10, %4
ret void
}