#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 {
  long tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
double difftimespec(struct timespec *stop, struct timespec *start) {
  double dsec = difftime(stop->tv_sec, start->tv_sec);
  long dnsec = stop->tv_nsec - start->tv_nsec;
  if (dnsec < 0) {
    return (dsec - 1) + (dnsec + 1000000000) / 1000000000.0;
  } else {
    return dsec + dnsec / 1000000000.0;
  }
}


x86 assembly (clang, -O0):
<difftimespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edi
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%esi
call   1030 <difftime@plt>
movsd  %xmm0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x18(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    118f <difftimespec+0x7f>
movsd  -0x20(%rbp),%xmm0
movsd  0xea6(%rip),%xmm1
subsd  %xmm1,%xmm0
mov    -0x28(%rbp),%rax
add    $0x3b9aca00,%rax
cvtsi2sd %rax,%xmm1
movsd  0xe83(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11af <difftimespec+0x9f>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  0xe5e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<difftimespec>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x8(%rdi),%edi
mov    0x8(%rsi),%esi
call   1030 <difftime@plt>
mov    (%rbx),%rcx
sub    (%r14),%rcx
lea    0x3b9aca00(%rcx),%rax
test   %rcx,%rcx
cmovns %rcx,%rax
jns    1143 <difftimespec+0x33>
addsd  0xebd(%rip),%xmm0
cvtsi2sd %rax,%xmm1
divsd  0xeb8(%rip),%xmm1
addsd  %xmm0,%xmm1
movapd %xmm1,%xmm0
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
define double @difftimespec(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%4 = load i32, i32* %3
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%6 = load i32, i32* %5
%7 = tail call double @difftime(i32 %4, i32 %6)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = sub nsw i64 %9, %11
%13 = icmp slt i64 %12, 0
%14 = fadd double %7, -1.000000e+00
%15 = add nsw i64 %12, 1000000000
%16 = select i1 %13, i64 %15, i64 %12
%17 = select i1 %13, double %14, double %7
%18 = sitofp i64 %16 to double
%19 = fdiv double %18, 1.000000e+09
%20 = fadd double %17, %19
ret double %20
}