#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*/ max_Heapify(int *, int /*<<< orphan*/, int, int);
void heapSort(int arr[], int n, int k) {
  int len = n;
  while (len > 1) {
    int temp = arr[0];
    arr[0] = arr[len - 1];
    arr[len - 1] = temp;
    len--;
    max_Heapify(arr, 0, len, k);
  }
}


x86 assembly (clang, -O0):
<heapSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    1183 <heapSort+0x73>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%edx
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
mov    -0x10(%rbp),%ecx
xor    %esi,%esi
call   1030 <max_Heapify@plt>
jmp    1128 <heapSort+0x18>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     115c <heapSort+0x4c>
mov    %edx,%r14d
mov    %rdi,%r15
mov    %esi,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    (%r15),%eax
lea    -0x1(%rbp),%rbx
mov    %ebx,%ecx
mov    (%r15,%rcx,4),%edx
mov    %edx,(%r15)
mov    %eax,(%r15,%rcx,4)
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebx,%edx
mov    %r14d,%ecx
call   1030 <max_Heapify@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1130 <heapSort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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* %5
store i32 %9, i32* %7
br label %10
10: ; preds = %13, %3
%11 = load i32, i32* %7
%12 = icmp sgt i32 %11, 1
br i1 %12, label %13, label %37
13: ; preds = %10
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 0
%16 = load i32, i32* %15
store i32 %16, i32* %8
%17 = load i32*, i32** %4
%18 = load i32, i32* %7
%19 = sub nsw i32 %18, 1
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i32, i32* %17, i64 %20
%22 = load i32, i32* %21
%23 = load i32*, i32** %4
%24 = getelementptr inbounds i32, i32* %23, i64 0
store i32 %22, i32* %24
%25 = load i32, i32* %8
%26 = load i32*, i32** %4
%27 = load i32, i32* %7
%28 = sub nsw i32 %27, 1
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %26, i64 %29
store i32 %25, i32* %30
%31 = load i32, i32* %7
%32 = add nsw i32 %31, -1
store i32 %32, i32* %7
%33 = load i32*, i32** %4
%34 = load i32, i32* %7
%35 = load i32, i32* %6
%36 = call i32 @max_Heapify(i32* %33, i32 0, i32 %34, i32 %35)
br label %10
37: ; preds = %10
ret void
}

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