#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*/ constroiHeap(int, int *);
int /*<<< orphan*/ peneira(int, int *);
int /*<<< orphan*/ troca(int, int);
void heapsort(int n, int v[]) {
  int m;
  constroiHeap(n, v);
  for (m = n; m >= 2; --m) {
    troca(v[1], v[m]);
    peneira(m - 1, v);
  }
}


x86 assembly (clang, -O0):
<heapsort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <constroiHeap@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
jl     118f <heapsort+0x5f>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
call   1050 <troca@plt>
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1040 <peneira@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1151 <heapsort+0x21>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heapsort>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %edi,%ebp
call   1030 <constroiHeap@plt>
cmp    $0x2,%ebp
jl     1174 <heapsort+0x44>
mov    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x4(%r14),%edi
mov    (%r14,%rbp,4),%esi
call   1050 <troca@plt>
lea    -0x1(%rbp),%rbx
mov    %ebx,%edi
mov    %r14,%rsi
call   1040 <peneira@plt>
cmp    $0x2,%rbp
mov    %rbx,%rbp
ja     1150 <heapsort+0x20>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @heapsort(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 @constroiHeap(i32 %6, i32* %7)
%9 = load i32, i32* %3
store i32 %9, i32* %5
br label %10
10: ; preds = %27, %2
%11 = load i32, i32* %5
%12 = icmp sge i32 %11, 2
br i1 %12, label %13, label %30
13: ; preds = %10
%14 = load i32*, i32** %4
%15 = getelementptr inbounds i32, i32* %14, i64 1
%16 = load i32, i32* %15
%17 = load i32*, i32** %4
%18 = load i32, i32* %5
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i32, i32* %17, i64 %19
%21 = load i32, i32* %20
%22 = call i32 @troca(i32 %16, i32 %21)
%23 = load i32, i32* %5
%24 = sub nsw i32 %23, 1
%25 = load i32*, i32** %4
%26 = call i32 @peneira(i32 %24, i32* %25)
br label %27
27: ; preds = %13
%28 = load i32, i32* %5
%29 = add nsw i32 %28, -1
store i32 %29, i32* %5
br label %10
30: ; preds = %10
ret void
}

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