#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*/ buildMaxHeap(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printArray(int *, int);
int /*<<< orphan*/ treeReOrderMaxHeap(int *, int, int);
void heapSortInPlace(int *array, int n) {
  int temp, i;
  int heapsize = n;
  buildMaxHeap(array, 0, heapsize);
  printArray(array, n);
  for (i = 0; i <= n - 1; i++) {
    treeReOrderMaxHeap(array, i, heapsize);
    printArray(array, n);
  }
}


x86 assembly (clang, -O0):
<heapSortInPlace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%edx
xor    %esi,%esi
call   1030 <buildMaxHeap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printArray@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    -0xc(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jg     11a0 <heapSortInPlace+0x70>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x18(%rbp),%edx
call   1050 <treeReOrderMaxHeap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <printArray@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1166 <heapSortInPlace+0x36>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSortInPlace>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebx
mov    %rdi,%r14
xor    %ebp,%ebp
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <buildMaxHeap@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <printArray@plt>
test   %ebx,%ebx
jle    117d <heapSortInPlace+0x4d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
mov    %ebx,%edx
call   1050 <treeReOrderMaxHeap@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <printArray@plt>
add    $0x1,%ebp
cmp    %ebp,%ebx
jne    1160 <heapSortInPlace+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @heapSortInPlace(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
store i32 %8, i32* %7
%9 = load i32*, i32** %3
%10 = load i32, i32* %7
%11 = call i32 @buildMaxHeap(i32* %9, i32 0, i32 %10)
%12 = load i32*, i32** %3
%13 = load i32, i32* %4
%14 = call i32 @printArray(i32* %12, i32 %13)
store i32 0, i32* %6
br label %15
15: ; preds = %28, %2
%16 = load i32, i32* %6
%17 = load i32, i32* %4
%18 = sub nsw i32 %17, 1
%19 = icmp sle i32 %16, %18
br i1 %19, label %20, label %31
20: ; preds = %15
%21 = load i32*, i32** %3
%22 = load i32, i32* %6
%23 = load i32, i32* %7
%24 = call i32 @treeReOrderMaxHeap(i32* %21, i32 %22, i32 %23)
%25 = load i32*, i32** %3
%26 = load i32, i32* %4
%27 = call i32 @printArray(i32* %25, i32 %26)
br label %28
28: ; preds = %20
%29 = load i32, i32* %6
%30 = add nsw i32 %29, 1
store i32 %30, i32* %6
br label %15
31: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @heapSortInPlace(i32* %0, i32 %1) {
%3 = tail call i32 @buildMaxHeap(i32* %0, i32 0, i32 %1)
%4 = tail call i32 @printArray(i32* %0, i32 %1)
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %12
6: ; preds = %2, %6
%7 = phi i32 [ %10, %6 ], [ 0, %2 ]
%8 = tail call i32 @treeReOrderMaxHeap(i32* %0, i32 %7, i32 %1)
%9 = tail call i32 @printArray(i32* %0, i32 %1)
%10 = add nuw nsw i32 %7, 1
%11 = icmp eq i32 %10, %1
br i1 %11, label %12, label %6
12: ; preds = %6, %2
ret void
}