#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 */
struct timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ HeapSortAsc(int *);
int /*<<< orphan*/ PopulateArrayDes(int *);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, double);
int CalculateTimeHS(int *A) {
  struct timeval tim;
  PopulateArrayDes(A);
  gettimeofday(&tim, NULL);
  double t1 = tim.tv_sec + (tim.tv_usec / 1000000.0);
  HeapSortAsc(A);
  gettimeofday(&tim, NULL);
  double t2 = tim.tv_sec + (tim.tv_usec / 1000000.0);
  printf("Before: %.6lf seconds since epoch\n", t1);
  printf("After: %.6lf seconds since epoch\n", t2);
  printf("Running time: %.6lf seconds\n", t2 - t1);
  return 1;
}


x86 assembly (clang, -O0):
<CalculateTimeHS>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <PopulateArrayDes@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe8c(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <HeapSortAsc@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
movsd  -0x18(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
movsd  0xe57(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe46(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
lea    0xe58(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x28(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CalculateTimeHS>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    %rdi,%rbx
call   1060 <PopulateArrayDes@plt>
lea    0x20(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movsd  0x20(%rsp),%xmm0
movaps %xmm0,(%rsp)
movsd  0x28(%rsp),%xmm0
movaps %xmm0,0x10(%rsp)
mov    %rbx,%rdi
call   1050 <HeapSortAsc@plt>
mov    %r14,%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
movapd 0x20(%rsp),%xmm1
movapd %xmm1,%xmm0
shufpd $0x1,0x10(%rsp),%xmm0
divpd  0xe62(%rip),%xmm0
unpcklpd (%rsp),%xmm1
addpd  %xmm0,%xmm1
movapd %xmm1,(%rsp)
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
movapd %xmm0,0x10(%rsp)
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
lea    0xe66(%rip),%rdi
movaps (%rsp),%xmm0
call   1030 <printf@plt>
movapd (%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
lea    0xe6d(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@.str = [35 x i8] c"Before: %.6lf seconds since epoch\0A\00"
@.str.1 = [34 x i8] c"After: %.6lf seconds since epoch\0A\00"
@.str.2 = [29 x i8] c"Running time: %.6lf seconds\0A\00"
define i32 @CalculateTimeHS(i32* %0) {
%2 = alloca i32*
%3 = alloca %struct.timeval
%4 = alloca double
%5 = alloca double
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @PopulateArrayDes(i32* %6)
%8 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%10 = load double, double* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%12 = load double, double* %11
%13 = fdiv double %12, 1.000000e+06
%14 = fadd double %10, %13
store double %14, double* %4
%15 = load i32*, i32** %2
%16 = call i32 @HeapSortAsc(i32* %15)
%17 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%19 = load double, double* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%21 = load double, double* %20
%22 = fdiv double %21, 1.000000e+06
%23 = fadd double %19, %22
store double %23, double* %5
%24 = load double, double* %4
%25 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %24)
%26 = load double, double* %5
%27 = call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), double %26)
%28 = load double, double* %5
%29 = load double, double* %4
%30 = fsub double %28, %29
%31 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %30)
ret i32 1
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@.str = [35 x i8] c"Before: %.6lf seconds since epoch\0A\00"
@.str.1 = [34 x i8] c"After: %.6lf seconds since epoch\0A\00"
@.str.2 = [29 x i8] c"Running time: %.6lf seconds\0A\00"
define i32 @CalculateTimeHS(i32* %0) {
%2 = alloca <2 x double>
%3 = bitcast <2 x double>* %2 to %struct.timeval*
%4 = bitcast <2 x double>* %2 to i8*
%5 = tail call i32 @PopulateArrayDes(i32* %0)
%6 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%7 = getelementptr inbounds <2 x double>, <2 x double>* %2, i64 0, i64 0
%8 = load double, double* %7
%9 = getelementptr inbounds <2 x double>, <2 x double>* %2, i64 0, i64 1
%10 = load double, double* %9
%11 = tail call i32 @HeapSortAsc(i32* %0)
%12 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%13 = load <2 x double>, <2 x double>* %2
%14 = shufflevector <2 x double> %13, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%15 = insertelement <2 x double> %14, double %10, i64 1
%16 = fdiv <2 x double> %15, <double 1.000000e+06, double 1.000000e+06>
%17 = insertelement <2 x double> %13, double %8, i64 1
%18 = fadd <2 x double> %17, %16
%19 = extractelement <2 x double> %18, i64 1
%20 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), double %19)
%21 = extractelement <2 x double> %18, i64 0
%22 = tail call i32 @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), double %21)
%23 = fsub double %21, %19
%24 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.2, i64 0, i64 0), double %23)
ret i32 1
}