#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_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
double fabs(double);
double timeval_diff(struct timeval t1, struct timeval t2) {
  double diff;
  diff = ((double)t2.tv_usec - (double)t1.tv_usec) / 1000000 +
         ((double)t2.tv_sec - (double)t1.tv_sec);
  return fabs(diff);
}


x86 assembly (clang, -O0):
<timeval_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x8(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x18(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
cvtsi2sdq -0x8(%rbp),%xmm1
subsd  %xmm1,%xmm0
movsd  0xee4(%rip),%xmm1
divsd  %xmm1,%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
cvtsi2sdq -0x10(%rbp),%xmm2
subsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movaps 0xeab(%rip),%xmm1
pand   %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_diff>:
cvtsi2sd %rcx,%xmm1
cvtsi2sd %rsi,%xmm0
subsd  %xmm0,%xmm1
divsd  0xeea(%rip),%xmm1
xorps  %xmm0,%xmm0
cvtsi2sd %rdx,%xmm0
cvtsi2sd %rdi,%xmm2
subsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
andpd  0xedd(%rip),%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @timeval_diff(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca double
%8 = bitcast %struct.timeval* %5 to { i64, i64 }*
%9 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 0
store i64 %0, i64* %9
%10 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %8, i32 0, i32 1
store i64 %1, i64* %10
%11 = bitcast %struct.timeval* %6 to { i64, i64 }*
%12 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 0
store i64 %2, i64* %12
%13 = getelementptr inbounds { i64, i64 }, { i64, i64 }* %11, i32 0, i32 1
store i64 %3, i64* %13
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%15 = load i64, i64* %14
%16 = sitofp i64 %15 to double
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = fsub double %16, %19
%21 = fdiv double %20, 1.000000e+06
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%23 = load i64, i64* %22
%24 = sitofp i64 %23 to double
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%26 = load i64, i64* %25
%27 = sitofp i64 %26 to double
%28 = fsub double %24, %27
%29 = fadd double %21, %28
store double %29, double* %7
%30 = load double, double* %7
%31 = call double @llvm.fabs.f64(double %30)
ret double %31
}

LLVM IR (-O2):
define double @timeval_diff(i64 %0, i64 %1, i64 %2, i64 %3) {
%5 = sitofp i64 %3 to double
%6 = sitofp i64 %1 to double
%7 = fsub double %5, %6
%8 = fdiv double %7, 1.000000e+06
%9 = sitofp i64 %2 to double
%10 = sitofp i64 %0 to double
%11 = fsub double %9, %10
%12 = fadd double %11, %8
%13 = tail call double @llvm.fabs.f64(double %12)
ret double %13
}