#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 timespec {
  double tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sub_time_hr(struct timespec *, struct timespec *,
                               struct timespec *);
double elapsed_time_hr(struct timespec t1, struct timespec t2, char *title) {
  struct timespec elapsed;
  sub_time_hr(&elapsed, &t1, &t2);
  double elapsed_duration = 0;
  double elapsed_start = 0;
  double elapsed_end = 0;
  elapsed_duration = elapsed.tv_sec + ((double)elapsed.tv_nsec / 1000000000);
  elapsed_start = t1.tv_sec + ((double)t1.tv_nsec / 1000000000);
  elapsed_end = t2.tv_sec + ((double)t2.tv_nsec / 1000000000);
  printf("\n--- %s\n", title);
  printf("--- Timings "
         "---------------------------------------------------------------------"
         "---\n");
  printf("|\n");
  printf("| Start: %.9lf   ", elapsed_start);
  printf("End: %.9lf   ", elapsed_end);
  printf("Duration: %.9lf s\n", elapsed_duration);
  printf("|\n");
  printf("---------------------------------------------------------------------"
         "---------------\n");
  return elapsed_duration;
}


x86 assembly (clang, -O0):
<elapsed_time_hr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x8(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x28(%rbp)
lea    -0x38(%rbp),%rdi
lea    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <sub_time_hr@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x40(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x48(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x38(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
movsd  0xe86(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x40(%rbp)
movsd  -0x10(%rbp),%xmm0
cvtsi2sdq -0x8(%rbp),%xmm1
movsd  0xe66(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x20(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xe46(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe79(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x48(%rbp),%xmm0
lea    0xe69(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x50(%rbp),%xmm0
lea    0xe68(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
lea    0xe63(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movsd  -0x40(%rbp),%xmm0
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_time_hr>:
push   %rbx
sub    $0x50,%rsp
mov    %rdx,%rbx
movsd  %xmm0,0x20(%rsp)
mov    %rdi,0x28(%rsp)
movsd  %xmm1,0x10(%rsp)
mov    %rsi,0x18(%rsp)
lea    0x40(%rsp),%rdi
lea    0x20(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1050 <sub_time_hr@plt>
xorps  %xmm1,%xmm1
cvtsi2sdq 0x48(%rsp),%xmm1
movsd  0xe8c(%rip),%xmm0
divsd  %xmm0,%xmm1
addsd  0x40(%rsp),%xmm1
movsd  %xmm1,0x8(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sdq 0x28(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0x20(%rsp),%xmm1
movsd  %xmm1,0x30(%rsp)
xorps  %xmm1,%xmm1
cvtsi2sdq 0x18(%rsp),%xmm1
divsd  %xmm0,%xmm1
addsd  0x10(%rsp),%xmm1
movsd  %xmm1,0x38(%rsp)
lea    0xe49(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
lea    0xebd(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe26(%rip),%rdi
movsd  0x30(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe24(%rip),%rdi
movsd  0x38(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe1e(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xe6c(%rip),%rdi
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
add    $0x50,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
@.str = [9 x i8] c"\0A--- %s\0A\00"
@.str.1 = [86 x i8] c"--- Timings ------------------------------------------------------------------------\0A\00"
@.str.2 = [3 x i8] c"|\0A\00"
@.str.3 = [18 x i8] c"| Start: %.9lf \00"
@.str.4 = [14 x i8] c"End: %.9lf \00"
@.str.5 = [19 x i8] c"Duration: %.9lf s\0A\00"
@.str.6 = [86 x i8] c"------------------------------------------------------------------------------------\0A\00"
define double @elapsed_time_hr(double %0, i64 %1, double %2, i64 %3, i8* %4) {
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca i8*
%9 = alloca %struct.timespec
%10 = alloca double
%11 = alloca double
%12 = alloca double
%13 = bitcast %struct.timespec* %6 to { double, i64 }*
%14 = getelementptr inbounds { double, i64 }, { double, i64 }* %13, i32 0, i32 0
store double %0, double* %14
%15 = getelementptr inbounds { double, i64 }, { double, i64 }* %13, i32 0, i32 1
store i64 %1, i64* %15
%16 = bitcast %struct.timespec* %7 to { double, i64 }*
%17 = getelementptr inbounds { double, i64 }, { double, i64 }* %16, i32 0, i32 0
store double %2, double* %17
%18 = getelementptr inbounds { double, i64 }, { double, i64 }* %16, i32 0, i32 1
store i64 %3, i64* %18
store i8* %4, i8** %8
%19 = call i32 @sub_time_hr(%struct.timespec* %9, %struct.timespec* %6, %struct.timespec* %7)
store double 0.000000e+00, double* %10
store double 0.000000e+00, double* %11
store double 0.000000e+00, double* %12
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%21 = load double, double* %20
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 1
%23 = load i64, i64* %22
%24 = sitofp i64 %23 to double
%25 = fdiv double %24, 1.000000e+09
%26 = fadd double %21, %25
store double %26, double* %10
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%28 = load double, double* %27
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%30 = load i64, i64* %29
%31 = sitofp i64 %30 to double
%32 = fdiv double %31, 1.000000e+09
%33 = fadd double %28, %32
store double %33, double* %11
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%35 = load double, double* %34
%36 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%37 = load i64, i64* %36
%38 = sitofp i64 %37 to double
%39 = fdiv double %38, 1.000000e+09
%40 = fadd double %35, %39
store double %40, double* %12
%41 = load i8*, i8** %8
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.1, i64 0, i64 0))
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%45 = load double, double* %11
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %45)
%47 = load double, double* %12
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %47)
%49 = load double, double* %10
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %49)
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([86 x i8], [86 x i8]* @.str.6, i64 0, i64 0))
%53 = load double, double* %10
ret double %53
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@.str = [9 x i8] c"\0A--- %s\0A\00"
@.str.3 = [18 x i8] c"| Start: %.9lf \00"
@.str.4 = [14 x i8] c"End: %.9lf \00"
@.str.5 = [19 x i8] c"Duration: %.9lf s\0A\00"
@str = [85 x i8] c"--- Timings ------------------------------------------------------------------------\00"
@str.8 = [2 x i8] c"|\00"
@str.9 = [85 x i8] c"------------------------------------------------------------------------------------\00"
define double @elapsed_time_hr(double %0, i64 %1, double %2, i64 %3, i8* %4) {
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = alloca %struct.timespec
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 0
store double %0, double* %9
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i64 0, i32 1
store i64 %1, i64* %10
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 0
store double %2, double* %11
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i64 0, i32 1
store i64 %3, i64* %12
%13 = bitcast %struct.timespec* %8 to i8*
%14 = call i32 @sub_time_hr(%struct.timespec* %8, %struct.timespec* %6, %struct.timespec* %7)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
%16 = load double, double* %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 1
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = fdiv double %19, 1.000000e+09
%21 = fadd double %16, %20
%22 = load double, double* %9
%23 = load i64, i64* %10
%24 = sitofp i64 %23 to double
%25 = fdiv double %24, 1.000000e+09
%26 = fadd double %22, %25
%27 = load double, double* %11
%28 = load i64, i64* %12
%29 = sitofp i64 %28 to double
%30 = fdiv double %29, 1.000000e+09
%31 = fadd double %27, %30
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %4)
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str, i64 0, i64 0))
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), double %26)
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), double %31)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), double %21)
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.8, i64 0, i64 0))
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @str.9, i64 0, i64 0))
ret double %21
}