#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 */
double tv_diff(const struct timeval *a, const struct timeval *b) {
  return (double)(a->tv_sec - b->tv_sec) +
         (double)((int)a->tv_usec - (int)b->tv_usec) * 1e-6;
}


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

x86 assembly (clang, -O2):
<tv_diff>:
mov    0x8(%rdi),%rax
sub    0x8(%rsi),%rax
cvtsi2sd %rax,%xmm1
mov    (%rdi),%eax
sub    (%rsi),%eax
cvtsi2sd %eax,%xmm0
mulsd  0xee3(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @tv_diff(%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** %3
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%7 = load i64, i64* %6
%8 = load %struct.timeval*, %struct.timeval** %4
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 1
%10 = load i64, i64* %9
%11 = sub nsw i64 %7, %10
%12 = sitofp i64 %11 to double
%13 = load %struct.timeval*, %struct.timeval** %3
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %13, i32 0, i32 0
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i32
%17 = load %struct.timeval*, %struct.timeval** %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = trunc i64 %19 to i32
%21 = sub nsw i32 %16, %20
%22 = sitofp i32 %21 to double
%23 = call double @llvm.fmuladd.f64(double %22, double 0x3EB0C6F7A0B5ED8D, double %12)
ret double %23
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @tv_diff(%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 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%6 = load i64, i64* %5
%7 = sub nsw i64 %4, %6
%8 = sitofp i64 %7 to double
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%10 = load i64, i64* %9
%11 = trunc i64 %10 to i32
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%13 = load i64, i64* %12
%14 = trunc i64 %13 to i32
%15 = sub nsw i32 %11, %14
%16 = sitofp i32 %15 to double
%17 = tail call double @llvm.fmuladd.f64(double %16, double 0x3EB0C6F7A0B5ED8D, double %8)
ret double %17
}