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

/* Variables and functions */
int /*<<< orphan*/ timersub(struct timeval *, struct timeval *,
                            struct timeval *);
double timediff(struct timeval *past, struct timeval *present) {
  double ms;
  struct timeval diff;
  timersub(present, past, &diff);
  ms = (double)diff.tv_sec * 1000 + (double)diff.tv_usec / 1000;
  return ms;
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x8(%rbp),%rsi
lea    -0x28(%rbp),%rdx
call   1030 <timersub@plt>
cvtsi2sdq -0x20(%rbp),%xmm0
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  0xebb(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xeaf(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
sub    $0x18,%rsp
mov    %rdi,%rax
lea    0x8(%rsp),%rdx
mov    %rsi,%rdi
mov    %rax,%rsi
call   1030 <timersub@plt>
cvtsi2sdq 0x10(%rsp),%xmm0
cvtsi2sdq 0x8(%rsp),%xmm1
movsd  0xec3(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @timediff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @timersub(%struct.timeval* %1, %struct.timeval* %0, %struct.timeval* %3)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%7 = load i64, i64* %6
%8 = sitofp i64 %7 to double
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = fdiv double %11, 1.000000e+03
%13 = call double @llvm.fmuladd.f64(double %8, double 1.000000e+03, double %12)
ret double %13
}