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

/* Variables and functions */
double difftv(struct timeval *tv0, struct timeval *tv1) {
  struct timeval diff_tv;
  do {
    (&diff_tv)->tv_sec = (tv0)->tv_sec - (tv1)->tv_sec;
    (&diff_tv)->tv_usec = (tv0)->tv_usec - (tv1)->tv_usec;
    if ((&diff_tv)->tv_usec < 0) {
      --(&diff_tv)->tv_sec;
      (&diff_tv)->tv_usec += 1000000;
    }
  } while (0);
  return (diff_tv.tv_sec + (diff_tv.tv_usec / 1000000.0));
}


x86 assembly (clang, -O0):
<difftv>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsd  (%rax),%xmm0
mov    -0x10(%rbp),%rax
subsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1160 <difftv+0x60>
movsd  0xeb8(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x18(%rbp)
jmp    1165 <difftv+0x65>
movsd  -0x20(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xe90(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<difftv>:
movsd  (%rdi),%xmm1
subsd  (%rsi),%xmm1
mov    0x8(%rdi),%rcx
sub    0x8(%rsi),%rcx
lea    0xf4240(%rcx),%rax
test   %rcx,%rcx
cmovns %rcx,%rax
jns    1128 <difftv+0x28>
addsd  0xed8(%rip),%xmm1
cvtsi2sd %rax,%xmm0
divsd  0xed3(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
define double @difftv(%struct.timeval* %0, %struct.timeval* %1) {
%3 = alloca %struct.timeval*
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %3
store %struct.timeval* %1, %struct.timeval** %4
br label %6
6: ; preds = %2
%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** %4
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%12 = load double, double* %11
%13 = fsub double %9, %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
store double %13, double* %14
%15 = load %struct.timeval*, %struct.timeval** %3
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = load %struct.timeval*, %struct.timeval** %4
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %18, i32 0, i32 1
%20 = load i64, i64* %19
%21 = sub nsw i64 %17, %20
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
store i64 %21, i64* %22
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%24 = load i64, i64* %23
%25 = icmp slt i64 %24, 0
br i1 %25, label %26, label %33
26: ; preds = %6
%27 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%28 = load double, double* %27
%29 = fadd double %28, -1.000000e+00
store double %29, double* %27
%30 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%31 = load i64, i64* %30
%32 = add nsw i64 %31, 1000000
store i64 %32, i64* %30
br label %33
33: ; preds = %26, %6
br label %34
34: ; preds = %33
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%36 = load double, double* %35
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%38 = load i64, i64* %37
%39 = sitofp i64 %38 to double
%40 = fdiv double %39, 1.000000e+06
%41 = fadd double %36, %40
ret double %41
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
define double @difftv(%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* %1, i64 0, i32 0
%6 = load double, double* %5
%7 = fsub double %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 nsw i64 %9, %11
%13 = icmp slt i64 %12, 0
%14 = fadd double %7, -1.000000e+00
%15 = add nsw i64 %12, 1000000
%16 = select i1 %13, i64 %15, i64 %12
%17 = select i1 %13, double %14, double %7
%18 = sitofp i64 %16 to double
%19 = fdiv double %18, 1.000000e+06
%20 = fadd double %17, %19
ret double %20
}