#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*/ heapify(int *, int, int);
int /*<<< orphan*/ swap(int *, int, int /*<<< orphan*/);
void heapSort(int *A, int n) {
  for (int i = n; i >= 0; i--)
    heapify(A, n, i);
  for (int i = n - 1; i > 0; i--) {
    swap(A, i, 0);
    heapify(A, i, 0);
  }
}


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,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     115c <heapSort+0x3c>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x10(%rbp),%edx
call   1030 <heapify@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1135 <heapSort+0x15>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1199 <heapSort+0x79>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
call   1040 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
xor    %edx,%edx
call   1030 <heapify@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1165 <heapSort+0x45>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSort>:
push   %rbp
push   %r14
push   %rbx
test   %esi,%esi
js     1173 <heapSort+0x53>
mov    %esi,%ebx
mov    %rdi,%r14
mov    %esi,%ebp
nop
mov    %r14,%rdi
mov    %ebx,%esi
mov    %ebp,%edx
call   1030 <heapify@plt>
add    $0xffffffff,%ebp
jb     1130 <heapSort+0x10>
cmp    $0x2,%ebx
jl     1173 <heapSort+0x53>
add    $0x1,%ebx
nopl   0x0(%rax)
lea    -0x2(%rbx),%ebp
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1040 <swap@plt>
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1030 <heapify@plt>
add    $0xffffffff,%ebx
cmp    $0x2,%ebx
ja     1150 <heapSort+0x30>
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* %5
br label %8
8: ; preds = %16, %2
%9 = load i32, i32* %5
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = load i32*, i32** %3
%13 = load i32, i32* %4
%14 = load i32, i32* %5
%15 = call i32 @heapify(i32* %12, i32 %13, i32 %14)
br label %16
16: ; preds = %11
%17 = load i32, i32* %5
%18 = add nsw i32 %17, -1
store i32 %18, i32* %5
br label %8
19: ; preds = %8
%20 = load i32, i32* %4
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %6
br label %22
22: ; preds = %32, %19
%23 = load i32, i32* %6
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i32*, i32** %3
%27 = load i32, i32* %6
%28 = call i32 @swap(i32* %26, i32 %27, i32 0)
%29 = load i32*, i32** %3
%30 = load i32, i32* %6
%31 = call i32 @heapify(i32* %29, i32 %30, i32 0)
br label %32
32: ; preds = %25
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
br label %22
35: ; preds = %22
ret void
}

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