#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 bb_get_time_diff_ms(const struct timespec *start,
                           const struct timespec *finish) {
  if (!start || !finish)
    return 0;
  double rs = (finish->tv_sec - start->tv_sec) * 1e3;
  rs += (finish->tv_nsec - start->tv_nsec) * 1e-6;
  return rs;
}


x86 assembly (clang, -O0):
<bb_get_time_diff_ms>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1122 <bb_get_time_diff_ms+0x22>
cmpq   $0x0,-0x18(%rbp)
jne    112f <bb_get_time_diff_ms+0x2f>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1186 <bb_get_time_diff_ms+0x86>
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm0
movsd  0xec1(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x10(%rbp),%rcx
sub    0x4(%rcx),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  0xe91(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<bb_get_time_diff_ms>:
test   %rdi,%rdi
je     1131 <bb_get_time_diff_ms+0x31>
test   %rsi,%rsi
je     1131 <bb_get_time_diff_ms+0x31>
mov    (%rsi),%eax
mov    0x4(%rsi),%ecx
sub    (%rdi),%eax
cvtsi2sd %eax,%xmm1
mulsd  0xee3(%rip),%xmm1
sub    0x4(%rdi),%ecx
cvtsi2sd %ecx,%xmm0
mulsd  0xedc(%rip),%xmm0
addsd  %xmm1,%xmm0
ret
xorps  %xmm0,%xmm0
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define double @bb_get_time_diff_ms(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca double
%4 = alloca %struct.timespec*
%5 = alloca %struct.timespec*
%6 = alloca double
store %struct.timespec* %0, %struct.timespec** %4
store %struct.timespec* %1, %struct.timespec** %5
%7 = load %struct.timespec*, %struct.timespec** %4
%8 = icmp ne %struct.timespec* %7, null
br i1 %8, label %9, label %12
9: ; preds = %2
%10 = load %struct.timespec*, %struct.timespec** %5
%11 = icmp ne %struct.timespec* %10, null
br i1 %11, label %13, label %12
12: ; preds = %9, %2
store double 0.000000e+00, double* %3
br label %34
13: ; preds = %9
%14 = load %struct.timespec*, %struct.timespec** %5
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %14, i32 0, i32 0
%16 = load i32, i32* %15
%17 = load %struct.timespec*, %struct.timespec** %4
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = sub nsw i32 %16, %19
%21 = sitofp i32 %20 to double
%22 = fmul double %21, 1.000000e+03
store double %22, double* %6
%23 = load %struct.timespec*, %struct.timespec** %5
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load %struct.timespec*, %struct.timespec** %4
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %26, i32 0, i32 1
%28 = load i32, i32* %27
%29 = sub nsw i32 %25, %28
%30 = sitofp i32 %29 to double
%31 = load double, double* %6
%32 = call double @llvm.fmuladd.f64(double %30, double 0x3EB0C6F7A0B5ED8D, double %31)
store double %32, double* %6
%33 = load double, double* %6
store double %33, double* %3
br label %34
34: ; preds = %13, %12
%35 = load double, double* %3
ret double %35
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define double @bb_get_time_diff_ms(%struct.timespec* %0, %struct.timespec* %1) {
%3 = icmp ne %struct.timespec* %0, null
%4 = icmp ne %struct.timespec* %1, null
%5 = and i1 %3, %4
br i1 %5, label %6, label %21
6: ; preds = %2
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%10 = load i32, i32* %9
%11 = sub nsw i32 %8, %10
%12 = sitofp i32 %11 to double
%13 = fmul double %12, 1.000000e+03
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%17 = load i32, i32* %16
%18 = sub nsw i32 %15, %17
%19 = sitofp i32 %18 to double
%20 = tail call double @llvm.fmuladd.f64(double %19, double 0x3EB0C6F7A0B5ED8D, double %13)
br label %21
21: ; preds = %2, %6
%22 = phi double [ %20, %6 ], [ 0.000000e+00, %2 ]
ret double %22
}