#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 getDynArr(struct DynArr *, int);
int indexSmallest(struct DynArr *, int, int);
int /*<<< orphan*/ printf(char *, int, int, ...);
int /*<<< orphan*/ swapDynArr(struct DynArr *, int, int);
void _adjustHeap(struct DynArr *heap, int maxInd, int currInd) {
  int leftChildInd = 2 * currInd + 1;
  int rghtChildInd = 2 * currInd + 2;
  int _minChildInd;
  if (1)
    printf("_adjust heap maxInd = %d, currInd = %d\n", maxInd, currInd);
  if (rghtChildInd < maxInd) {
    _minChildInd = indexSmallest(heap, leftChildInd, rghtChildInd);
    if (1)
      printf("\tComparing %d and %d; smallest is %d [index %d]\n",
             getDynArr(heap, leftChildInd), getDynArr(heap, rghtChildInd),
             getDynArr(heap, _minChildInd), _minChildInd);
    if (getDynArr(heap, currInd) > getDynArr(heap, _minChildInd)) {
      if (1)
        printf("\t\tSwapping values %d and %d [index %d / %d]\n",
               getDynArr(heap, currInd), getDynArr(heap, _minChildInd), currInd,
               _minChildInd);
      swapDynArr(heap, currInd, _minChildInd);
      _adjustHeap(heap, maxInd, _minChildInd);
    }
  } else if (leftChildInd < maxInd) {
    if (1)
      printf("Comparing %d and %d\n", getDynArr(heap, leftChildInd),
             getDynArr(heap, currInd));
    if (getDynArr(heap, currInd) > getDynArr(heap, leftChildInd))
      swapDynArr(heap, currInd, leftChildInd);
    _adjustHeap(heap, maxInd, leftChildInd);
  }
  return;
}


x86 assembly (clang, -O0):
<_adjustHeap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%eax
shl    $0x1,%eax
add    $0x2,%eax
mov    %eax,-0x18(%rbp)
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1270 <_adjustHeap+0x120>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <indexSmallest@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <getDynArr@plt>
mov    -0x28(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    %eax,%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe3f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%eax
cmp    %ecx,%eax
jle    126b <_adjustHeap+0x11b>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <getDynArr@plt>
mov    -0x2c(%rbp),%esi
mov    %eax,%edx
mov    -0x10(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
lea    0xe13(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <swapDynArr@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1040 <_adjustHeap@plt>
jmp    12f5 <_adjustHeap+0x1a5>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    12f0 <_adjustHeap+0x1a0>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <getDynArr@plt>
mov    -0x34(%rbp),%esi
mov    %eax,%edx
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1060 <getDynArr@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%eax
cmp    %ecx,%eax
jle    12e1 <_adjustHeap+0x191>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1070 <swapDynArr@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <_adjustHeap@plt>
jmp    12f5 <_adjustHeap+0x1a5>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_adjustHeap>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r13d
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %esi,0x4(%rsp)
jmp    116e <_adjustHeap+0x2e>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r12d,%esi
mov    %r13d,%edx
call   1060 <swapDynArr@plt>
mov    %r13d,%r12d
lea    (%r12,%r12,1),%r13d
add    $0x1,%r13d
lea    0x2(%r12,%r12,1),%r14d
lea    0xe7b(%rip),%rdi
mov    %ebp,%esi
mov    %r12d,%edx
xor    %eax,%eax
call   1030 <printf@plt>
cmp    %ebp,%r14d
jge    1250 <_adjustHeap+0x110>
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r14d,%edx
call   1040 <indexSmallest@plt>
mov    %eax,%r15d
mov    %rbx,%rdi
mov    %r13d,%esi
call   1050 <getDynArr@plt>
mov    %eax,%r13d
mov    %rbx,%rdi
mov    %r14d,%esi
call   1050 <getDynArr@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <getDynArr@plt>
lea    0xe50(%rip),%rdi
mov    %r13d,%esi
mov    %ebp,%edx
mov    %eax,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <getDynArr@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <getDynArr@plt>
cmp    %eax,%ebp
jle    12a8 <_adjustHeap+0x168>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <getDynArr@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r15d,%esi
call   1050 <getDynArr@plt>
lea    0xe31(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
mov    %r12d,%ecx
mov    %r15d,%r8d
xor    %eax,%eax
call   1030 <printf@plt>
mov    %r15d,%r13d
mov    0x4(%rsp),%ebp
jmp    1160 <_adjustHeap+0x20>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    %ebp,%r13d
jge    12a8 <_adjustHeap+0x168>
mov    %rbx,%rdi
mov    %r13d,%esi
call   1050 <getDynArr@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <getDynArr@plt>
lea    0xe12(%rip),%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    %r12d,%esi
call   1050 <getDynArr@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r13d,%esi
call   1050 <getDynArr@plt>
cmp    %eax,%ebp
mov    0x4(%rsp),%ebp
jle    116e <_adjustHeap+0x2e>
jmp    1160 <_adjustHeap+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.DynArr = type { i32 }
@.str = [40 x i8] c"_adjust heap maxInd = %d, currInd = %d\0A\00"
@.str.1 = [49 x i8] c"\09Comparing %d and %d; smallest is %d [index %d]\0A\00"
@.str.2 = [45 x i8] c"\09\09Swapping values %d and %d [index %d / %d]\0A\00"
@.str.3 = [21 x i8] c"Comparing %d and %d\0A\00"
define void @_adjustHeap(%struct.DynArr* %0, i32 %1, i32 %2) {
%4 = alloca %struct.DynArr*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store %struct.DynArr* %0, %struct.DynArr** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = mul nsw i32 2, %10
%12 = add nsw i32 %11, 1
store i32 %12, i32* %7
%13 = load i32, i32* %6
%14 = mul nsw i32 2, %13
%15 = add nsw i32 %14, 2
store i32 %15, i32* %8
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %17)
%19 = load i32, i32* %8
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %63
22: ; preds = %3
%23 = load %struct.DynArr*, %struct.DynArr** %4
%24 = load i32, i32* %7
%25 = load i32, i32* %8
%26 = call i32 @indexSmallest(%struct.DynArr* %23, i32 %24, i32 %25)
store i32 %26, i32* %9
%27 = load %struct.DynArr*, %struct.DynArr** %4
%28 = load i32, i32* %7
%29 = call i32 @getDynArr(%struct.DynArr* %27, i32 %28)
%30 = load %struct.DynArr*, %struct.DynArr** %4
%31 = load i32, i32* %8
%32 = call i32 @getDynArr(%struct.DynArr* %30, i32 %31)
%33 = load %struct.DynArr*, %struct.DynArr** %4
%34 = load i32, i32* %9
%35 = call i32 @getDynArr(%struct.DynArr* %33, i32 %34)
%36 = load i32, i32* %9
%37 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %32, i32 %35, i32 %36)
%38 = load %struct.DynArr*, %struct.DynArr** %4
%39 = load i32, i32* %6
%40 = call i32 @getDynArr(%struct.DynArr* %38, i32 %39)
%41 = load %struct.DynArr*, %struct.DynArr** %4
%42 = load i32, i32* %9
%43 = call i32 @getDynArr(%struct.DynArr* %41, i32 %42)
%44 = icmp sgt i32 %40, %43
br i1 %44, label %45, label %62
45: ; preds = %22
%46 = load %struct.DynArr*, %struct.DynArr** %4
%47 = load i32, i32* %6
%48 = call i32 @getDynArr(%struct.DynArr* %46, i32 %47)
%49 = load %struct.DynArr*, %struct.DynArr** %4
%50 = load i32, i32* %9
%51 = call i32 @getDynArr(%struct.DynArr* %49, i32 %50)
%52 = load i32, i32* %6
%53 = load i32, i32* %9
%54 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %48, i32 %51, i32 %52, i32 %53)
%55 = load %struct.DynArr*, %struct.DynArr** %4
%56 = load i32, i32* %6
%57 = load i32, i32* %9
%58 = call i32 @swapDynArr(%struct.DynArr* %55, i32 %56, i32 %57)
%59 = load %struct.DynArr*, %struct.DynArr** %4
%60 = load i32, i32* %5
%61 = load i32, i32* %9
br label %62
62: ; preds = %45, %22
br label %92
63: ; preds = %3
%64 = load i32, i32* %7
%65 = load i32, i32* %5
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %91
67: ; preds = %63
%68 = load %struct.DynArr*, %struct.DynArr** %4
%69 = load i32, i32* %7
%70 = call i32 @getDynArr(%struct.DynArr* %68, i32 %69)
%71 = load %struct.DynArr*, %struct.DynArr** %4
%72 = load i32, i32* %6
%73 = call i32 @getDynArr(%struct.DynArr* %71, i32 %72)
%74 = call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %70, i32 %73)
%75 = load %struct.DynArr*, %struct.DynArr** %4
%76 = load i32, i32* %6
%77 = call i32 @getDynArr(%struct.DynArr* %75, i32 %76)
%78 = load %struct.DynArr*, %struct.DynArr** %4
%79 = load i32, i32* %7
%80 = call i32 @getDynArr(%struct.DynArr* %78, i32 %79)
%81 = icmp sgt i32 %77, %80
br i1 %81, label %82, label %87
82: ; preds = %67
%83 = load %struct.DynArr*, %struct.DynArr** %4
%84 = load i32, i32* %6
%85 = load i32, i32* %7
%86 = call i32 @swapDynArr(%struct.DynArr* %83, i32 %84, i32 %85)
br label %87
87: ; preds = %82, %67
%88 = load %struct.DynArr*, %struct.DynArr** %4
%89 = load i32, i32* %5
%90 = load i32, i32* %7
br label %91
91: ; preds = %87, %63
br label %92
92: ; preds = %91, %62
ret void
}

LLVM IR (-O2):
%struct.DynArr = type { i32 }
@.str = [40 x i8] c"_adjust heap maxInd = %d, currInd = %d\0A\00"
@.str.1 = [49 x i8] c"\09Comparing %d and %d; smallest is %d [index %d]\0A\00"
@.str.2 = [45 x i8] c"\09\09Swapping values %d and %d [index %d / %d]\0A\00"
@.str.3 = [21 x i8] c"Comparing %d and %d\0A\00"
define void @_adjustHeap(%struct.DynArr* %0, i32 %1, i32 %2) {
br label %4
4: ; preds = %27, %3
%5 = phi i32 [ %2, %3 ], [ %28, %27 ]
%6 = shl nsw i32 %5, 1
%7 = or i32 %6, 1
%8 = add nsw i32 %6, 2
%9 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %1, i32 %5)
%10 = icmp slt i32 %8, %1
br i1 %10, label %11, label %29
11: ; preds = %4
%12 = tail call i32 @indexSmallest(%struct.DynArr* %0, i32 %7, i32 %8)
%13 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %7)
%14 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %8)
%15 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %12)
%16 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14, i32 %15, i32 %12)
%17 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %5)
%18 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %12)
%19 = icmp sgt i32 %17, %18
br i1 %19, label %20, label %38
20: ; preds = %11
%21 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %5)
%22 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %12)
%23 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i32 %21, i32 %22, i32 %5, i32 %12)
br label %24
24: ; preds = %31, %20
%25 = phi i32 [ %12, %20 ], [ %7, %31 ]
%26 = tail call i32 @swapDynArr(%struct.DynArr* %0, i32 %5, i32 %25)
br label %27
27: ; preds = %24, %31
%28 = phi i32 [ %7, %31 ], [ %25, %24 ]
br label %4
29: ; preds = %4
%30 = icmp slt i32 %7, %1
br i1 %30, label %31, label %38
31: ; preds = %29
%32 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %7)
%33 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %5)
%34 = tail call i32 (i8*, i32, i32, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %32, i32 %33)
%35 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %5)
%36 = tail call i32 @getDynArr(%struct.DynArr* %0, i32 %7)
%37 = icmp sgt i32 %35, %36
br i1 %37, label %24, label %27
38: ; preds = %29, %11
ret void
}