#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 */
typedef int /*<<< orphan*/ heap;

/* Variables and functions */
int /*<<< orphan*/ insert_max_heap(int *, int *, int);
int /*<<< orphan*/ print_array(int *, int);
int /*<<< orphan*/ printf(char *, int);
int remove_max_heap(int *, int *);
int main(void) {
  int heap[256];
  int heap_size = 0;
  printf("max size of heap: %d\n", sizeof(heap) / sizeof(*heap));
  insert_max_heap(heap, &heap_size, 20);
  insert_max_heap(heap, &heap_size, 10);
  insert_max_heap(heap, &heap_size, 50);
  insert_max_heap(heap, &heap_size, 3);
  print_array(heap, heap_size);
  insert_max_heap(heap, &heap_size, 8);
  insert_max_heap(heap, &heap_size, 5);
  insert_max_heap(heap, &heap_size, 3);
  insert_max_heap(heap, &heap_size, 1);
  insert_max_heap(heap, &heap_size, 100);
  print_array(heap, heap_size);
  printf("Removing element: %d\n", remove_max_heap(heap, &heap_size));
  print_array(heap, heap_size);
  printf("Removing element: %d\n", remove_max_heap(heap, &heap_size));
  print_array(heap, heap_size);
  printf("Removing element: %d\n", remove_max_heap(heap, &heap_size));
  print_array(heap, heap_size);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x414(%rbp)
lea    0xe9d(%rip),%rdi
mov    $0x100,%esi
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x14,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0xa,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x32,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x3,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   1030 <print_array@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x8,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x5,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x3,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x1,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
mov    $0x64,%edx
call   1050 <insert_max_heap@plt>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   1030 <print_array@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
call   1060 <remove_max_heap@plt>
mov    %eax,%esi
lea    0xd91(%rip),%rdi
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   1030 <print_array@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
call   1060 <remove_max_heap@plt>
mov    %eax,%esi
lea    0xd5e(%rip),%rdi
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   1030 <print_array@plt>
lea    -0x410(%rbp),%rdi
lea    -0x414(%rbp),%rsi
call   1060 <remove_max_heap@plt>
mov    %eax,%esi
lea    0xd2b(%rip),%rdi
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x414(%rbp),%esi
call   1030 <print_array@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
movl   $0x0,0xc(%rsp)
lea    0xea5(%rip),%rdi
mov    $0x100,%esi
call   1040 <printf@plt>
lea    0x10(%rsp),%rbx
lea    0xc(%rsp),%r14
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x14,%edx
call   1050 <insert_max_heap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0xa,%edx
call   1050 <insert_max_heap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x32,%edx
call   1050 <insert_max_heap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1050 <insert_max_heap@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <print_array@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x8,%edx
call   1050 <insert_max_heap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x5,%edx
call   1050 <insert_max_heap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x3,%edx
call   1050 <insert_max_heap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <insert_max_heap@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    $0x64,%edx
call   1050 <insert_max_heap@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <print_array@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <remove_max_heap@plt>
lea    0xded(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <print_array@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <remove_max_heap@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <print_array@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1060 <remove_max_heap@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    0xc(%rsp),%esi
mov    %rbx,%rdi
call   1030 <print_array@plt>
xor    %eax,%eax
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"max size of heap: %d\0A\00"
@.str.1 = [22 x i8] c"Removing element: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i32]
%3 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %3
%4 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 256)
%5 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%6 = call i32 @insert_max_heap(i32* %5, i32* %3, i32 20)
%7 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%8 = call i32 @insert_max_heap(i32* %7, i32* %3, i32 10)
%9 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%10 = call i32 @insert_max_heap(i32* %9, i32* %3, i32 50)
%11 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%12 = call i32 @insert_max_heap(i32* %11, i32* %3, i32 3)
%13 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%14 = load i32, i32* %3
%15 = call i32 @print_array(i32* %13, i32 %14)
%16 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%17 = call i32 @insert_max_heap(i32* %16, i32* %3, i32 8)
%18 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%19 = call i32 @insert_max_heap(i32* %18, i32* %3, i32 5)
%20 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%21 = call i32 @insert_max_heap(i32* %20, i32* %3, i32 3)
%22 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%23 = call i32 @insert_max_heap(i32* %22, i32* %3, i32 1)
%24 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%25 = call i32 @insert_max_heap(i32* %24, i32* %3, i32 100)
%26 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%27 = load i32, i32* %3
%28 = call i32 @print_array(i32* %26, i32 %27)
%29 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%30 = call i32 @remove_max_heap(i32* %29, i32* %3)
%31 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %30)
%32 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%33 = load i32, i32* %3
%34 = call i32 @print_array(i32* %32, i32 %33)
%35 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%36 = call i32 @remove_max_heap(i32* %35, i32* %3)
%37 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %36)
%38 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%39 = load i32, i32* %3
%40 = call i32 @print_array(i32* %38, i32 %39)
%41 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%42 = call i32 @remove_max_heap(i32* %41, i32* %3)
%43 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [256 x i32], [256 x i32]* %2, i64 0, i64 0
%45 = load i32, i32* %3
%46 = call i32 @print_array(i32* %44, i32 %45)
ret i32 0
}

LLVM IR (-O2):
@.str = [22 x i8] c"max size of heap: %d\0A\00"
@.str.1 = [22 x i8] c"Removing element: %d\0A\00"
define i32 @main() {
%1 = alloca [256 x i32]
%2 = alloca i32
%3 = bitcast [256 x i32]* %1 to i8*
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32 256)
%6 = getelementptr inbounds [256 x i32], [256 x i32]* %1, i64 0, i64 0
%7 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 20)
%8 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 10)
%9 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 50)
%10 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 3)
%11 = load i32, i32* %2
%12 = call i32 @print_array(i32* %6, i32 %11)
%13 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 8)
%14 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 5)
%15 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 3)
%16 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 1)
%17 = call i32 @insert_max_heap(i32* %6, i32* %2, i32 100)
%18 = load i32, i32* %2
%19 = call i32 @print_array(i32* %6, i32 %18)
%20 = call i32 @remove_max_heap(i32* %6, i32* %2)
%21 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = load i32, i32* %2
%23 = call i32 @print_array(i32* %6, i32 %22)
%24 = call i32 @remove_max_heap(i32* %6, i32* %2)
%25 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = load i32, i32* %2
%27 = call i32 @print_array(i32* %6, i32 %26)
%28 = call i32 @remove_max_heap(i32* %6, i32* %2)
%29 = call i32 @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %2
%31 = call i32 @print_array(i32* %6, i32 %30)
ret i32 0
}