#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 timeval {
  unsigned long tv_sec;
  unsigned long tv_usec;
};

/* Variables and functions */
double elapsed_ms(struct timeval *start, struct timeval *end) {
  unsigned long sec = end->tv_sec - start->tv_sec;
  unsigned long usec = end->tv_usec - start->tv_usec;
  return sec * 1000.0 + usec / 1000.0;
}


x86 assembly (clang, -O0):
<elapsed_ms>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
mov    (%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x8(%rbp),%rcx
mov    0x8(%rcx),%rcx
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
movaps 0xed1(%rip),%xmm3
movq   -0x18(%rbp),%xmm0
punpckldq %xmm3,%xmm0
movapd 0xed0(%rip),%xmm2
subpd  %xmm2,%xmm0
movaps %xmm0,%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
movq   -0x20(%rbp),%xmm1
punpckldq %xmm3,%xmm1
subpd  %xmm2,%xmm1
movaps %xmm1,%xmm2
unpckhpd %xmm1,%xmm1
addsd  %xmm2,%xmm1
movsd  0xe81(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xe75(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_ms>:
mov    (%rsi),%rax
mov    0x8(%rsi),%rcx
sub    (%rdi),%rax
sub    0x8(%rdi),%rcx
movq   %rax,%xmm1
movdqa 0xee5(%rip),%xmm2
punpckldq %xmm2,%xmm1
movapd 0xee9(%rip),%xmm3
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
addsd  %xmm1,%xmm0
movq   %rcx,%xmm1
punpckldq %xmm2,%xmm1
subpd  %xmm3,%xmm1
movapd %xmm1,%xmm2
unpckhpd %xmm1,%xmm2
addsd  %xmm1,%xmm2
movsd  0xec8(%rip),%xmm1
divsd  %xmm1,%xmm2
mulsd  %xmm1,%xmm0
addsd  %xmm2,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @elapsed_ms(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i64
%6 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%7 = load %struct.timeval*, %struct.timeval** %4
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = sub i64 %9, %12
store i64 %13, i64* %5
%14 = load %struct.timeval*, %struct.timeval** %4
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%16 = load i64, i64* %15
%17 = load %struct.timeval*, %struct.timeval** %3
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%19 = load i64, i64* %18
%20 = sub i64 %16, %19
store i64 %20, i64* %6
%21 = load i64, i64* %5
%22 = uitofp i64 %21 to double
%23 = load i64, i64* %6
%24 = uitofp i64 %23 to double
%25 = fdiv double %24, 1.000000e+03
%26 = call double @llvm.fmuladd.f64(double %22, double 1.000000e+03, double %25)
ret double %26
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @elapsed_ms(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = sub i64 %4, %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sub i64 %9, %11
%13 = uitofp i64 %7 to double
%14 = uitofp i64 %12 to double
%15 = fdiv double %14, 1.000000e+03
%16 = tail call double @llvm.fmuladd.f64(double %13, double 1.000000e+03, double %15)
ret double %16
}