#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*/ int64_t;

/* Variables and functions */
int /*<<< orphan*/ sorter_heap_sift_down(int /*<<< orphan*/ *,
                                         int /*<<< orphan*/, size_t);
int /*<<< orphan*/ sorter_heapify(int /*<<< orphan*/ *, size_t const);
void sorter_heap_sort(int64_t *dst, const size_t size) {
  size_t end = size - 1;
  if (size <= 1) {
    return;
  }
  sorter_heapify(dst, size);
  while (end > 0) {
    {
      int64_t _sort_swap_temp = (dst[end]);
      (dst[end]) = (dst[0]);
      (dst[0]) = _sort_swap_temp;
    };
    sorter_heap_sift_down(dst, 0, end - 1);
    end--;
  }
}


x86 assembly (clang, -O0):
<sorter_heap_sort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x1,-0x10(%rbp)
ja     114c <sorter_heap_sort+0x2c>
jmp    11b0 <sorter_heap_sort+0x90>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <sorter_heapify@plt>
cmpq   $0x0,-0x18(%rbp)
jbe    11b0 <sorter_heap_sort+0x90>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x1c(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rdx
sub    $0x1,%rdx
xor    %esi,%esi
call   1030 <sorter_heap_sift_down@plt>
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
jmp    1159 <sorter_heap_sort+0x39>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sorter_heap_sort>:
push   %r14
push   %rbx
push   %rax
cmp    $0x2,%rsi
jb     1163 <sorter_heap_sort+0x43>
mov    %rsi,%rbx
mov    %rdi,%r14
call   1040 <sorter_heapify@plt>
add    $0xfffffffffffffffe,%rbx
nopl   0x0(%rax)
mov    0x4(%r14,%rbx,4),%eax
mov    (%r14),%ecx
mov    %ecx,0x4(%r14,%rbx,4)
mov    %eax,(%r14)
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1030 <sorter_heap_sift_down@plt>
add    $0xffffffffffffffff,%rbx
jb     1140 <sorter_heap_sort+0x20>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @sorter_heap_sort(i32* %0, i64 %1) {
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
store i32* %0, i32** %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = sub i64 %7, 1
store i64 %8, i64* %5
%9 = load i64, i64* %4
%10 = icmp ule i64 %9, 1
br i1 %10, label %11, label %12
11: ; preds = %2
br label %39
12: ; preds = %2
%13 = load i32*, i32** %3
%14 = load i64, i64* %4
%15 = call i32 @sorter_heapify(i32* %13, i64 %14)
br label %16
16: ; preds = %19, %12
%17 = load i64, i64* %5
%18 = icmp ugt i64 %17, 0
br i1 %18, label %19, label %39
19: ; preds = %16
%20 = load i32*, i32** %3
%21 = load i64, i64* %5
%22 = getelementptr inbounds i32, i32* %20, 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 i64, i64* %5
%29 = getelementptr inbounds i32, i32* %27, i64 %28
store i32 %26, i32* %29
%30 = load i32, i32* %6
%31 = load i32*, i32** %3
%32 = getelementptr inbounds i32, i32* %31, i64 0
store i32 %30, i32* %32
%33 = load i32*, i32** %3
%34 = load i64, i64* %5
%35 = sub i64 %34, 1
%36 = call i32 @sorter_heap_sift_down(i32* %33, i32 0, i64 %35)
%37 = load i64, i64* %5
%38 = add i64 %37, -1
store i64 %38, i64* %5
br label %16
39: ; preds = %11, %16
ret void
}

LLVM IR (-O2):
define void @sorter_heap_sort(i32* %0, i64 %1) {
%3 = icmp ult i64 %1, 2
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call i32 @sorter_heapify(i32* %0, i64 %1)
%6 = add i64 %1, -1
br label %7
7: ; preds = %4, %7
%8 = phi i64 [ %15, %7 ], [ %6, %4 ]
%9 = phi i64 [ %8, %7 ], [ %1, %4 ]
%10 = getelementptr inbounds i32, i32* %0, i64 %8
%11 = load i32, i32* %10
%12 = load i32, i32* %0
store i32 %12, i32* %10
store i32 %11, i32* %0
%13 = add i64 %9, -2
%14 = tail call i32 @sorter_heap_sift_down(i32* %0, i32 0, i64 %13)
%15 = add i64 %8, -1
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %7
17: ; preds = %7, %2
ret void
}