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

/* Variables and functions */
double calcdiff(struct timespec t1, struct timespec t2) {
  long diff;
  diff = 1000000 * ((long)t1.tv_sec - (long)t2.tv_sec);
  diff += ((int)t1.tv_nsec - (int)t2.tv_nsec) / 1000;
  return (1e-6 * diff);
}


x86 assembly (clang, -O0):
<calcdiff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
sub    -0x18(%rbp),%rax
imul   $0xf4240,%rax,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
sub    %ecx,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cltq
add    -0x28(%rbp),%rax
mov    %rax,-0x28(%rbp)
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  0xeaf(%rip),%xmm0
mulsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcdiff>:
sub    %rcx,%rsi
imul   $0xf4240,%rsi,%rax
sub    %edx,%edi
movslq %edi,%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rax,%rcx
cvtsi2sd %rcx,%xmm0
mulsd  0xeca(%rip),%xmm0
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define double @calcdiff(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = alloca i64
%8 = bitcast %struct.timespec* %5 to { i64, i64 }*
%9 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 0
store i64 %0, i64* %9
%10 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 1
store i64 %1, i64* %10
%11 = bitcast %struct.timespec* %6 to { i64, i64 }*
%12 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 0
store i64 %2, i64* %12
%13 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 1
store i64 %3, i64* %13
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 1
%17 = load i64, i64* %16
%18 = sub nsw i64 %15, %17
%19 = mul nsw i64 1000000, %18
store i64 %19, i64* %7
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%21 = load i64, i64* %20
%22 = trunc i64 %21 to i32
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i32
%26 = sub nsw i32 %22, %25
%27 = sdiv i32 %26, 1000
%28 = sext i32 %27 to i64
%29 = load i64, i64* %7
%30 = add nsw i64 %29, %28
store i64 %30, i64* %7
%31 = load i64, i64* %7
%32 = sitofp i64 %31 to double
%33 = fmul double 0x3EB0C6F7A0B5ED8D, %32
ret double %33
}

LLVM IR (-O2):
define double @calcdiff(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = sub nsw i64 %1, %3
%6 = mul nsw i64 %5, 1000000
%7 = trunc i64 %0 to i32
%8 = trunc i64 %2 to i32
%9 = sub nsw i32 %7, %8
%10 = sdiv i32 %9, 1000
%11 = sext i32 %10 to i64
%12 = add nsw i64 %6, %11
%13 = sitofp i64 %12 to double
%14 = fmul double %13, 0x3EB0C6F7A0B5ED8D
ret double %14
}