#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 /*<<< orphan*/, int);
void heapsort(int numbers[], int array_size) {
  int i, temp;
  for (i = array_size - 1; i >= 1; i--) {
    temp = numbers[0];
    numbers[0] = numbers[i];
    numbers[i] = temp;
    siftDown(numbers, 0, i - 1);
  }
}


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    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     1179 <heapsort+0x69>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x14(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <siftDown@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1128 <heapsort+0x18>
add    $0x20,%rsp
pop    %rbp
ret

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

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