#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 */
double timediff(struct timespec now, struct timespec old) {
  struct timespec diff;
  diff.tv_sec = now.tv_sec - old.tv_sec;
  diff.tv_nsec = now.tv_nsec - old.tv_nsec;
  if (diff.tv_nsec < 0) {
    diff.tv_sec--;
    diff.tv_nsec += (1000 * (1000 * 1000));
  }
  return diff.tv_sec + ((double)diff.tv_nsec / (1000 * (1000 * 1000)));
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
mov    %rdi,-0x8(%rbp)
movsd  %xmm1,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x8(%rbp),%rax
sub    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    115c <timediff+0x5c>
movsd  0xebc(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x28(%rbp),%rax
add    $0x3b9aca00,%rax
mov    %rax,-0x28(%rbp)
movsd  -0x30(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  0xe99(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
subsd  %xmm1,%xmm0
sub    %rsi,%rdi
lea    0x3b9aca00(%rdi),%rax
test   %rdi,%rdi
cmovns %rdi,%rax
jns    111f <timediff+0x1f>
addsd  0xee1(%rip),%xmm0
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
divsd  0xed9(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64 }
define double @timediff(double %0, i64 %1, double %2, i64 %3) {
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = alloca %struct.timespec
%8 = bitcast %struct.timespec* %5 to { double, i64 }*
%9 = getelementptr inbounds { double, i64 }, { double, i64 }* %8, i32 0, i32 0
store double %0, double* %9
%10 = getelementptr inbounds { double, i64 }, { double, i64 }* %8, i32 0, i32 1
store i64 %1, i64* %10
%11 = bitcast %struct.timespec* %6 to { double, i64 }*
%12 = getelementptr inbounds { double, i64 }, { double, i64 }* %11, i32 0, i32 0
store double %2, double* %12
%13 = getelementptr inbounds { double, i64 }, { double, i64 }* %11, i32 0, i32 1
store i64 %3, i64* %13
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%15 = load double, double* %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%17 = load double, double* %16
%18 = fsub double %15, %17
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
store double %18, double* %19
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%21 = load i64, i64* %20
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%23 = load i64, i64* %22
%24 = sub nsw i64 %21, %23
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
store i64 %24, i64* %25
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%27 = load i64, i64* %26
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %36
29: ; preds = %4
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%31 = load double, double* %30
%32 = fadd double %31, -1.000000e+00
store double %32, double* %30
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%34 = load i64, i64* %33
%35 = add nsw i64 %34, 1000000000
store i64 %35, i64* %33
br label %36
36: ; preds = %29, %4
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%38 = load double, double* %37
%39 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
%40 = load i64, i64* %39
%41 = sitofp i64 %40 to double
%42 = fdiv double %41, 1.000000e+09
%43 = fadd double %38, %42
ret double %43
}

LLVM IR (-O2):
define double @timediff(double %0, i64 %1, double %2, i64 %3) {
%5 = fsub double %0, %2
%6 = sub nsw i64 %1, %3
%7 = icmp slt i64 %6, 0
%8 = fadd double %5, -1.000000e+00
%9 = add nsw i64 %6, 1000000000
%10 = select i1 %7, i64 %9, i64 %6
%11 = select i1 %7, double %8, double %5
%12 = sitofp i64 %10 to double
%13 = fdiv double %12, 1.000000e+09
%14 = fadd double %11, %13
ret double %14
}