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

/* Variables and functions */
int /*<<< orphan*/ printf(char *, double);
void print_time(struct timespec *start, struct timespec *end, int iterations,
                double *result) {
  time_t start_s = start->tv_sec;
  time_t end_s = end->tv_sec;
  long start_ns = start->tv_nsec;
  long end_ns = end->tv_nsec;
  double start_time = start_s * 1000000000.0 + start_ns;
  double end_time = end_s * 1000000000.0 + end_ns;
  double average = (end_time - start_time) / ((double)iterations);
  if (result != NULL) {
    *result = average;
  }
  printf("Time between in average is %f\n", average);
}


x86 assembly (clang, -O0):
<print_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdq -0x38(%rbp),%xmm1
movsd  0xe94(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdq -0x40(%rbp),%xmm1
movsd  0xe74(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x50(%rbp)
movsd  -0x50(%rbp),%xmm0
subsd  -0x48(%rbp),%xmm0
cvtsi2sdl -0x14(%rbp),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x58(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11c9 <print_time+0xb9>
movsd  -0x58(%rbp),%xmm0
mov    -0x20(%rbp),%rax
movsd  %xmm0,(%rax)
movsd  -0x58(%rbp),%xmm0
lea    0xe33(%rip),%rdi
call   1030 <printf@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_time>:
cvtsi2sdq 0x8(%rdi),%xmm1
movsd  0xee2(%rip),%xmm0
movsd  (%rdi),%xmm2
mulsd  %xmm0,%xmm2
addsd  %xmm1,%xmm2
xorps  %xmm1,%xmm1
cvtsi2sdq 0x8(%rsi),%xmm1
mulsd  (%rsi),%xmm0
addsd  %xmm1,%xmm0
subsd  %xmm2,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %edx,%xmm1
divsd  %xmm1,%xmm0
test   %rcx,%rcx
je     1153 <print_time+0x43>
movsd  %xmm0,(%rcx)
lea    0xeae(%rip),%rdi
jmp    1030 <printf@plt>

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
@.str = [31 x i8] c"Time between in average is %f\0A\00"
define void @print_time(%struct.timespec* %0, %struct.timespec* %1, i32 %2, double* %3) {
%5 = alloca %struct.timespec*
%6 = alloca %struct.timespec*
%7 = alloca i32
%8 = alloca double*
%9 = alloca double
%10 = alloca double
%11 = alloca i64
%12 = alloca i64
%13 = alloca double
%14 = alloca double
%15 = alloca double
store %struct.timespec* %0, %struct.timespec** %5
store %struct.timespec* %1, %struct.timespec** %6
store i32 %2, i32* %7
store double* %3, double** %8
%16 = load %struct.timespec*, %struct.timespec** %5
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
%18 = load double, double* %17
store double %18, double* %9
%19 = load %struct.timespec*, %struct.timespec** %6
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 0
%21 = load double, double* %20
store double %21, double* %10
%22 = load %struct.timespec*, %struct.timespec** %5
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %22, i32 0, i32 1
%24 = load i64, i64* %23
store i64 %24, i64* %11
%25 = load %struct.timespec*, %struct.timespec** %6
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %25, i32 0, i32 1
%27 = load i64, i64* %26
store i64 %27, i64* %12
%28 = load double, double* %9
%29 = load i64, i64* %11
%30 = sitofp i64 %29 to double
%31 = call double @llvm.fmuladd.f64(double %28, double 1.000000e+09, double %30)
store double %31, double* %13
%32 = load double, double* %10
%33 = load i64, i64* %12
%34 = sitofp i64 %33 to double
%35 = call double @llvm.fmuladd.f64(double %32, double 1.000000e+09, double %34)
store double %35, double* %14
%36 = load double, double* %14
%37 = load double, double* %13
%38 = fsub double %36, %37
%39 = load i32, i32* %7
%40 = sitofp i32 %39 to double
%41 = fdiv double %38, %40
store double %41, double* %15
%42 = load double*, double** %8
%43 = icmp ne double* %42, null
br i1 %43, label %44, label %47
44: ; preds = %4
%45 = load double, double* %15
%46 = load double*, double** %8
store double %45, double* %46
br label %47
47: ; preds = %44, %4
%48 = load double, double* %15
%49 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %48)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
@.str = [31 x i8] c"Time between in average is %f\0A\00"
define void @print_time(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1, i32 %2, double* writeonly %3) {
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%6 = load double, double* %5
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%8 = load double, double* %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %10 to double
%14 = tail call double @llvm.fmuladd.f64(double %6, double 1.000000e+09, double %13)
%15 = sitofp i64 %12 to double
%16 = tail call double @llvm.fmuladd.f64(double %8, double 1.000000e+09, double %15)
%17 = fsub double %16, %14
%18 = sitofp i32 %2 to double
%19 = fdiv double %17, %18
%20 = icmp eq double* %3, null
br i1 %20, label %22, label %21
21: ; preds = %4
store double %19, double* %3
br label %22
22: ; preds = %21, %4
%23 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), double %19)
ret void
}