#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);
int /*<<< orphan*/ maxHeapFilterDown(int *, int /*<<< orphan*/, int);
void heapSortInc(int array[], int size) {
  int temp;
  int n;
  buildMaxHeap(array, size);
  for (n = size - 1; n > 0; n--) {
    temp = array[n];
    array[n] = array[0];
    array[0] = temp;
    maxHeapFilterDown(array, 0, n);
  }
}


x86 assembly (clang, -O0):
<heapSortInc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <buildMaxHeap@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1192 <heapSortInc+0x72>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1030 <maxHeapFilterDown@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <heapSortInc+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSortInc>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <buildMaxHeap@plt>
cmp    $0x2,%ebp
jl     1169 <heapSortInc+0x49>
mov    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x1(%rbp),%rbx
mov    %ebx,%eax
mov    (%r14,%rax,4),%ecx
mov    (%r14),%edx
mov    %edx,(%r14,%rax,4)
mov    %ecx,(%r14)
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <maxHeapFilterDown@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1140 <heapSortInc+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @heapSortInc(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
%8 = load i32, i32* %4
%9 = call i32 @buildMaxHeap(i32* %7, i32 %8)
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 1
store i32 %11, i32* %6
br label %12
12: ; preds = %34, %2
%13 = load i32, i32* %6
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = load i32, i32* %6
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
store i32 %20, i32* %5
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 0
%23 = load i32, i32* %22
%24 = load i32*, i32** %3
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %24, i64 %26
store i32 %23, i32* %27
%28 = load i32, i32* %5
%29 = load i32*, i32** %3
%30 = getelementptr inbounds i32, i32* %29, i64 0
store i32 %28, i32* %30
%31 = load i32*, i32** %3
%32 = load i32, i32* %6
%33 = call i32 @maxHeapFilterDown(i32* %31, i32 0, i32 %32)
br label %34
34: ; preds = %15
%35 = load i32, i32* %6
%36 = add nsw i32 %35, -1
store i32 %36, i32* %6
br label %12
37: ; preds = %12
ret void
}

LLVM IR (-O2):
define void @heapSortInc(i32* %0, i32 %1) {
%3 = tail call i32 @buildMaxHeap(i32* %0, i32 %1)
%4 = icmp sgt i32 %1, 1
br i1 %4, label %5, label %17
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ %6, %5 ], [ %9, %7 ]
%9 = add nsw i64 %8, -1
%10 = trunc i64 %9 to i32
%11 = and i64 %9, 4294967295
%12 = getelementptr inbounds i32, i32* %0, i64 %11
%13 = load i32, i32* %12
%14 = load i32, i32* %0
store i32 %14, i32* %12
store i32 %13, i32* %0
%15 = tail call i32 @maxHeapFilterDown(i32* %0, i32 0, i32 %10)
%16 = icmp ugt i64 %8, 2
br i1 %16, label %7, label %17
17: ; preds = %7, %2
ret void
}