#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 {
  int tv_sec;
  int tv_nsec;
};

/* Variables and functions */
double tv_diff(struct timespec *first, struct timespec *second) {
  double rtn = (second->tv_sec - first->tv_sec) +
               (second->tv_nsec - first->tv_nsec) * 1e-9;
  return rtn;
}


x86 assembly (clang, -O0):
<tv_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm1
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
sub    0x4(%rcx),%eax
cvtsi2sd %eax,%xmm0
movsd  0xeca(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<tv_diff>:
mov    (%rsi),%eax
mov    0x4(%rsi),%ecx
sub    (%rdi),%eax
cvtsi2sd %eax,%xmm1
sub    0x4(%rdi),%ecx
cvtsi2sd %ecx,%xmm0
mulsd  0xee6(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define double @tv_diff(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
%5 = alloca double
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
%6 = load %struct.timespec*, %struct.timespec** %4
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%8 = load i32, i32* %7
%9 = load %struct.timespec*, %struct.timespec** %3
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sub nsw i32 %8, %11
%13 = sitofp i32 %12 to double
%14 = load %struct.timespec*, %struct.timespec** %4
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = load %struct.timespec*, %struct.timespec** %3
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = sub nsw i32 %16, %19
%21 = sitofp i32 %20 to double
%22 = call double @llvm.fmuladd.f64(double %21, double 1.000000e-09, double %13)
store double %22, double* %5
%23 = load double, double* %5
ret double %23
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define double @tv_diff(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%6 = load i32, i32* %5
%7 = sub nsw i32 %4, %6
%8 = sitofp i32 %7 to double
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%12 = load i32, i32* %11
%13 = sub nsw i32 %10, %12
%14 = sitofp i32 %13 to double
%15 = tail call double @llvm.fmuladd.f64(double %14, double 1.000000e-09, double %8)
ret double %15
}