#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 */
double difftimeval(struct timeval *old, struct timeval *new) {
  return (new->tv_sec - old->tv_sec) * 1000. +
         (new->tv_usec - old->tv_usec) / 1000;
}


x86 assembly (clang, -O0):
<difftimeval>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm0
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x8(%rbp),%rcx
sub    0x4(%rcx),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm1
movsd  0xec2(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<difftimeval>:
mov    (%rsi),%eax
mov    0x4(%rsi),%ecx
sub    (%rdi),%eax
cvtsi2sd %eax,%xmm0
sub    0x4(%rdi),%ecx
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
cvtsi2sd %eax,%xmm1
mulsd  0xecf(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

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

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