#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 *allocate_array(int, char **);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ heapify(int *, int);
int /*<<< orphan*/ printf(char *, ...);
int test_heap(int *, int);
int main(int argc, char *argv[]) {
  int result;
  int i;
  int n = argc - 1;
  int *arr = allocate_array(argc, argv);
  heapify(arr, n);
  result = test_heap(arr, n);
  for (i = 0; i < n; i++)
    printf("%d ", arr[i]);
  printf("\n");
  if (result == 1)
    printf("Heap test success!\n");
  else
    printf("Heap test failed.\n");
  free(arr);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <allocate_array@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1060 <heapify@plt>
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1070 <test_heap@plt>
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11d4 <main+0x84>
mov    -0x28(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <main+0x51>
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x14(%rbp)
jne    11ff <main+0xaf>
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    120d <main+0xbd>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edi,%ebp
lea    -0x1(%rbp),%r15d
call   1050 <allocate_array@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15d,%esi
call   1080 <heapify@plt>
mov    %r12,%rdi
mov    %r15d,%esi
call   1090 <test_heap@plt>
mov    %eax,%r14d
cmp    $0x2,%ebp
jl     11c7 <main+0x57>
mov    %r15d,%ebp
lea    0xe52(%rip),%r15
xor    %ebx,%ebx
mov    (%r12,%rbx,4),%esi
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    11b0 <main+0x40>
mov    $0xa,%edi
call   1040 <putchar@plt>
cmp    $0x1,%r14d
lea    0xe3a(%rip),%rax
lea    0xe21(%rip),%rdi
cmove  %rax,%rdi
call   1060 <puts@plt>
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
@str = [18 x i8] c"Heap test failed.\00"
@str.4 = [19 x i8] c"Heap test success!\00"
define i32 @main(i32 %0, i8** %1) {
%3 = add i32 %0, -1
%4 = tail call i32* @allocate_array(i32 %0, i8** %1)
%5 = tail call i32 @heapify(i32* %4, i32 %3)
%6 = tail call i32 @test_heap(i32* %4, i32 %3)
%7 = icmp sgt i32 %0, 1
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = zext i32 %3 to i64
br label %10
10: ; preds = %8, %10
%11 = phi i64 [ 0, %8 ], [ %15, %10 ]
%12 = getelementptr inbounds i32, i32* %4, i64 %11
%13 = load i32, i32* %12
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = add nuw nsw i64 %11, 1
%16 = icmp eq i64 %15, %9
br i1 %16, label %17, label %10
17: ; preds = %10, %2
%18 = tail call i32 @putchar(i32 10)
%19 = icmp eq i32 %6, 1
%20 = select i1 %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0)
%21 = tail call i32 @puts(i8* dereferenceable(1) %20)
%22 = tail call i32 @free(i32* %4)
ret i32 0
}