#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*/ shiftDown(int *, int, int);
int /*<<< orphan*/ swap(int *, int /*<<< orphan*/, int);
void heapSort(int *arr, int arrSize) {
  int i;
  int len = arrSize;
  for (i = len / 2 - 1; i >= 0; i--) {
    shiftDown(arr, i, len);
  }
  for (i = len - 1; i > 0; i--) {
    swap(arr, 0, i);
    shiftDown(arr, 0, i);
  }
}


x86 assembly (clang, -O0):
<heapSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     116d <heapSort+0x4d>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0x14(%rbp),%edx
call   1040 <shiftDown@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <heapSort+0x26>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    11aa <heapSort+0x8a>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
xor    %esi,%esi
call   1030 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
xor    %esi,%esi
call   1040 <shiftDown@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1176 <heapSort+0x56>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSort>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%esi
jl     1183 <heapSort+0x63>
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%ebx
shr    %ebx
add    $0x1,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
lea    -0x2(%rbx),%esi
mov    %r14,%rdi
mov    %ebp,%edx
call   1040 <shiftDown@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1140 <heapSort+0x20>
cmp    $0x2,%ebp
jl     1183 <heapSort+0x63>
add    $0x1,%ebp
nopl   (%rax)
lea    -0x2(%rbp),%ebx
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <swap@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <shiftDown@plt>
add    $0xffffffff,%ebp
cmp    $0x2,%ebp
ja     1160 <heapSort+0x40>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @heapSort(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* %4
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = sdiv i32 %8, 2
%10 = sub nsw i32 %9, 1
store i32 %10, i32* %5
br label %11
11: ; preds = %19, %2
%12 = load i32, i32* %5
%13 = icmp sge i32 %12, 0
br i1 %13, label %14, label %22
14: ; preds = %11
%15 = load i32*, i32** %3
%16 = load i32, i32* %5
%17 = load i32, i32* %6
%18 = call i32 @shiftDown(i32* %15, i32 %16, i32 %17)
br label %19
19: ; preds = %14
%20 = load i32, i32* %5
%21 = add nsw i32 %20, -1
store i32 %21, i32* %5
br label %11
22: ; preds = %11
%23 = load i32, i32* %6
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %5
br label %25
25: ; preds = %35, %22
%26 = load i32, i32* %5
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = load i32*, i32** %3
%30 = load i32, i32* %5
%31 = call i32 @swap(i32* %29, i32 0, i32 %30)
%32 = load i32*, i32** %3
%33 = load i32, i32* %5
%34 = call i32 @shiftDown(i32* %32, i32 0, i32 %33)
br label %35
35: ; preds = %28
%36 = load i32, i32* %5
%37 = add nsw i32 %36, -1
store i32 %37, i32* %5
br label %25
38: ; preds = %25
ret void
}

LLVM IR (-O2):
define void @heapSort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %18
4: ; preds = %2
%5 = lshr i32 %1, 1
br label %7
6: ; preds = %7
br i1 %3, label %12, label %18
7: ; preds = %4, %7
%8 = phi i32 [ %9, %7 ], [ %5, %4 ]
%9 = add nsw i32 %8, -1
%10 = tail call i32 @shiftDown(i32* %0, i32 %9, i32 %1)
%11 = icmp ugt i32 %8, 1
br i1 %11, label %7, label %6
12: ; preds = %6, %12
%13 = phi i32 [ %14, %12 ], [ %1, %6 ]
%14 = add nsw i32 %13, -1
%15 = tail call i32 @swap(i32* %0, i32 0, i32 %14)
%16 = tail call i32 @shiftDown(i32* %0, i32 0, i32 %14)
%17 = icmp ugt i32 %13, 2
br i1 %17, label %12, label %18
18: ; preds = %12, %2, %6
ret void
}