#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 {
  int tv_sec;
  int tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double __attribute__((unused)) elapsed_time_ms(struct timeval *ref_time) {
  struct timeval now;
  gettimeofday(&now, NULL);
  return (now.tv_sec - ref_time->tv_sec) * 1000. +
         (now.tv_usec - ref_time->tv_usec) / 1000.;
}


x86 assembly (clang, -O0):
<elapsed_time_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm0
mov    -0xc(%rbp),%eax
mov    -0x8(%rbp),%rcx
sub    0x4(%rcx),%eax
cvtsi2sd %eax,%xmm1
movsd  0xeb4(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xea8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<elapsed_time_ms>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
sub    (%rbx),%eax
cvtsi2sd %eax,%xmm0
sub    0x4(%rbx),%ecx
cvtsi2sd %ecx,%xmm1
movsd  0xebf(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define double @elapsed_time_ms(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%4 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%6 = load i32, i32* %5
%7 = load %struct.timeval*, %struct.timeval** %2
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i32, i32* %8
%10 = sub nsw i32 %6, %9
%11 = sitofp i32 %10 to double
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load %struct.timeval*, %struct.timeval** %2
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%16 = load i32, i32* %15
%17 = sub nsw i32 %13, %16
%18 = sitofp i32 %17 to double
%19 = fdiv double %18, 1.000000e+03
%20 = call double @llvm.fmuladd.f64(double %11, double 1.000000e+03, double %19)
ret double %20
}

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