#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 */
unsigned long tdiff(struct timeval *end, struct timeval *start) {
  long ret;
  ret = 1e9 * (end->tv_sec - start->tv_sec);
  ret += 1e3 * (end->tv_usec - start->tv_usec);
  return ret;
}


x86 assembly (clang, -O0):
<tdiff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%eax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%eax
cvtsi2sd %eax,%xmm1
movsd  0xee4(%rip),%xmm0
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%eax
mov    -0x10(%rbp),%rcx
sub    0x4(%rcx),%eax
cvtsi2sd %eax,%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xeaf(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<tdiff>:
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
sub    (%rsi),%eax
cvtsi2sd %eax,%xmm0
mulsd  0xeed(%rip),%xmm0
cvttsd2si %xmm0,%rax
sub    0x4(%rsi),%ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
cvtsi2sd %rax,%xmm1
mulsd  0xed9(%rip),%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define i64 @tdiff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca i64
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 0
%8 = load i32, i32* %7
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i32, i32* %10
%12 = sub nsw i32 %8, %11
%13 = sitofp i32 %12 to double
%14 = fmul double 1.000000e+09, %13
%15 = fptosi double %14 to i64
store i64 %15, i64* %5
%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 = load %struct.timeval*, %struct.timeval** %4
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %18, %21
%23 = sitofp i32 %22 to double
%24 = load i64, i64* %5
%25 = sitofp i64 %24 to double
%26 = call double @llvm.fmuladd.f64(double 1.000000e+03, double %23, double %25)
%27 = fptosi double %26 to i64
store i64 %27, i64* %5
%28 = load i64, i64* %5
ret i64 %28
}

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