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


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xffffffff,-0x60(%rbp)
movl   $0x1,-0x68(%rbp)
movslq -0x68(%rbp),%rax
lea    -0x60(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xe9d(%rip),%rdi
call   1050 <scanf@plt>
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
je     118b <main+0x5b>
jmp    117d <main+0x4d>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    114d <main+0x1d>
mov    -0x68(%rbp),%eax
mov    %eax,-0x64(%rbp)
lea    0xe6b(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    11d6 <main+0xa6>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    11a6 <main+0x76>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x64(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x68(%rbp)
cmpl   $0x0,-0x68(%rbp)
jle    121c <main+0xec>
lea    -0x60(%rbp),%rdi
mov    -0x68(%rbp),%esi
mov    -0x64(%rbp),%edx
sub    $0x1,%edx
call   1040 <downheap@plt>
mov    -0x68(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x68(%rbp)
jmp    11f2 <main+0xc2>
lea    0xdf1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x1,-0x68(%rbp)
mov    -0x68(%rbp),%eax
cmp    -0x64(%rbp),%eax
jge    1261 <main+0x131>
movslq -0x68(%rbp),%rax
mov    -0x60(%rbp,%rax,4),%esi
lea    0xdc1(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x68(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x68(%rbp)
jmp    1231 <main+0x101>
lea    0xdaa(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
movl   $0xffffffff,(%rsp)
lea    0x4(%rsp),%rbx
xor    %ebp,%ebp
lea    0xe9f(%rip),%r14
mov    0x2e80(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <scanf@plt>
add    $0x1,%ebp
add    $0x4,%rbx
cmp    (%r15),%rax
jne    1170 <main+0x30>
lea    0xe75(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x1,%ebp
jbe    1238 <main+0xf8>
mov    %ebp,%r12d
mov    $0x1,%ebx
lea    0xe60(%rip),%r14
nopl   (%rax)
mov    (%rsp,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    11b0 <main+0x70>
mov    $0xa,%edi
call   1030 <putchar@plt>
cmp    $0x2,%ebp
jb     11f7 <main+0xb7>
mov    %ebp,%ebx
shr    %ebx
lea    -0x1(%rbp),%r15d
mov    %rsp,%r14
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15d,%edx
call   1050 <downheap@plt>
lea    -0x1(%rbx),%eax
cmp    $0x1,%ebx
mov    %eax,%ebx
ja     11e0 <main+0xa0>
lea    0xe14(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
cmp    $0x2,%ebp
jb     1250 <main+0x110>
mov    $0x1,%ebp
lea    0xdf7(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
mov    (%rsp,%rbp,4),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1220 <main+0xe0>
jmp    1250 <main+0x110>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xdc9(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [10 x i8] c"BEFORE : \00"
@.str.2 = [5 x i8] c"%2d \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [10 x i8] c"AFTER : \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [20 x i32]
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
%5 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
store i32 -1, i32* %5
store i32 1, i32* %4
br label %6
6: ; preds = %14, %0
%7 = load i32, i32* %4
%8 = sext i32 %7 to i64
%9 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %8
%10 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %9)
%11 = load i64, i64* @EOF
%12 = icmp ne i64 %10, %11
br i1 %12, label %13, label %17
13: ; preds = %6
br label %14
14: ; preds = %13
%15 = load i32, i32* %4
%16 = add nsw i32 %15, 1
store i32 %16, i32* %4
br label %6
17: ; preds = %6
%18 = load i32, i32* %4
store i32 %18, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 1, i32* %4
br label %20
20: ; preds = %30, %17
%21 = load i32, i32* %4
%22 = load i32, i32* %3
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32, i32* %4
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %4
%32 = add nsw i32 %31, 1
store i32 %32, i32* %4
br label %20
33: ; preds = %20
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%35 = load i32, i32* %3
%36 = sdiv i32 %35, 2
store i32 %36, i32* %4
br label %37
37: ; preds = %46, %33
%38 = load i32, i32* %4
%39 = icmp sgt i32 %38, 0
br i1 %39, label %40, label %49
40: ; preds = %37
%41 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 0
%42 = load i32, i32* %4
%43 = load i32, i32* %3
%44 = sub nsw i32 %43, 1
%45 = call i32 @downheap(i32* %41, i32 %42, i32 %44)
br label %46
46: ; preds = %40
%47 = load i32, i32* %4
%48 = add nsw i32 %47, -1
store i32 %48, i32* %4
br label %37
49: ; preds = %37
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %4
br label %51
51: ; preds = %61, %49
%52 = load i32, i32* %4
%53 = load i32, i32* %3
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %64
55: ; preds = %51
%56 = load i32, i32* %4
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds [20 x i32], [20 x i32]* %2, i64 0, i64 %57
%59 = load i32, i32* %58
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %59)
br label %61
61: ; preds = %55
%62 = load i32, i32* %4
%63 = add nsw i32 %62, 1
store i32 %63, i32* %4
br label %51
64: ; preds = %51
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@EOF = global i64 0
@.str.1 = [10 x i8] c"BEFORE : \00"
@.str.2 = [5 x i8] c"%2d \00"
@.str.4 = [10 x i8] c"AFTER : \00"
define i32 @main() {
%1 = alloca [20 x i32]
%2 = bitcast [20 x i32]* %1 to i8*
%3 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 0
store i32 -1, i32* %3
br label %4
4: ; preds = %4, %0
%5 = phi i64 [ %10, %4 ], [ 1, %0 ]
%6 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %5
%7 = call i64 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %6)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
%10 = add nuw i64 %5, 1
br i1 %9, label %11, label %4
11: ; preds = %4
%12 = trunc i64 %5 to i32
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp ugt i32 %12, 1
br i1 %14, label %18, label %15
15: ; preds = %11
%16 = call i32 @putchar(i32 10)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br label %49
18: ; preds = %11
%19 = and i64 %5, 4294967295
br label %20
20: ; preds = %18, %20
%21 = phi i64 [ 1, %18 ], [ %25, %20 ]
%22 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %21
%23 = load i32, i32* %22
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = add nuw nsw i64 %21, 1
%26 = icmp eq i64 %25, %19
br i1 %26, label %27, label %20
27: ; preds = %20
%28 = call i32 @putchar(i32 10)
%29 = icmp ult i32 %12, 2
br i1 %29, label %38, label %30
30: ; preds = %27
%31 = lshr i32 %12, 1
%32 = add nsw i32 %12, -1
br label %33
33: ; preds = %30, %33
%34 = phi i32 [ %31, %30 ], [ %36, %33 ]
%35 = call i32 @downheap(i32* %3, i32 %34, i32 %32)
%36 = add nsw i32 %34, -1
%37 = icmp ugt i32 %34, 1
br i1 %37, label %33, label %38
38: ; preds = %33, %27
%39 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0))
br i1 %14, label %40, label %49
40: ; preds = %38
%41 = and i64 %5, 4294967295
br label %42
42: ; preds = %40, %42
%43 = phi i64 [ 1, %40 ], [ %47, %42 ]
%44 = getelementptr inbounds [20 x i32], [20 x i32]* %1, i64 0, i64 %43
%45 = load i32, i32* %44
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32 %45)
%47 = add nuw nsw i64 %43, 1
%48 = icmp eq i64 %47, %41
br i1 %48, label %49, label %42
49: ; preds = %42, %15, %38
%50 = call i32 @putchar(i32 10)
ret i32 0
}