#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 */
typedef double uint64_t;
struct timespec {
  double tv_nsec;
  double tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ free(struct timespec *);
scalar_t__ malloc(int);
int /*<<< orphan*/ timespec_difference(struct timespec *, struct timespec *,
                                       struct timespec **);
uint64_t timespec_difference_ms(struct timespec *start, struct timespec *end) {
  uint64_t difference = 0;
  struct timespec *temp = (struct timespec *)malloc(sizeof(struct timespec));
  timespec_difference(start, end, &temp);
  difference = temp->tv_nsec / 1.0e6 + temp->tv_sec * 1.0e9;
  free(temp);
  return difference;
}


x86 assembly (clang, -O0):
<timespec_difference_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1030 <timespec_difference@plt>
mov    -0x20(%rbp),%rax
movsd  (%rax),%xmm1
movsd  0xe91(%rip),%xmm0
divsd  %xmm0,%xmm1
mov    -0x20(%rbp),%rax
movsd  0x8(%rax),%xmm0
movsd  0xe74(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <free@plt>
movsd  -0x18(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_difference_ms>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
mov    $0x10,%edi
call   1050 <malloc@plt>
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <timespec_difference@plt>
mov    0x8(%rsp),%rdi
movsd  (%rdi),%xmm0
divsd  0xe93(%rip),%xmm0
movsd  0x8(%rdi),%xmm1
mulsd  0xe8e(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x10(%rsp)
call   1040 <free@plt>
movsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { double, double }
define double @timespec_difference_ms(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
%5 = alloca double
%6 = alloca %struct.timespec*
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
store double 0.000000e+00, double* %5
%7 = call i64 @malloc(i32 16)
%8 = inttoptr i64 %7 to %struct.timespec*
store %struct.timespec* %8, %struct.timespec** %6
%9 = load %struct.timespec*, %struct.timespec** %3
%10 = load %struct.timespec*, %struct.timespec** %4
%11 = call i32 @timespec_difference(%struct.timespec* %9, %struct.timespec* %10, %struct.timespec** %6)
%12 = load %struct.timespec*, %struct.timespec** %6
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 0
%14 = load double, double* %13
%15 = fdiv double %14, 1.000000e+06
%16 = load %struct.timespec*, %struct.timespec** %6
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 1
%18 = load double, double* %17
%19 = call double @llvm.fmuladd.f64(double %18, double 1.000000e+09, double %15)
store double %19, double* %5
%20 = load %struct.timespec*, %struct.timespec** %6
%21 = call i32 @free(%struct.timespec* %20)
%22 = load double, double* %5
ret double %22
}

LLVM IR (-O2):
%struct.timespec = type { double, double }
define double @timespec_difference_ms(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = bitcast %struct.timespec** %3 to i8*
%5 = tail call i64 @malloc(i32 16)
%6 = inttoptr i64 %5 to %struct.timespec*
store %struct.timespec* %6, %struct.timespec** %3
%7 = call i32 @timespec_difference(%struct.timespec* %0, %struct.timespec* %1, %struct.timespec** %3)
%8 = load %struct.timespec*, %struct.timespec** %3
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 0
%10 = load double, double* %9
%11 = fdiv double %10, 1.000000e+06
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i64 0, i32 1
%13 = load double, double* %12
%14 = call double @llvm.fmuladd.f64(double %13, double 1.000000e+09, double %11)
%15 = call i32 @free(%struct.timespec* %8)
ret double %14
}