#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*/ heapAdjust(int *, int, int);
int /*<<< orphan*/ swap(int *, int *);
void heapSort(int myArr[], int len) {
  for (int i = len / 2 - 1; i >= 0; i--) {
    heapAdjust(myArr, i, len);
  }
  for (int i = len - 1; i >= 0; i--) {
    swap(&myArr[0], &myArr[i]);
    heapAdjust(myArr, 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    $0x2,%ecx
cltd
idiv   %ecx
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1167 <heapSort+0x47>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1040 <heapAdjust@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1140 <heapSort+0x20>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jl     11ae <heapSort+0x8e>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x14(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
call   1030 <swap@plt>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1040 <heapAdjust@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1170 <heapSort+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSort>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
cmp    $0x2,%esi
jl     1155 <heapSort+0x35>
mov    %ebp,%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 <heapAdjust@plt>
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     1140 <heapSort+0x20>
test   %ebp,%ebp
jle    1187 <heapSort+0x67>
mov    %ebp,%ebp
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rbx
mov    %ebx,%eax
lea    (%r14,%rax,4),%rsi
mov    %r14,%rdi
call   1030 <swap@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1040 <heapAdjust@plt>
cmp    $0x1,%rbp
mov    %rbx,%rbp
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
%8 = sdiv i32 %7, 2
%9 = sub nsw i32 %8, 1
store i32 %9, i32* %5
br label %10
10: ; preds = %18, %2
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = load i32*, i32** %3
%15 = load i32, i32* %5
%16 = load i32, i32* %4
%17 = call i32 @heapAdjust(i32* %14, i32 %15, i32 %16)
br label %18
18: ; preds = %13
%19 = load i32, i32* %5
%20 = add nsw i32 %19, -1
store i32 %20, i32* %5
br label %10
21: ; preds = %10
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
store i32 %23, i32* %6
br label %24
24: ; preds = %38, %21
%25 = load i32, i32* %6
%26 = icmp sge i32 %25, 0
br i1 %26, label %27, label %41
27: ; preds = %24
%28 = load i32*, i32** %3
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32*, i32** %3
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i32, i32* %30, i64 %32
%34 = call i32 @swap(i32* %29, i32* %33)
%35 = load i32*, i32** %3
%36 = load i32, i32* %6
%37 = call i32 @heapAdjust(i32* %35, i32 0, i32 %36)
br label %38
38: ; preds = %27
%39 = load i32, i32* %6
%40 = add nsw i32 %39, -1
store i32 %40, i32* %6
br label %24
41: ; preds = %24
ret void
}

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