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

/* Variables and functions */
double timeval_diff(struct timeval *tv0, struct timeval *tv1) {
  double time1, time2;
  time1 = tv0->tv_sec + (tv0->tv_usec / 1000000.0);
  time2 = tv1->tv_sec + (tv1->tv_usec / 1000000.0);
  time1 = time1 - time2;
  if (time1 < 0)
    time1 = -time1;
  return time1;
}


x86 assembly (clang, -O0):
<timeval_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x8(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xedb(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
movsd  0xeb5(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    1196 <timeval_diff+0x96>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<timeval_diff>:
movsd  (%rdi),%xmm1
movsd  0x8(%rdi),%xmm0
movhpd 0x8(%rsi),%xmm0
divpd  0xeea(%rip),%xmm0
movhpd (%rsi),%xmm1
addpd  %xmm0,%xmm1
movapd %xmm1,%xmm0
unpckhpd %xmm1,%xmm0
subsd  %xmm0,%xmm1
movapd 0xede(%rip),%xmm2
xorpd  %xmm1,%xmm2
xorpd  %xmm3,%xmm3
movapd %xmm1,%xmm0
cmpltsd %xmm3,%xmm0
andpd  %xmm0,%xmm2
andnpd %xmm1,%xmm0
orpd   %xmm2,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
define double @timeval_diff(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca double
%6 = alloca double
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 double, double* %8
%10 = load %struct.timeval*, %struct.timeval** %3
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 1
%12 = load double, double* %11
%13 = fdiv double %12, 1.000000e+06
%14 = fadd double %9, %13
store double %14, double* %5
%15 = load %struct.timeval*, %struct.timeval** %4
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 0
%17 = load double, double* %16
%18 = load %struct.timeval*, %struct.timeval** %4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%20 = load double, double* %19
%21 = fdiv double %20, 1.000000e+06
%22 = fadd double %17, %21
store double %22, double* %6
%23 = load double, double* %5
%24 = load double, double* %6
%25 = fsub double %23, %24
store double %25, double* %5
%26 = load double, double* %5
%27 = fcmp olt double %26, 0.000000e+00
br i1 %27, label %28, label %31
28: ; preds = %2
%29 = load double, double* %5
%30 = fneg double %29
store double %30, double* %5
br label %31
31: ; preds = %28, %2
%32 = load double, double* %5
ret double %32
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
define double @timeval_diff(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%4 = load double, double* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%6 = load double, double* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%8 = load double, double* %7
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load double, double* %9
%11 = insertelement <2 x double> poison, double %6, i64 0
%12 = insertelement <2 x double> %11, double %10, i64 1
%13 = fdiv <2 x double> %12, <double 1.000000e+06, double 1.000000e+06>
%14 = insertelement <2 x double> poison, double %4, i64 0
%15 = insertelement <2 x double> %14, double %8, i64 1
%16 = fadd <2 x double> %15, %13
%17 = shufflevector <2 x double> %16, <2 x double> poison, <2 x i32> <i32 1, i32 undef>
%18 = fsub <2 x double> %16, %17
%19 = extractelement <2 x double> %18, i64 0
%20 = fcmp olt double %19, 0.000000e+00
%21 = fneg double %19
%22 = select i1 %20, double %21, double %19
ret double %22
}