#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 */
scalar_t__ EOF;
int /*<<< orphan*/ heapsort(int *, int, int *);
int /*<<< orphan*/ printf(char *, int, ...);
scalar_t__ scanf(char *, int *);
int main() {
  int data[20];
  int num;
  int i;
  int times[] = {0, 0};
  data[0] = -1;
  for (i = 1; scanf("%d", &data[i]) != EOF; i++)
    ;
  num = i;
  heapsort(data, num - 1, times);
  for (i = 1; i < num; i++)
    printf(" %2d", data[i]);
  printf("\nkey    : %2d\ndata   : %2d\n", times[0], times[1]);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
movl   $0xffffffff,-0x60(%rbp)
movl   $0x1,-0x68(%rbp)
movslq -0x68(%rbp),%rax
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe7d(%rip),%rdi
call   1060 <scanf@plt>
mov    0x2e59(%rip),%rcx
cmp    (%rcx),%rax
je     11ab <main+0x6b>
jmp    119d <main+0x5d>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    116d <main+0x2d>
mov    -0x68(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%esi
sub    $0x1,%esi
lea    -0x70(%rbp),%rdx
call   1050 <heapsort@plt>
movl   $0x1,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    11fb <main+0xbb>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe1d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11cb <main+0x8b>
mov    -0x70(%rbp),%esi
mov    -0x6c(%rbp),%edx
lea    0xe00(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x68,%rsp
movq   $0x0,0x8(%rsp)
movl   $0xffffffff,0x10(%rsp)
ff
lea    0x14(%rsp),%rbx
xor    %r15d,%r15d
lea    0xea5(%rip),%r14
mov    0x2e86(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
add    $0x1,%r15d
add    $0x4,%rbx
cmp    (%r12),%rax
jne    1170 <main+0x40>
lea    -0x1(%r15),%esi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
call   1040 <heapsort@plt>
cmp    $0x2,%r15d
jb     11d7 <main+0xa7>
mov    %r15d,%r15d
mov    $0x1,%ebx
lea    0xe52(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x10(%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    11c0 <main+0x90>
mov    0x8(%rsp),%esi
mov    0xc(%rsp),%edx
lea    0xe22(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [5 x i8] c" %2d\00"
@.str.2 = [28 x i8] c"\0Akey : %2d\0Adata : %2d\0A\00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = alloca i64
%3 = bitcast [20 x i32]* %1 to i8*
%4 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
store i32 -1, i32* %5
br label %6
6: ; preds = %6, %0
%7 = phi i64 [ %12, %6 ], [ 1, %0 ]
%8 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %7
%9 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %8)
%10 = load i64, i64* @EOF
%11 = icmp eq i64 %9, %10
%12 = add nuw i64 %7, 1
br i1 %11, label %13, label %6
13: ; preds = %6
%14 = trunc i64 %7 to i32
%15 = add nsw i32 %14, -1
%16 = bitcast i64* %2 to i32*
%17 = call i32 @heapsort(i32* %5, i32 %15, i32* %16)
%18 = icmp ugt i32 %14, 1
br i1 %18, label %19, label %28
19: ; preds = %13
%20 = and i64 %7, 4294967295
br label %21
21: ; preds = %19, %21
%22 = phi i64 [ 1, %19 ], [ %26, %21 ]
%23 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %22
%24 = load i32, i32* %23
%25 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = add nuw nsw i64 %22, 1
%27 = icmp eq i64 %26, %20
br i1 %27, label %28, label %21
28: ; preds = %21, %13
%29 = bitcast i64* %2 to [2 x i32]*
%30 = load i32, i32* %16
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %29, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %32)
ret i32 0
}