#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*/ build_min_heap(int *, int);
int /*<<< orphan*/ min_heap_fixup(int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ print_heap_struct(int *, int);
void min_heap_sort(int arr[], int len) {
  build_min_heap(arr, len);
  print_heap_struct(arr, len);
  for (int i = len - 1; i >= 1; i--) {
    int tmp = arr[i];
    arr[i] = arr[0];
    arr[0] = tmp;
    min_heap_fixup(arr, i - 1, 0);
  }
}


x86 assembly (clang, -O0):
<min_heap_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1050 <build_min_heap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1030 <print_heap_struct@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
cmpl   $0x1,-0x10(%rbp)
jl     11b1 <min_heap_sort+0x81>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%esi
sub    $0x1,%esi
xor    %edx,%edx
call   1040 <min_heap_fixup@plt>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    1160 <min_heap_sort+0x30>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<min_heap_sort>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1050 <build_min_heap@plt>
mov    %r14,%rdi
mov    %ebp,%esi
call   1030 <print_heap_struct@plt>
cmp    $0x2,%ebp
jl     118a <min_heap_sort+0x5a>
mov    %ebp,%ebx
add    $0xfffffffe,%ebp
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
lea    -0x2(%rbx),%eax
mov    (%r14,%rax,4),%ecx
mov    (%r14),%edx
mov    %edx,(%r14,%rax,4)
mov    %ecx,(%r14)
mov    %r14,%rdi
mov    %ebp,%esi
xor    %edx,%edx
call   1040 <min_heap_fixup@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
ja     1160 <min_heap_sort+0x30>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @min_heap_sort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%7 = load i32*, i32** %3
%8 = load i32, i32* %4
%9 = call i32 @build_min_heap(i32* %7, i32 %8)
%10 = load i32*, i32** %3
%11 = load i32, i32* %4
%12 = call i32 @print_heap_struct(i32* %10, i32 %11)
%13 = load i32, i32* %4
%14 = sub nsw i32 %13, 1
store i32 %14, i32* %5
br label %15
15: ; preds = %38, %2
%16 = load i32, i32* %5
%17 = icmp sge i32 %16, 1
br i1 %17, label %18, label %41
18: ; preds = %15
%19 = load i32*, i32** %3
%20 = load i32, i32* %5
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32, i32* %19, i64 %21
%23 = load i32, i32* %22
store i32 %23, i32* %6
%24 = load i32*, i32** %3
%25 = getelementptr inbounds i32, i32* %24, i64 0
%26 = load i32, i32* %25
%27 = load i32*, i32** %3
%28 = load i32, i32* %5
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
store i32 %26, i32* %30
%31 = load i32, i32* %6
%32 = load i32*, i32** %3
%33 = getelementptr inbounds i32, i32* %32, i64 0
store i32 %31, i32* %33
%34 = load i32*, i32** %3
%35 = load i32, i32* %5
%36 = sub nsw i32 %35, 1
%37 = call i32 @min_heap_fixup(i32* %34, i32 %36, i32 0)
br label %38
38: ; preds = %18
%39 = load i32, i32* %5
%40 = add nsw i32 %39, -1
store i32 %40, i32* %5
br label %15
41: ; preds = %15
ret void
}

LLVM IR (-O2):
define void @min_heap_sort(i32* %0, i32 %1) {
%3 = tail call i32 @build_min_heap(i32* %0, i32 %1)
%4 = tail call i32 @print_heap_struct(i32* %0, i32 %1)
%5 = icmp sgt i32 %1, 1
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = zext i32 %1 to i64
br label %9
8: ; preds = %9, %2
ret void
9: ; preds = %6, %9
%10 = phi i64 [ %7, %6 ], [ %12, %9 ]
%11 = trunc i64 %10 to i32
%12 = add nsw i64 %10, -1
%13 = and i64 %12, 4294967295
%14 = getelementptr inbounds i32, i32* %0, i64 %13
%15 = load i32, i32* %14
%16 = load i32, i32* %0
store i32 %16, i32* %14
store i32 %15, i32* %0
%17 = add nsw i32 %11, -2
%18 = tail call i32 @min_heap_fixup(i32* %0, i32 %17, i32 0)
%19 = icmp ugt i64 %10, 2
br i1 %19, label %9, label %8
}