#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 extract_min(int *);
int /*<<< orphan*/ insert_heap(int *, int);
int /*<<< orphan*/ printf(char *, int);
void heap_sort(int a[], int len) {
  for (int i = 1; i < len; i++) {
    insert_heap(a, a[i]);
  }
  for (int i = 1; i < len; i++) {
  }
  for (int i = 1; i < len; i++) {
    printf("%d ", extract_min(a));
  }
}


x86 assembly (clang, -O0):
<heap_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x1,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1174 <heap_sort+0x44>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <insert_heap@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1146 <heap_sort+0x16>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    119a <heap_sort+0x6a>
jmp    118c <heap_sort+0x5c>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    117b <heap_sort+0x4b>
movl   $0x1,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11d2 <heap_sort+0xa2>
mov    -0x8(%rbp),%rdi
call   1030 <extract_min@plt>
mov    %eax,%esi
lea    0xe41(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11a1 <heap_sort+0x71>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heap_sort>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%esi
jl     1197 <heap_sort+0x67>
mov    %esi,%ebp
mov    %rdi,%r14
mov    %esi,%r15d
mov    $0x1,%ebx
nopl   0x0(%rax)
mov    (%r14,%rbx,4),%esi
mov    %r14,%rdi
call   1050 <insert_heap@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <heap_sort+0x20>
cmp    $0x2,%ebp
jl     1197 <heap_sort+0x67>
add    $0xffffffff,%ebp
lea    0xe8c(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1030 <extract_min@plt>
mov    %r15,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
add    $0xffffffff,%ebp
jne    1180 <heap_sort+0x50>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c"%d \00"
define void @heap_sort(i32* %0, i32 %1) {
%3 = icmp sgt i32 %1, 1
br i1 %3, label %4, label %14
4: ; preds = %2
%5 = zext i32 %1 to i64
br label %7
6: ; preds = %7
br i1 %3, label %15, label %14
7: ; preds = %4, %7
%8 = phi i64 [ 1, %4 ], [ %12, %7 ]
%9 = getelementptr inbounds i32, i32* %0, i64 %8
%10 = load i32, i32* %9
%11 = tail call i32 @insert_heap(i32* %0, i32 %10)
%12 = add nuw nsw i64 %8, 1
%13 = icmp eq i64 %12, %5
br i1 %13, label %6, label %7
14: ; preds = %15, %2, %6
ret void
15: ; preds = %6, %15
%16 = phi i32 [ %19, %15 ], [ 1, %6 ]
%17 = tail call i32 @extract_min(i32* %0)
%18 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i32 %16, 1
%20 = icmp eq i32 %19, %1
br i1 %20, label %14, label %15
}