#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*/ maxheapify(int *, int, int);
int /*<<< orphan*/ printarray(int *);
int rand();
int /*<<< orphan*/ srand(int /*<<< orphan*/);
int /*<<< orphan*/ swap(int *, int /*<<< orphan*/, int);
int main() {
  int array[(10)];
  int i;
  srand(0);
  for (i = 0; i < (10); ++i)
    array[i] = rand() % 100;
  printarray(array);
  for (i = (10) - 1; i >= 0; --i)
    maxheapify(array, (10), i);
  printarray(array);
  for (i = 0; i < (10); ++i) {
    maxheapify(array, (10) - i, 0);
    swap(array, 0, (10) - 1 - i);
  }
  printarray(array);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %edi,%edi
call   1030 <srand@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    119c <main+0x4c>
mov    $0x0,%al
call   1070 <rand@plt>
mov    $0x64,%ecx
cltd
idiv   %ecx
movslq -0x34(%rbp),%rax
mov    %edx,-0x30(%rbp,%rax,4)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    116d <main+0x1d>
lea    -0x30(%rbp),%rdi
call   1040 <printarray@plt>
movl   $0x9,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jl     11d5 <main+0x85>
lea    -0x30(%rbp),%rdi
mov    -0x34(%rbp),%edx
mov    $0xa,%esi
call   1050 <maxheapify@plt>
mov    -0x34(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x34(%rbp)
jmp    11ac <main+0x5c>
lea    -0x30(%rbp),%rdi
call   1040 <printarray@plt>
movl   $0x0,-0x34(%rbp)
cmpl   $0xa,-0x34(%rbp)
jge    1223 <main+0xd3>
lea    -0x30(%rbp),%rdi
mov    $0xa,%esi
sub    -0x34(%rbp),%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
lea    -0x30(%rbp),%rdi
mov    $0x9,%edx
sub    -0x34(%rbp),%edx
xor    %esi,%esi
call   1060 <swap@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    11e5 <main+0x95>
lea    -0x30(%rbp),%rdi
call   1040 <printarray@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
xor    %edi,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x4(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x8(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0xc(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x10(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x14(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x18(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x1c(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x20(%rsp)
xor    %eax,%eax
call   1070 <rand@plt>
cltq
imul   $0x51eb851f,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
shr    $0x20,%rcx
sar    $0x5,%ecx
add    %edx,%ecx
imul   $0x64,%ecx,%ecx
sub    %ecx,%eax
mov    %eax,0x24(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1040 <printarray@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x9,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x8,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x7,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x6,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x5,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x4,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x3,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x2,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
mov    $0x1,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
call   1040 <printarray@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x9,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x9,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x8,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x7,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x7,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x6,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x6,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x3,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x2,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x1,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <maxheapify@plt>
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <swap@plt>
mov    %rbx,%rdi
call   1040 <printarray@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main() {
%1 = alloca i32
%2 = alloca [10 x i32]
%3 = alloca i32
store i32 0, i32* %1
%4 = call i32 @srand(i32 0)
store i32 0, i32* %3
br label %5
5: ; preds = %14, %0
%6 = load i32, i32* %3
%7 = icmp slt i32 %6, 10
br i1 %7, label %8, label %17
8: ; preds = %5
%9 = call i32 (...) @rand()
%10 = srem i32 %9, 100
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 %12
store i32 %10, i32* %13
br label %14
14: ; preds = %8
%15 = load i32, i32* %3
%16 = add nsw i32 %15, 1
store i32 %16, i32* %3
br label %5
17: ; preds = %5
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%19 = call i32 @printarray(i32* %18)
store i32 9, i32* %3
br label %20
20: ; preds = %27, %17
%21 = load i32, i32* %3
%22 = icmp sge i32 %21, 0
br i1 %22, label %23, label %30
23: ; preds = %20
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %3
%26 = call i32 @maxheapify(i32* %24, i32 10, i32 %25)
br label %27
27: ; preds = %23
%28 = load i32, i32* %3
%29 = add nsw i32 %28, -1
store i32 %29, i32* %3
br label %20
30: ; preds = %20
%31 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%32 = call i32 @printarray(i32* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %45, %30
%34 = load i32, i32* %3
%35 = icmp slt i32 %34, 10
br i1 %35, label %36, label %48
36: ; preds = %33
%37 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%38 = load i32, i32* %3
%39 = sub nsw i32 10, %38
%40 = call i32 @maxheapify(i32* %37, i32 %39, i32 0)
%41 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%42 = load i32, i32* %3
%43 = sub nsw i32 9, %42
%44 = call i32 @swap(i32* %41, i32 0, i32 %43)
br label %45
45: ; preds = %36
%46 = load i32, i32* %3
%47 = add nsw i32 %46, 1
store i32 %47, i32* %3
br label %33
48: ; preds = %33
%49 = getelementptr inbounds [10 x i32], [10 x i32]* %2, i64 0, i64 0
%50 = call i32 @printarray(i32* %49)
ret i32 0
}

LLVM IR (-O2):
define i32 @main() {
%1 = alloca [10 x i32]
%2 = bitcast [10 x i32]* %1 to i8*
%3 = tail call i32 @srand(i32 0)
%4 = tail call i32 (...) @rand()
%5 = srem i32 %4, 100
%6 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 0
store i32 %5, i32* %6
%7 = tail call i32 (...) @rand()
%8 = srem i32 %7, 100
%9 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 1
store i32 %8, i32* %9
%10 = tail call i32 (...) @rand()
%11 = srem i32 %10, 100
%12 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 2
store i32 %11, i32* %12
%13 = tail call i32 (...) @rand()
%14 = srem i32 %13, 100
%15 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 3
store i32 %14, i32* %15
%16 = tail call i32 (...) @rand()
%17 = srem i32 %16, 100
%18 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 4
store i32 %17, i32* %18
%19 = tail call i32 (...) @rand()
%20 = srem i32 %19, 100
%21 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 5
store i32 %20, i32* %21
%22 = tail call i32 (...) @rand()
%23 = srem i32 %22, 100
%24 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 6
store i32 %23, i32* %24
%25 = tail call i32 (...) @rand()
%26 = srem i32 %25, 100
%27 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 7
store i32 %26, i32* %27
%28 = tail call i32 (...) @rand()
%29 = srem i32 %28, 100
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 8
store i32 %29, i32* %30
%31 = tail call i32 (...) @rand()
%32 = srem i32 %31, 100
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %1, i64 0, i64 9
store i32 %32, i32* %33
%34 = call i32 @printarray(i32* %6)
%35 = call i32 @maxheapify(i32* %6, i32 10, i32 9)
%36 = call i32 @maxheapify(i32* %6, i32 10, i32 8)
%37 = call i32 @maxheapify(i32* %6, i32 10, i32 7)
%38 = call i32 @maxheapify(i32* %6, i32 10, i32 6)
%39 = call i32 @maxheapify(i32* %6, i32 10, i32 5)
%40 = call i32 @maxheapify(i32* %6, i32 10, i32 4)
%41 = call i32 @maxheapify(i32* %6, i32 10, i32 3)
%42 = call i32 @maxheapify(i32* %6, i32 10, i32 2)
%43 = call i32 @maxheapify(i32* %6, i32 10, i32 1)
%44 = call i32 @maxheapify(i32* %6, i32 10, i32 0)
%45 = call i32 @printarray(i32* %6)
%46 = call i32 @maxheapify(i32* %6, i32 10, i32 0)
%47 = call i32 @swap(i32* %6, i32 0, i32 9)
%48 = call i32 @maxheapify(i32* %6, i32 9, i32 0)
%49 = call i32 @swap(i32* %6, i32 0, i32 8)
%50 = call i32 @maxheapify(i32* %6, i32 8, i32 0)
%51 = call i32 @swap(i32* %6, i32 0, i32 7)
%52 = call i32 @maxheapify(i32* %6, i32 7, i32 0)
%53 = call i32 @swap(i32* %6, i32 0, i32 6)
%54 = call i32 @maxheapify(i32* %6, i32 6, i32 0)
%55 = call i32 @swap(i32* %6, i32 0, i32 5)
%56 = call i32 @maxheapify(i32* %6, i32 5, i32 0)
%57 = call i32 @swap(i32* %6, i32 0, i32 4)
%58 = call i32 @maxheapify(i32* %6, i32 4, i32 0)
%59 = call i32 @swap(i32* %6, i32 0, i32 3)
%60 = call i32 @maxheapify(i32* %6, i32 3, i32 0)
%61 = call i32 @swap(i32* %6, i32 0, i32 2)
%62 = call i32 @maxheapify(i32* %6, i32 2, i32 0)
%63 = call i32 @swap(i32* %6, i32 0, i32 1)
%64 = call i32 @maxheapify(i32* %6, i32 1, i32 0)
%65 = call i32 @swap(i32* %6, i32 0, i32 0)
%66 = call i32 @printarray(i32* %6)
ret i32 0
}