#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*/ InsereEmHeap(int, int *);
int /*<<< orphan*/ SacodeHeap(int, int *);
int /*<<< orphan*/ debug(char *, int *);
void Heapsort(int n, int v[]) {
  int m;
  debug("Inicio: ", v);
  for (m = 1; m < n; m++)
    InsereEmHeap(m, v);
  for (m = n; m > 1; m--) {
    int t = v[1];
    v[1] = v[m];
    v[m] = t;
    SacodeHeap(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    -0x10(%rbp),%rsi
lea    0xeb6(%rip),%rdi
call   1030 <debug@plt>
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    117c <Heapsort+0x4c>
mov    -0x14(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1050 <InsereEmHeap@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1156 <Heapsort+0x26>
mov    -0x4(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jle    11d3 <Heapsort+0xa3>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x14(%rbp),%edi
sub    $0x1,%edi
mov    -0x10(%rbp),%rsi
call   1040 <SacodeHeap@plt>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
jmp    1182 <Heapsort+0x52>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<Heapsort>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %edi,%r14d
lea    0xebf(%rip),%rdi
call   1030 <debug@plt>
cmp    $0x2,%r14d
jl     11a4 <Heapsort+0x74>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1050 <InsereEmHeap@plt>
add    $0x1,%ebp
cmp    %ebp,%r14d
jne    1160 <Heapsort+0x30>
cmp    $0x2,%r14d
jl     11a4 <Heapsort+0x74>
mov    %r14d,%ebp
nopl   0x0(%rax,%rax,1)
mov    0x4(%rbx),%eax
mov    (%rbx,%rbp,4),%ecx
mov    %ecx,0x4(%rbx)
mov    %eax,(%rbx,%rbp,4)
lea    -0x1(%rbp),%r14
mov    %r14d,%edi
mov    %rbx,%rsi
call   1040 <SacodeHeap@plt>
cmp    $0x2,%rbp
mov    %r14,%rbp
ja     1180 <Heapsort+0x50>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"Inicio: \00"
define void @Heapsort(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** %4
%8 = call i32 @debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %7)
store i32 1, i32* %5
br label %9
9: ; preds = %17, %2
%10 = load i32, i32* %5
%11 = load i32, i32* %3
%12 = icmp slt i32 %10, %11
br i1 %12, label %13, label %20
13: ; preds = %9
%14 = load i32, i32* %5
%15 = load i32*, i32** %4
%16 = call i32 @InsereEmHeap(i32 %14, i32* %15)
br label %17
17: ; preds = %13
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
store i32 %19, i32* %5
br label %9
20: ; preds = %9
%21 = load i32, i32* %3
store i32 %21, i32* %5
br label %22
22: ; preds = %45, %20
%23 = load i32, i32* %5
%24 = icmp sgt i32 %23, 1
br i1 %24, label %25, label %48
25: ; preds = %22
%26 = load i32*, i32** %4
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
store i32 %28, i32* %6
%29 = load i32*, i32** %4
%30 = load i32, i32* %5
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i32, i32* %29, i64 %31
%33 = load i32, i32* %32
%34 = load i32*, i32** %4
%35 = getelementptr inbounds i32, i32* %34, i64 1
store i32 %33, i32* %35
%36 = load i32, i32* %6
%37 = load i32*, i32** %4
%38 = load i32, i32* %5
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i32, i32* %37, i64 %39
store i32 %36, i32* %40
%41 = load i32, i32* %5
%42 = sub nsw i32 %41, 1
%43 = load i32*, i32** %4
%44 = call i32 @SacodeHeap(i32 %42, i32* %43)
br label %45
45: ; preds = %25
%46 = load i32, i32* %5
%47 = add nsw i32 %46, -1
store i32 %47, i32* %5
br label %22
48: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"Inicio: \00"
define void @Heapsort(i32 %0, i32* %1) {
%3 = tail call i32 @debug(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32* %1)
%4 = icmp sgt i32 %0, 1
br i1 %4, label %9, label %23
5: ; preds = %9
br i1 %4, label %6, label %23
6: ; preds = %5
%7 = getelementptr inbounds i32, i32* %1, i64 1
%8 = zext i32 %0 to i64
br label %14
9: ; preds = %2, %9
%10 = phi i32 [ %12, %9 ], [ 1, %2 ]
%11 = tail call i32 @InsereEmHeap(i32 %10, i32* %1)
%12 = add nuw nsw i32 %10, 1
%13 = icmp eq i32 %12, %0
br i1 %13, label %5, label %9
14: ; preds = %6, %14
%15 = phi i64 [ %8, %6 ], [ %19, %14 ]
%16 = load i32, i32* %7
%17 = getelementptr inbounds i32, i32* %1, i64 %15
%18 = load i32, i32* %17
store i32 %18, i32* %7
store i32 %16, i32* %17
%19 = add nsw i64 %15, -1
%20 = trunc i64 %19 to i32
%21 = tail call i32 @SacodeHeap(i32 %20, i32* %1)
%22 = icmp ugt i64 %15, 2
br i1 %22, label %14, label %23
23: ; preds = %14, %2, %5
ret void
}