#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 */
struct DynArr {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ _adjustHeap(struct DynArr *, int, int);
int /*<<< orphan*/ printf(char *);
int sizeDynArr(struct DynArr *);
void buildHeap(struct DynArr *heap) {
  if (1)
    printf("+++++++++ Building Heap +++++++++\n");
  int max = sizeDynArr(heap);
  int i;
  for (i = max / 2 - 1; i >= 0; i--)
    _adjustHeap(heap, max, i);
}


x86 assembly (clang, -O0):
<buildHeap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xebd(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <sizeDynArr@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     118c <buildHeap+0x5c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1050 <_adjustHeap@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1165 <buildHeap+0x35>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buildHeap>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xec2(%rip),%rdi
call   1040 <puts@plt>
mov    %r14,%rdi
call   1030 <sizeDynArr@plt>
cmp    $0x2,%eax
jl     1175 <buildHeap+0x45>
mov    %eax,%ebp
mov    %eax,%ebx
shr    %ebx
add    $0x1,%ebx
nopl   0x0(%rax)
lea    -0x2(%rbx),%edx
mov    %r14,%rdi
mov    %ebp,%esi
call   1050 <_adjustHeap@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1160 <buildHeap+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.DynArr = type { i32 }
@.str = [35 x i8] c"+++++++++ Building Heap +++++++++\0A\00"
define void @buildHeap(%struct.DynArr* %0) {
%2 = alloca %struct.DynArr*
%3 = alloca i32
%4 = alloca i32
store %struct.DynArr* %0, %struct.DynArr** %2
%5 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0))
%6 = load %struct.DynArr*, %struct.DynArr** %2
%7 = call i32 @sizeDynArr(%struct.DynArr* %6)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = sdiv i32 %8, 2
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %4
br label %11
11: ; preds = %19, %1
%12 = load i32, i32* %4
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load %struct.DynArr*, %struct.DynArr** %2
%16 = load i32, i32* %3
%17 = load i32, i32* %4
%18 = call i32 @_adjustHeap(%struct.DynArr* %15, i32 %16, i32 %17)
br label %19
19: ; preds = %14
%20 = load i32, i32* %4
%21 = add nsw i32 %20, -1
store i32 %21, i32* %4
br label %11
22: ; preds = %11
ret void
}

LLVM IR (-O2):
%struct.DynArr = type { i32 }
@str = [34 x i8] c"+++++++++ Building Heap +++++++++\00"
define void @buildHeap(%struct.DynArr* %0) {
%2 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str, i64 0, i64 0))
%3 = tail call i32 @sizeDynArr(%struct.DynArr* %0)
%4 = icmp sgt i32 %3, 1
br i1 %4, label %5, label %12
5: ; preds = %1
%6 = lshr i32 %3, 1
br label %7
7: ; preds = %5, %7
%8 = phi i32 [ %9, %7 ], [ %6, %5 ]
%9 = add nsw i32 %8, -1
%10 = tail call i32 @_adjustHeap(%struct.DynArr* %0, i32 %3, i32 %9)
%11 = icmp ugt i32 %8, 1
br i1 %11, label %7, label %12
12: ; preds = %7, %1
ret void
}