#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 scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ ConstroiHeap(int *, int, int);
scalar_t__ clock();
double HeapSort(int *vetor, int tamanho) {
  clock_t tempoInicial, tempoFinal;
  int i, troca;
  tempoInicial = clock();
  for (i = tamanho / 2; i >= 0; i--)
    ConstroiHeap(vetor, tamanho, i);
  while (tamanho > 0) {
    troca = vetor[0];
    vetor[0] = vetor[tamanho];
    vetor[tamanho] = troca;
    ConstroiHeap(vetor, --tamanho, 0);
  }
  tempoFinal = clock();
  return ((double)(tempoFinal - tempoInicial) / CLOCKS_PER_SEC) / 1000;
}


x86 assembly (clang, -O0):
<HeapSort>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jl     116f <HeapSort+0x4f>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x24(%rbp),%edx
call   1030 <ConstroiHeap@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    1148 <HeapSort+0x28>
jmp    1174 <HeapSort+0x54>
cmpl   $0x0,-0xc(%rbp)
jle    11bf <HeapSort+0x9f>
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x28(%rbp),%edx
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
add    $0xffffffff,%esi
mov    %esi,-0xc(%rbp)
xor    %edx,%edx
call   1030 <ConstroiHeap@plt>
jmp    1174 <HeapSort+0x54>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e0a(%rip),%rax
divsd  (%rax),%xmm0
movsd  0xe16(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HeapSort>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r12
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%r14
cmp    $0xffffffff,%r15d
jl     1199 <HeapSort+0x79>
mov    %r15d,%ebp
shr    $0x1f,%ebp
add    %r15d,%ebp
sar    %ebp
nopl   0x0(%rax)
mov    %r12,%rdi
mov    %r15d,%esi
mov    %ebp,%edx
call   1030 <ConstroiHeap@plt>
add    $0xffffffff,%ebp
jb     1150 <HeapSort+0x30>
test   %r15d,%r15d
jle    1199 <HeapSort+0x79>
mov    %r15d,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%r12),%eax
mov    (%r12,%rbp,4),%ecx
mov    %ecx,(%r12)
mov    %eax,(%r12,%rbp,4)
lea    -0x1(%rbp),%rbx
mov    %r12,%rdi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <ConstroiHeap@plt>
cmp    $0x1,%rbp
mov    %rbx,%rbp
ja     1170 <HeapSort+0x50>
xor    %eax,%eax
call   1040 <clock@plt>
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e39(%rip),%rax
divsd  (%rax),%xmm0
divsd  0xe45(%rip),%xmm0
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
define double @HeapSort(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%9 = call i64 (...) @clock()
store i64 %9, i64* %5
%10 = load i32, i32* %4
%11 = sdiv i32 %10, 2
store i32 %11, i32* %7
br label %12
12: ; preds = %20, %2
%13 = load i32, i32* %7
%14 = icmp sge i32 %13, 0
br i1 %14, label %15, label %23
15: ; preds = %12
%16 = load i32*, i32** %3
%17 = load i32, i32* %4
%18 = load i32, i32* %7
%19 = call i32 @ConstroiHeap(i32* %16, i32 %17, i32 %18)
br label %20
20: ; preds = %15
%21 = load i32, i32* %7
%22 = add nsw i32 %21, -1
store i32 %22, i32* %7
br label %12
23: ; preds = %12
br label %24
24: ; preds = %27, %23
%25 = load i32, i32* %4
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %47
27: ; preds = %24
%28 = load i32*, i32** %3
%29 = getelementptr inbounds i32, i32* %28, i64 0
%30 = load i32, i32* %29
store i32 %30, i32* %8
%31 = load i32*, i32** %3
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i32, i32* %31, i64 %33
%35 = load i32, i32* %34
%36 = load i32*, i32** %3
%37 = getelementptr inbounds i32, i32* %36, i64 0
store i32 %35, i32* %37
%38 = load i32, i32* %8
%39 = load i32*, i32** %3
%40 = load i32, i32* %4
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i32, i32* %39, i64 %41
store i32 %38, i32* %42
%43 = load i32*, i32** %3
%44 = load i32, i32* %4
%45 = add nsw i32 %44, -1
store i32 %45, i32* %4
%46 = call i32 @ConstroiHeap(i32* %43, i32 %45, i32 0)
br label %24
47: ; preds = %24
%48 = call i64 (...) @clock()
store i64 %48, i64* %6
%49 = load i64, i64* %6
%50 = load i64, i64* %5
%51 = sub nsw i64 %49, %50
%52 = sitofp i64 %51 to double
%53 = load double, double* @CLOCKS_PER_SEC
%54 = fdiv double %52, %53
%55 = fdiv double %54, 1.000000e+03
ret double %55
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
define double @HeapSort(i32* %0, i32 %1) {
%3 = tail call i64 (...) @clock()
%4 = icmp sgt i32 %1, -2
br i1 %4, label %5, label %25
5: ; preds = %2
%6 = sdiv i32 %1, 2
br label %11
7: ; preds = %11
%8 = icmp sgt i32 %1, 0
br i1 %8, label %9, label %25
9: ; preds = %7
%10 = zext i32 %1 to i64
br label %16
11: ; preds = %5, %11
%12 = phi i32 [ %14, %11 ], [ %6, %5 ]
%13 = tail call i32 @ConstroiHeap(i32* %0, i32 %1, i32 %12)
%14 = add nsw i32 %12, -1
%15 = icmp eq i32 %12, 0
br i1 %15, label %7, label %11
16: ; preds = %9, %16
%17 = phi i64 [ %10, %9 ], [ %21, %16 ]
%18 = load i32, i32* %0
%19 = getelementptr inbounds i32, i32* %0, i64 %17
%20 = load i32, i32* %19
store i32 %20, i32* %0
store i32 %18, i32* %19
%21 = add nsw i64 %17, -1
%22 = trunc i64 %21 to i32
%23 = tail call i32 @ConstroiHeap(i32* %0, i32 %22, i32 0)
%24 = icmp ugt i64 %17, 1
br i1 %24, label %16, label %25
25: ; preds = %16, %2, %7
%26 = tail call i64 (...) @clock()
%27 = sub nsw i64 %26, %3
%28 = sitofp i64 %27 to double
%29 = load double, double* @CLOCKS_PER_SEC
%30 = fdiv double %28, %29
%31 = fdiv double %30, 1.000000e+03
ret double %31
}