#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 */
char HeapGetFirst(struct DynArr *);
int /*<<< orphan*/ HeapRemoveFirst(struct DynArr *);
int /*<<< orphan*/ _adjustHeap(struct DynArr *, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ buildHeap(struct DynArr *);
int /*<<< orphan*/ fillTestData(struct DynArr *);
struct DynArr *newDynArr(int);
int /*<<< orphan*/ printDynArr(struct DynArr *);
int /*<<< orphan*/ printf(char *, char);
scalar_t__ sizeDynArr(struct DynArr *);
int main() {
  char val;
  struct DynArr *heap;
  heap = newDynArr(24);
  fillTestData(heap);
  printDynArr(heap);
  buildHeap(heap);
  _adjustHeap(heap, sizeDynArr(heap) - 1, 0);
  printDynArr(heap);
  while (sizeDynArr(heap) > 0) {
    val = HeapGetFirst(heap);
    printf("======= removing least value %d =======\n", val);
    HeapRemoveFirst(heap);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x18,%edi
call   1090 <newDynArr@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1080 <fillTestData@plt>
mov    -0x10(%rbp),%rdi
call   1030 <printDynArr@plt>
mov    -0x10(%rbp),%rdi
call   10b0 <buildHeap@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sizeDynArr@plt>
mov    -0x18(%rbp),%rdi
mov    %rax,%rsi
sub    $0x1,%rsi
xor    %edx,%edx
call   1070 <_adjustHeap@plt>
mov    -0x10(%rbp),%rdi
call   1030 <printDynArr@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sizeDynArr@plt>
cmp    $0x0,%rax
jle    1231 <main+0xa1>
mov    -0x10(%rbp),%rdi
call   10a0 <HeapGetFirst@plt>
mov    %al,-0x5(%rbp)
lea    0xde6(%rip),%rdi
movsbl -0x5(%rbp),%esi
call   1060 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <HeapRemoveFirst@plt>
jmp    11f4 <main+0x64>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    $0x18,%edi
call   1090 <newDynArr@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1080 <fillTestData@plt>
mov    %rbx,%rdi
call   1030 <printDynArr@plt>
mov    %rbx,%rdi
call   10b0 <buildHeap@plt>
mov    %rbx,%rdi
call   1050 <sizeDynArr@plt>
lea    -0x1(%rax),%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1070 <_adjustHeap@plt>
mov    %rbx,%rdi
call   1030 <printDynArr@plt>
mov    %rbx,%rdi
call   1050 <sizeDynArr@plt>
test   %rax,%rax
jle    1218 <main+0x88>
lea    0xe15(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <HeapGetFirst@plt>
movsbl %al,%esi
mov    %r14,%rdi
call   1060 <printf@plt>
mov    %rbx,%rdi
call   1040 <HeapRemoveFirst@plt>
mov    %rbx,%rdi
call   1050 <sizeDynArr@plt>
test   %rax,%rax
jg     11f0 <main+0x60>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.DynArr = type { i32 }
@.str = [41 x i8] c"======= removing least value %d =======\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca %struct.DynArr*
store i32 0, i32* %1
%4 = call %struct.DynArr* @newDynArr(i32 24)
store %struct.DynArr* %4, %struct.DynArr** %3
%5 = load %struct.DynArr*, %struct.DynArr** %3
%6 = call i32 @fillTestData(%struct.DynArr* %5)
%7 = load %struct.DynArr*, %struct.DynArr** %3
%8 = call i32 @printDynArr(%struct.DynArr* %7)
%9 = load %struct.DynArr*, %struct.DynArr** %3
%10 = call i32 @buildHeap(%struct.DynArr* %9)
%11 = load %struct.DynArr*, %struct.DynArr** %3
%12 = load %struct.DynArr*, %struct.DynArr** %3
%13 = call i64 @sizeDynArr(%struct.DynArr* %12)
%14 = sub nsw i64 %13, 1
%15 = call i32 @_adjustHeap(%struct.DynArr* %11, i64 %14, i32 0)
%16 = load %struct.DynArr*, %struct.DynArr** %3
%17 = call i32 @printDynArr(%struct.DynArr* %16)
br label %18
18: ; preds = %22, %0
%19 = load %struct.DynArr*, %struct.DynArr** %3
%20 = call i64 @sizeDynArr(%struct.DynArr* %19)
%21 = icmp sgt i64 %20, 0
br i1 %21, label %22, label %29
22: ; preds = %18
%23 = load %struct.DynArr*, %struct.DynArr** %3
%24 = call signext i8 @HeapGetFirst(%struct.DynArr* %23)
store i8 %24, i8* %2
%25 = load i8, i8* %2
%26 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8 signext %25)
%27 = load %struct.DynArr*, %struct.DynArr** %3
%28 = call i32 @HeapRemoveFirst(%struct.DynArr* %27)
br label %18
29: ; preds = %18
ret i32 0
}

LLVM IR (-O2):
%struct.DynArr = type { i32 }
@.str = [41 x i8] c"======= removing least value %d =======\0A\00"
define i32 @main() {
%1 = tail call %struct.DynArr* @newDynArr(i32 24)
%2 = tail call i32 @fillTestData(%struct.DynArr* %1)
%3 = tail call i32 @printDynArr(%struct.DynArr* %1)
%4 = tail call i32 @buildHeap(%struct.DynArr* %1)
%5 = tail call i64 @sizeDynArr(%struct.DynArr* %1)
%6 = add nsw i64 %5, -1
%7 = tail call i32 @_adjustHeap(%struct.DynArr* %1, i64 %6, i32 0)
%8 = tail call i32 @printDynArr(%struct.DynArr* %1)
%9 = tail call i64 @sizeDynArr(%struct.DynArr* %1)
%10 = icmp sgt i64 %9, 0
br i1 %10, label %11, label %17
11: ; preds = %0, %11
%12 = tail call signext i8 @HeapGetFirst(%struct.DynArr* %1)
%13 = tail call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i8 signext %12)
%14 = tail call i32 @HeapRemoveFirst(%struct.DynArr* %1)
%15 = tail call i64 @sizeDynArr(%struct.DynArr* %1)
%16 = icmp sgt i64 %15, 0
br i1 %16, label %11, label %17
17: ; preds = %11, %0
ret i32 0
}