#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 *);
void heapSort(int arr[], int length, int *heapSize) {
  int i, t;
  buildMaxHeap(arr, length, heapSize);
  for (i = length - 1; i > 0; i--) {
    {
      t = arr[1];
      arr[1] = arr[i];
      arr[i] = t;
    };
  }
}


x86 assembly (clang, -O0):
<heapSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1030 <buildMaxHeap@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jle    117e <heapSort+0x6e>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x20(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    113c <heapSort+0x2c>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSort>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%rbx
call   1030 <buildMaxHeap@plt>
cmp    $0x2,%ebp
jl     1149 <heapSort+0x39>
mov    %ebp,%eax
add    $0x1,%rax
nopl   0x0(%rax,%rax,1)
lea    -0x2(%rax),%ecx
mov    0x4(%rbx),%edx
mov    (%rbx,%rcx,4),%esi
mov    %esi,0x4(%rbx)
mov    %edx,(%rbx,%rcx,4)
add    $0xffffffffffffffff,%rax
cmp    $0x2,%rax
ja     1130 <heapSort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

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