#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 */
void loopPeriodSec(double *period, struct timespec *current,
                   struct timespec *previous) {
  *period = current->tv_sec - previous->tv_sec;
  *period += ((double)(current->tv_nsec - previous->tv_nsec)) / 1000000000;
}


x86 assembly (clang, -O0):
<loopPeriodSec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x18(%rbp),%rax
subsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x18(%rbp),%rcx
sub    0x8(%rcx),%rax
cvtsi2sd %rax,%xmm0
movsd  0xebb(%rip),%xmm1
divsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
addsd  (%rax),%xmm0
movsd  %xmm0,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<loopPeriodSec>:
movsd  (%rsi),%xmm0
subsd  (%rdx),%xmm0
mov    0x8(%rsi),%rax
sub    0x8(%rdx),%rax
cvtsi2sd %rax,%xmm1
divsd  0xee3(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rdi)
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
define void @loopPeriodSec(double* %0, %struct.timespec* %1, %struct.timespec* %2) {
%4 = alloca double*
%5 = alloca %struct.timespec*
%6 = alloca %struct.timespec*
store double* %0, double** %4
store %struct.timespec* %1, %struct.timespec** %5
store %struct.timespec* %2, %struct.timespec** %6
%7 = load %struct.timespec*, %struct.timespec** %5
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%9 = load double, double* %8
%10 = load %struct.timespec*, %struct.timespec** %6
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
%12 = load double, double* %11
%13 = fsub double %9, %12
%14 = load double*, double** %4
store double %13, double* %14
%15 = load %struct.timespec*, %struct.timespec** %5
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = load %struct.timespec*, %struct.timespec** %6
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = sub nsw i64 %17, %20
%22 = sitofp i64 %21 to double
%23 = fdiv double %22, 1.000000e+09
%24 = load double*, double** %4
%25 = load double, double* %24
%26 = fadd double %25, %23
store double %26, double* %24
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, i64 }
define void @loopPeriodSec(double* nocapture writeonly %0, %struct.timespec* nocapture %1, %struct.timespec* nocapture %2) {
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%5 = load double, double* %4
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%7 = load double, double* %6
%8 = fsub double %5, %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sub nsw i64 %10, %12
%14 = sitofp i64 %13 to double
%15 = fdiv double %14, 1.000000e+09
%16 = fadd double %8, %15
store double %16, double* %0
ret void
}