#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 */
float timediff(const struct timeval *thistime, const struct timeval *lasttime) {
  float diff;
  diff = ((double)thistime->tv_sec * 1.0e6 + (double)thistime->tv_usec -
          (double)lasttime->tv_sec * 1.0e6 - (double)lasttime->tv_usec) /
         1.0e6;
  return diff;
}


x86 assembly (clang, -O0):
<timediff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
cvtsi2sdq (%rax),%xmm0
movsd  0xed9(%rip),%xmm2
mulsd  %xmm2,%xmm1
addsd  %xmm0,%xmm1
mov    -0x10(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  0xea8(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x10(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
subsd  %xmm1,%xmm0
movsd  0xe8b(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsd2ss %xmm0,%xmm0
movss  %xmm0,-0x14(%rbp)
movss  -0x14(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<timediff>:
cvtsi2sdq 0x8(%rdi),%xmm0
cvtsi2sdq (%rdi),%xmm1
movsd  0xeed(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x8(%rsi),%xmm1
mulsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq (%rsi),%xmm1
subsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
cvtsd2ss %xmm0,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define float @timediff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca float
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%6 = load %struct.timeval*, %struct.timeval** %3
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%8 = load i64, i64* %7
%9 = sitofp i64 %8 to double
%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 = sitofp i64 %12 to double
%14 = call double @llvm.fmuladd.f64(double %9, double 1.000000e+06, double %13)
%15 = load %struct.timeval*, %struct.timeval** %4
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = fneg double %18
%20 = call double @llvm.fmuladd.f64(double %19, double 1.000000e+06, double %14)
%21 = load %struct.timeval*, %struct.timeval** %4
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = sitofp i64 %23 to double
%25 = fsub double %20, %24
%26 = fdiv double %25, 1.000000e+06
%27 = fptrunc double %26 to float
store float %27, float* %5
%28 = load float, float* %5
ret float %28
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define float @timediff(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%4 = load i64, i64* %3
%5 = sitofp i64 %4 to double
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%7 = load i64, i64* %6
%8 = sitofp i64 %7 to double
%9 = tail call double @llvm.fmuladd.f64(double %5, double 1.000000e+06, double %8)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = fneg double %12
%14 = tail call double @llvm.fmuladd.f64(double %13, double 1.000000e+06, double %9)
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = fsub double %14, %17
%19 = fdiv double %18, 1.000000e+06
%20 = fptrunc double %19 to float
ret float %20
}