#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*/ siftDown(int *, int, int);
void heapSort(int *a, int count) {
  int start, end;
  for (start = (count - 2) / 2; start >= 0; start--) {
    siftDown(a, start, count);
  }
  for (end = count - 1; end > 0; end--) {
    do {
      int t = a[end];
      a[end] = a[0];
      a[0] = t;
    } while (0);
    siftDown(a, 0, end);
  }
}


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
sub    $0x2,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jl     1157 <heapSort+0x47>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <siftDown@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1130 <heapSort+0x20>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b3 <heapSort+0xa3>
jmp    116f <heapSort+0x5f>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
xor    %esi,%esi
call   1030 <siftDown@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1160 <heapSort+0x50>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapSort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %esi,%esi
jle    1189 <heapSort+0x79>
mov    %esi,%r14d
mov    %rdi,%r15
lea    -0x2(%r14),%eax
shr    $0x1f,%eax
lea    (%r14,%rax,1),%ebp
add    $0xfffffffe,%ebp
sar    %ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r14d,%edx
call   1030 <siftDown@plt>
add    $0xffffffff,%ebp
jb     1140 <heapSort+0x30>
cmp    $0x2,%r14d
jl     1189 <heapSort+0x79>
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
lea    -0x1(%rbp),%rbx
mov    %ebx,%eax
mov    (%r15,%rax,4),%ecx
mov    (%r15),%edx
mov    %edx,(%r15,%rax,4)
mov    %ecx,(%r15)
mov    %r15,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1030 <siftDown@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1160 <heapSort+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
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
%7 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
%9 = sub nsw i32 %8, 2
%10 = sdiv i32 %9, 2
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* %4
%18 = call i32 @siftDown(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* %4
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %6
br label %25
25: ; preds = %49, %22
%26 = load i32, i32* %6
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %52
28: ; preds = %25
br label %29
29: ; preds = %28
%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 = load i32, i32* %33
store i32 %34, i32* %7
%35 = load i32*, i32** %3
%36 = getelementptr inbounds i32, i32* %35, i64 0
%37 = load i32, i32* %36
%38 = load i32*, i32** %3
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i32, i32* %38, i64 %40
store i32 %37, i32* %41
%42 = load i32, i32* %7
%43 = load i32*, i32** %3
%44 = getelementptr inbounds i32, i32* %43, i64 0
store i32 %42, i32* %44
br label %45
45: ; preds = %29
%46 = load i32*, i32** %3
%47 = load i32, i32* %6
%48 = call i32 @siftDown(i32* %46, i32 0, i32 %47)
br label %49
49: ; preds = %45
%50 = load i32, i32* %6
%51 = add nsw i32 %50, -1
store i32 %51, i32* %6
br label %25
52: ; preds = %25
ret void
}

LLVM IR (-O2):
define void @heapSort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 0
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = add nsw i32 %1, -2
%6 = sdiv i32 %5, 2
br label %11
7: ; preds = %11
%8 = icmp sgt i32 %1, 1
br i1 %8, label %9, label %26
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %16
11: ; preds = %4, %11
%12 = phi i32 [ %14, %11 ], [ %6, %4 ]
%13 = tail call i32 @siftDown(i32* %0, i32 %12, i32 %1)
%14 = add nsw i32 %12, -1
%15 = icmp eq i32 %12, 0
br i1 %15, label %7, label %11
16: ; preds = %9, %16
%17 = phi i64 [ %10, %9 ], [ %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 = load i32, i32* %21
%23 = load i32, i32* %0
store i32 %23, i32* %21
store i32 %22, i32* %0
%24 = tail call i32 @siftDown(i32* %0, i32 0, i32 %19)
%25 = icmp ugt i64 %17, 2
br i1 %25, label %16, label %26
26: ; preds = %16, %2, %7
ret void
}