#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*/ adjust_heap_max(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ build_heap_max(int *, int);
double clock();
int /*<<< orphan*/ print_heap(char *, int *, int);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ swap(int *, int /*<<< orphan*/, int);
void heap_sort_max_with_time_shown(int matrix[], int length) {
  double t1, t2;
  int i, j;
  double k;
  t1 = clock();
  int ilength = length;
  print_heap("Before sort:", matrix, length);
  build_heap_max(matrix, length);
  print_heap("Built  heap:", matrix, length);
  for (i = length - 1; i >= 1; i--) {
    swap(matrix, 0, i);
    length--;
    adjust_heap_max(matrix, 0, length);
    print_heap("Sort   heap:", matrix, ilength);
  }
  for (i = 0; i < 10000; i++)
    for (j = 0; j < 10000; j++)
      k = 0.123 * j + 3.567 * i;
  t2 = clock();
  printf("It takes %lf \n", (t2 - t1) / 18.2);
}


x86 assembly (clang, -O0):
<heap_sort_max_with_time_shown>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe89(%rip),%rdi
call   1070 <print_heap@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <build_heap_max@plt>
mov    -0x8(%rbp),%rsi
mov    -0xc(%rbp),%edx
lea    0xe77(%rip),%rdi
call   1070 <print_heap@plt>
mov    -0xc(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x1,-0x24(%rbp)
jl     120c <heap_sort_max_with_time_shown+0xac>
mov    -0x8(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1080 <swap@plt>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1060 <adjust_heap_max@plt>
mov    -0x8(%rbp),%rsi
mov    -0x34(%rbp),%edx
lea    0xe39(%rip),%rdi
call   1070 <print_heap@plt>
mov    -0x24(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x24(%rbp)
jmp    11bc <heap_sort_max_with_time_shown+0x5c>
movl   $0x0,-0x24(%rbp)
cmpl   $0x2710,-0x24(%rbp)
jge    1280 <heap_sort_max_with_time_shown+0x120>
movl   $0x0,-0x28(%rbp)
cmpl   $0x2710,-0x28(%rbp)
jge    126d <heap_sort_max_with_time_shown+0x10d>
cvtsi2sdl -0x28(%rbp),%xmm0
cvtsi2sdl -0x24(%rbp),%xmm2
movsd  0xdca(%rip),%xmm1
mulsd  %xmm2,%xmm1
movsd  0xdb6(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1227 <heap_sort_max_with_time_shown+0xc7>
jmp    1272 <heap_sort_max_with_time_shown+0x112>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1213 <heap_sort_max_with_time_shown+0xb3>
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
subsd  -0x18(%rbp),%xmm0
movsd  0xd62(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xd96(%rip),%rdi
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<heap_sort_max_with_time_shown>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %rdi,%r12
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x8(%rsp)
lea    0xe82(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1070 <print_heap@plt>
mov    %r12,%rdi
mov    %r14d,%esi
call   1040 <build_heap_max@plt>
lea    0xe72(%rip),%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1070 <print_heap@plt>
cmp    $0x2,%r14d
jl     11f1 <heap_sort_max_with_time_shown+0x91>
lea    0x1(%r14),%ebx
lea    0xe63(%rip),%r15
nop
lea    -0x2(%rbx),%ebp
mov    %r12,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1080 <swap@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1060 <adjust_heap_max@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %r14d,%edx
call   1070 <print_heap@plt>
add    $0xffffffff,%ebx
cmp    $0x2,%ebx
ja     11c0 <heap_sort_max_with_time_shown+0x60>
xor    %eax,%eax
call   1030 <clock@plt>
subsd  0x8(%rsp),%xmm0
divsd  0xdfa(%rip),%xmm0
lea    0xe22(%rip),%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1050 <printf@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"Before sort:\00"
@.str.1 = [13 x i8] c"Built heap:\00"
@.str.2 = [13 x i8] c"Sort heap:\00"
@.str.3 = [15 x i8] c"It takes %lf \0A\00"
define void @heap_sort_max_with_time_shown(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca double
%6 = alloca double
%7 = alloca i32
%8 = alloca i32
%9 = alloca double
%10 = alloca i32
store i32* %0, i32** %3
store i32 %1, i32* %4
%11 = call double (...) @clock()
store double %11, double* %5
%12 = load i32, i32* %4
store i32 %12, i32* %10
%13 = load i32*, i32** %3
%14 = load i32, i32* %4
%15 = call i32 @print_heap(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %13, i32 %14)
%16 = load i32*, i32** %3
%17 = load i32, i32* %4
%18 = call i32 @build_heap_max(i32* %16, i32 %17)
%19 = load i32*, i32** %3
%20 = load i32, i32* %4
%21 = call i32 @print_heap(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %19, i32 %20)
%22 = load i32, i32* %4
%23 = sub nsw i32 %22, 1
store i32 %23, i32* %7
br label %24
24: ; preds = %39, %2
%25 = load i32, i32* %7
%26 = icmp sge i32 %25, 1
br i1 %26, label %27, label %42
27: ; preds = %24
%28 = load i32*, i32** %3
%29 = load i32, i32* %7
%30 = call i32 @swap(i32* %28, i32 0, i32 %29)
%31 = load i32, i32* %4
%32 = add nsw i32 %31, -1
store i32 %32, i32* %4
%33 = load i32*, i32** %3
%34 = load i32, i32* %4
%35 = call i32 @adjust_heap_max(i32* %33, i32 0, i32 %34)
%36 = load i32*, i32** %3
%37 = load i32, i32* %10
%38 = call i32 @print_heap(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* %36, i32 %37)
br label %39
39: ; preds = %27
%40 = load i32, i32* %7
%41 = add nsw i32 %40, -1
store i32 %41, i32* %7
br label %24
42: ; preds = %24
store i32 0, i32* %7
br label %43
43: ; preds = %61, %42
%44 = load i32, i32* %7
%45 = icmp slt i32 %44, 10000
br i1 %45, label %46, label %64
46: ; preds = %43
store i32 0, i32* %8
br label %47
47: ; preds = %57, %46
%48 = load i32, i32* %8
%49 = icmp slt i32 %48, 10000
br i1 %49, label %50, label %60
50: ; preds = %47
%51 = load i32, i32* %8
%52 = sitofp i32 %51 to double
%53 = load i32, i32* %7
%54 = sitofp i32 %53 to double
%55 = fmul double 3.567000e+00, %54
%56 = call double @llvm.fmuladd.f64(double 1.230000e-01, double %52, double %55)
store double %56, double* %9
br label %57
57: ; preds = %50
%58 = load i32, i32* %8
%59 = add nsw i32 %58, 1
store i32 %59, i32* %8
br label %47
60: ; preds = %47
br label %61
61: ; preds = %60
%62 = load i32, i32* %7
%63 = add nsw i32 %62, 1
store i32 %63, i32* %7
br label %43
64: ; preds = %43
%65 = call double (...) @clock()
store double %65, double* %6
%66 = load double, double* %6
%67 = load double, double* %5
%68 = fsub double %66, %67
%69 = fdiv double %68, 1.820000e+01
%70 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double %69)
ret void
}

LLVM IR (-O2):
@.str = [13 x i8] c"Before sort:\00"
@.str.1 = [13 x i8] c"Built heap:\00"
@.str.2 = [13 x i8] c"Sort heap:\00"
@.str.3 = [15 x i8] c"It takes %lf \0A\00"
define void @heap_sort_max_with_time_shown(i32* %0, i32 %1) {
%3 = tail call double (...) @clock()
%4 = tail call i32 @print_heap(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32* %0, i32 %1)
%5 = tail call i32 @build_heap_max(i32* %0, i32 %1)
%6 = tail call i32 @print_heap(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32* %0, i32 %1)
%7 = icmp sgt i32 %1, 1
br i1 %7, label %13, label %8
8: ; preds = %13, %2
%9 = tail call double (...) @clock()
%10 = fsub double %9, %3
%11 = fdiv double %10, 1.820000e+01
%12 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), double %11)
ret void
13: ; preds = %2, %13
%14 = phi i32 [ %15, %13 ], [ %1, %2 ]
%15 = add nsw i32 %14, -1
%16 = tail call i32 @swap(i32* %0, i32 0, i32 %15)
%17 = tail call i32 @adjust_heap_max(i32* %0, i32 0, i32 %15)
%18 = tail call i32 @print_heap(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i32* %0, i32 %1)
%19 = icmp ugt i32 %14, 2
br i1 %19, label %13, label %8
}