#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*/ init_heap(int *, int);
int /*<<< orphan*/ pop();
int /*<<< orphan*/ push(int);
void do_heap_sort2(int arr[], int n) {
  int i;
  init_heap(arr, n);
  for (i = 0; i < n; ++i) {
    push(arr[i]);
  }
  for (i = 0; i < n; ++i) {
    pop();
  }
}


x86 assembly (clang, -O0):
<do_heap_sort2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <init_heap@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    117c <do_heap_sort2+0x4c>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
call   1050 <push@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1152 <do_heap_sort2+0x22>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11a4 <do_heap_sort2+0x74>
mov    $0x0,%al
call   1030 <pop@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1183 <do_heap_sort2+0x53>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_heap_sort2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <init_heap@plt>
test   %ebp,%ebp
jle    117c <do_heap_sort2+0x4c>
mov    %ebp,%r15d
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    (%r14,%rbx,4),%edi
call   1050 <push@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <do_heap_sort2+0x20>
test   %ebp,%ebp
jle    117c <do_heap_sort2+0x4c>
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1030 <pop@plt>
add    $0xffffffff,%ebp
jne    1170 <do_heap_sort2+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @do_heap_sort2(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%6 = load i32*, i32** %3
%7 = load i32, i32* %4
%8 = call i32 @init_heap(i32* %6, i32 %7)
store i32 0, i32* %5
br label %9
9: ; preds = %20, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %23
13: ; preds = %9
%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 @push(i32 %18)
br label %20
20: ; preds = %13
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %9
23: ; preds = %9
store i32 0, i32* %5
br label %24
24: ; preds = %30, %23
%25 = load i32, i32* %5
%26 = load i32, i32* %4
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %33
28: ; preds = %24
%29 = call i32 (...) @pop()
br label %30
30: ; preds = %28
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %24
33: ; preds = %24
ret void
}

LLVM IR (-O2):
define void @do_heap_sort2(i32* %0, i32 %1) {
%3 = tail call i32 @init_heap(i32* %0, i32 %1)
%4 = icmp sgt i32 %1, 0
br i1 %4, label %5, label %20
5: ; preds = %2
%6 = zext i32 %1 to i64
br label %8
7: ; preds = %8
br i1 %4, label %15, label %20
8: ; preds = %5, %8
%9 = phi i64 [ 0, %5 ], [ %13, %8 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %9
%11 = load i32, i32* %10
%12 = tail call i32 @push(i32 %11)
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %6
br i1 %14, label %7, label %8
15: ; preds = %7, %15
%16 = phi i32 [ %18, %15 ], [ 0, %7 ]
%17 = tail call i32 (...) @pop()
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i32 %18, %1
br i1 %19, label %20, label %15
20: ; preds = %15, %2, %7
ret void
}