#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*/ percolateDown(int *, int, int);
int /*<<< orphan*/ printData(int *, int);
int /*<<< orphan*/ printf(char *, int);
void buildHeap(int data[], int size) {
  int i;
  printf("%2c: ", 'i');
  printData(data, size);
  for (i = size / 2 - 1; i >= 0; i--) {
    percolateDown(data, size, i);
    printf("%2d: ", i);
    printData(data, size);
  }
}


x86 assembly (clang, -O0):
<buildHeap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    0xeba(%rip),%rdi
mov    $0x69,%esi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printData@plt>
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     11af <buildHeap+0x7f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <percolateDown@plt>
mov    -0x10(%rbp),%esi
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printData@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    116d <buildHeap+0x3d>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildHeap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r12d
mov    %rdi,%r14
lea    0xebb(%rip),%rdi
mov    $0x69,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <printData@plt>
cmp    $0x2,%r12d
jl     119d <buildHeap+0x6d>
mov    %r12d,%ebx
shr    %ebx
add    $0x1,%ebx
lea    0xe97(%rip),%r15
nop
lea    -0x2(%rbx),%ebp
mov    %r14,%rdi
mov    %r12d,%esi
mov    %ebp,%edx
call   1050 <percolateDown@plt>
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
mov    %r14,%rdi
mov    %r12d,%esi
call   1040 <printData@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1170 <buildHeap+0x40>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%2c: \00"
@.str.1 = [6 x i8] c"%2d: \00"
define void @buildHeap(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 105)
%7 = load i32*, i32** %3
%8 = load i32, i32* %4
%9 = call i32 @printData(i32* %7, i32 %8)
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 2
%12 = sub nsw i32 %11, 1
store i32 %12, i32* %5
br label %13
13: ; preds = %26, %2
%14 = load i32, i32* %5
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %29
16: ; preds = %13
%17 = load i32*, i32** %3
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = call i32 @percolateDown(i32* %17, i32 %18, i32 %19)
%21 = load i32, i32* %5
%22 = call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32*, i32** %3
%24 = load i32, i32* %4
%25 = call i32 @printData(i32* %23, i32 %24)
br label %26
26: ; preds = %16
%27 = load i32, i32* %5
%28 = add nsw i32 %27, -1
store i32 %28, i32* %5
br label %13
29: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [6 x i8] c"%2c: \00"
@.str.1 = [6 x i8] c"%2d: \00"
define void @buildHeap(i32* %0, i32 %1) {
%3 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 105)
%4 = tail call i32 @printData(i32* %0, i32 %1)
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %15
6: ; preds = %2
%7 = lshr i32 %1, 1
br label %8
8: ; preds = %6, %8
%9 = phi i32 [ %10, %8 ], [ %7, %6 ]
%10 = add nsw i32 %9, -1
%11 = tail call i32 @percolateDown(i32* %0, i32 %1, i32 %10)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%13 = tail call i32 @printData(i32* %0, i32 %1)
%14 = icmp ugt i32 %9, 1
br i1 %14, label %8, label %15
15: ; preds = %8, %2
ret void
}