#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;
  double tv_nsec;
};

/* Variables and functions */
double timespec_diff(struct timespec *a, struct timespec *b) {
  return (((a->tv_sec * 1000000000) + a->tv_nsec) -
          ((b->tv_sec * 1000000000) + b->tv_nsec)) /
         1000000.0;
}


x86 assembly (clang, -O0):
<timespec_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3b9aca00,(%rax),%eax
cvtsi2sd %eax,%xmm0
mov    -0x8(%rbp),%rax
addsd  0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
imul   $0x3b9aca00,(%rax),%eax
cvtsi2sd %eax,%xmm1
mov    -0x10(%rbp),%rax
addsd  0x8(%rax),%xmm1
subsd  %xmm1,%xmm0
movsd  0xeba(%rip),%xmm1
divsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_diff>:
imul   $0x3b9aca00,(%rdi),%eax
cvtsi2sd %eax,%xmm0
addsd  0x8(%rdi),%xmm0
imul   $0x3b9aca00,(%rsi),%eax
cvtsi2sd %eax,%xmm1
addsd  0x8(%rsi),%xmm1
subsd  %xmm1,%xmm0
divsd  0xed6(%rip),%xmm0
ret

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

LLVM IR (-O2):
%struct.timespec = type { i32, double }
define double @timespec_diff(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%4 = load i32, i32* %3
%5 = mul nsw i32 %4, 1000000000
%6 = sitofp i32 %5 to double
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%8 = load double, double* %7
%9 = fadd double %8, %6
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = mul nsw i32 %11, 1000000000
%13 = sitofp i32 %12 to double
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%15 = load double, double* %14
%16 = fadd double %15, %13
%17 = fsub double %9, %16
%18 = fdiv double %17, 1.000000e+06
ret double %18
}