#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*/ heapify(int *, int);
int /*<<< orphan*/ sift_down(int *, int /*<<< orphan*/, int);
void _heap_sort(int *vet, int size) {
  int start, end;
  heapify(vet, size);
  for (end = size - 1; end > 0; end--) {
    ({
      int t = vet[end];
      vet[end] = vet[0];
      vet[0] = t;
    });
    sift_down(vet, 0, end - 1);
  }
}


x86 assembly (clang, -O0):
<_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   1040 <heapify@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1198 <_heap_sort+0x78>
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x18(%rbp),%eax
mov    -0x8(%rbp),%rcx
mov    %eax,(%rcx)
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
xor    %esi,%esi
call   1030 <sift_down@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1144 <_heap_sort+0x24>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_heap_sort>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <heapify@plt>
cmp    $0x2,%ebp
jl     116a <_heap_sort+0x4a>
mov    %ebp,%ebx
add    $0xfffffffe,%ebp
add    $0x1,%rbx
nopl   0x0(%rax)
lea    -0x2(%rbx),%eax
mov    (%r14,%rax,4),%ecx
mov    (%r14),%edx
mov    %edx,(%r14,%rax,4)
mov    %ecx,(%r14)
mov    %r14,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1030 <sift_down@plt>
add    $0xffffffff,%ebp
add    $0xffffffffffffffff,%rbx
cmp    $0x2,%rbx
ja     1140 <_heap_sort+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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