#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*/ heapsort(int *, int);
int /*<<< orphan*/ printf(char *, int, char *);
int main() {
  int a[] = {4, 65, 2, -31, 0, 99, 2, 83, 782, 1};
  int n = sizeof a / sizeof a[0];
  int i;
  for (i = 0; i < n; i++)
    printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
  heapsort(a, n);
  for (i = 0; i < n; i++)
    printf("%d%s", a[i], i == n - 1 ? "\n" : " ");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x30(%rbp),%rdi
lea    0xeb6(%rip),%rsi
mov    $0x28,%edx
call   1050 <memcpy@plt>
movl   $0xa,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    11ad <main+0x7d>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%edi
sub    $0x1,%edi
lea    0xea9(%rip),%rdx
lea    0xea0(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xe8e(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    1162 <main+0x32>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%esi
call   1040 <heapsort@plt>
movl   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%eax
cmp    -0x34(%rbp),%eax
jge    120b <main+0xdb>
movslq -0x38(%rbp),%rax
mov    -0x30(%rbp,%rax,4),%esi
mov    -0x38(%rbp),%ecx
mov    -0x34(%rbp),%edi
sub    $0x1,%edi
lea    0xe4b(%rip),%rdx
lea    0xe42(%rip),%rax
cmp    %edi,%ecx
cmove  %rax,%rdx
lea    0xe30(%rip),%rdi
call   1030 <printf@plt>
mov    -0x38(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x38(%rbp)
jmp    11c0 <main+0x90>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    0xef0(%rip),%rax
mov    %rax,0x20(%rsp)
movaps 0xed4(%rip),%xmm0
movaps %xmm0,0x10(%rsp)
movaps 0xeb8(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0xed5(%rip),%rbx
lea    0xed5(%rip),%r14
mov    %rbx,%rdi
mov    $0x4,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x41,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0xffffffe1,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x63,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x53,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    %rbx,%rdi
mov    $0x30e,%esi
mov    %r14,%rdx
call   1030 <printf@plt>
lea    0xe3f(%rip),%r15
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
call   1030 <printf@plt>
mov    %rsp,%rdi
mov    $0xa,%esi
call   1040 <heapsort@plt>
mov    (%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x4(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x10(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x14(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x18(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x1c(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x20(%rsp),%esi
mov    %rbx,%rdi
mov    %r14,%rdx
call   1030 <printf@plt>
mov    0x24(%rsp),%esi
mov    %rbx,%rdi
mov    %r15,%rdx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.a = [10 x i32] [i32 4, i32 65, i32 2, i32 -31, i32 0, i32 99, i32 2, i32 83, i32 782, i32 1]
@.str = [5 x i8] c"%d%s\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [10 x i32]* %2 to i8*
store i32 10, i32* %3
store i32 0, i32* %4
br label %6
6: ; preds = %22, %0
%7 = load i32, i32* %4
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %25
10: ; preds = %6
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %12
%14 = load i32, i32* %13
%15 = load i32, i32* %4
%16 = load i32, i32* %3
%17 = sub nsw i32 %16, 1
%18 = icmp eq i32 %15, %17
%19 = zext i1 %18 to i64
%20 = select i1 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%21 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %14, i8* %20)
br label %22
22: ; preds = %10
%23 = load i32, i32* %4
%24 = add nsw i32 %23, 1
store i32 %24, i32* %4
br label %6
25: ; preds = %6
%26 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %3
%28 = call i32 @heapsort(i32* %26, i32 %27)
store i32 0, i32* %4
br label %29
29: ; preds = %45, %25
%30 = load i32, i32* %4
%31 = load i32, i32* %3
%32 = icmp slt i32 %30, %31
br i1 %32, label %33, label %48
33: ; preds = %29
%34 = load i32, i32* %4
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %35
%37 = load i32, i32* %36
%38 = load i32, i32* %4
%39 = load i32, i32* %3
%40 = sub nsw i32 %39, 1
%41 = icmp eq i32 %38, %40
%42 = zext i1 %41 to i64
%43 = select i1 %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%44 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %37, i8* %43)
br label %45
45: ; preds = %33
%46 = load i32, i32* %4
%47 = add nsw i32 %46, 1
store i32 %47, i32* %4
br label %29
48: ; preds = %29
ret i32 0
}

LLVM IR (-O2):
@__const.main.a = [10 x i32] [i32 4, i32 65, i32 2, i32 -31, i32 0, i32 99, i32 2, i32 83, i32 782, i32 1]
@.str = [5 x i8] c"%d%s\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [2 x i8] c" \00"
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%5 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 65, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%7 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
%10 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 -31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
%12 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
%14 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 99, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
%16 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%17 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
%18 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 83, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%19 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
%20 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 782, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
%22 = tail call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%23 = call i32 @heapsort(i32* %3, i32 10)
%24 = load i32, i32* %3
%25 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* %7
%29 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%30 = load i32, i32* %9
%31 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %30, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* %11
%33 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* %13
%35 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* %15
%37 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %36, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32, i32* %17
%39 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%40 = load i32, i32* %19
%41 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* %21
%43 = call i32 @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
}