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

/* Variables and functions */
double tvsub(const struct timeval *a, const struct timeval *b) {
  long sdiff;
  long udiff;
  sdiff = a->tv_sec - b->tv_sec;
  udiff = a->tv_usec - b->tv_usec;
  return (double)(sdiff * 1000000 + udiff) / 1e6;
}


x86 assembly (clang, -O0):
<tvsub>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x20(%rbp)
imul   $0xf4240,-0x18(%rbp),%rax
add    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xeb5(%rip),%xmm1
divsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<tvsub>:
mov    (%rdi),%rax
mov    0x8(%rdi),%rcx
sub    (%rsi),%rax
sub    0x8(%rsi),%rcx
imul   $0xf4240,%rax,%rax
add    %rcx,%rax
cvtsi2sd %rax,%xmm0
divsd  0xedb(%rip),%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @tvsub(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i64
%6 = alloca i64
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
%7 = load %struct.timeval*, %struct.timeval** %3
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load %struct.timeval*, %struct.timeval** %4
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load i64, i64* %11
%13 = sub nsw i64 %9, %12
store i64 %13, i64* %5
%14 = load %struct.timeval*, %struct.timeval** %3
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %14, i32 0, i32 1
%16 = load i64, i64* %15
%17 = load %struct.timeval*, %struct.timeval** %4
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 1
%19 = load i64, i64* %18
%20 = sub nsw i64 %16, %19
store i64 %20, i64* %6
%21 = load i64, i64* %5
%22 = mul nsw i64 %21, 1000000
%23 = load i64, i64* %6
%24 = add nsw i64 %22, %23
%25 = sitofp i64 %24 to double
%26 = fdiv double %25, 1.000000e+06
ret double %26
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @tvsub(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = sub nsw i64 %4, %6
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sub i64 %9, %11
%13 = mul nsw i64 %7, 1000000
%14 = add nsw i64 %12, %13
%15 = sitofp i64 %14 to double
%16 = fdiv double %15, 1.000000e+06
ret double %16
}