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

/* Variables and functions */
double tv_diff(struct timeval *res, struct timeval *x, struct timeval *y) {
  struct timeval r;
  if (!res)
    res = &r;
  res->tv_sec = x->tv_sec - y->tv_sec;
  res->tv_usec = x->tv_usec - y->tv_usec;
  if (res->tv_usec > x->tv_usec)
    res->tv_sec -= 1;
  return (double)res->tv_sec + (double)res->tv_usec / 1000000;
}


x86 assembly (clang, -O0):
<tv_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1123 <tv_diff+0x23>
lea    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jle    1174 <tv_diff+0x74>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm0
mov    -0x8(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
movsd  0xe71(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<tv_diff>:
mov    0x8(%rsi),%r9
sub    0x8(%rdx),%r9
lea    0x8(%rdi),%rcx
test   %rdi,%rdi
lea    -0x10(%rsp),%r8
cmovne %rcx,%r8
mov    %r9,(%r8)
mov    (%rsi),%rcx
lea    -0x8(%rsp),%rax
cmovne %rdi,%rax
sub    (%rdx),%rcx
mov    %rcx,(%rax)
cmp    (%rsi),%rcx
jle    1139 <tv_diff+0x39>
add    $0xffffffffffffffff,%r9
mov    %r9,(%r8)
cvtsi2sd %r9,%xmm1
cvtsi2sd %rcx,%xmm0
divsd  0xeb5(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @tv_diff(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2) {
%4 = alloca %struct.timeval*
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %4
store %struct.timeval* %1, %struct.timeval** %5
store %struct.timeval* %2, %struct.timeval** %6
%8 = load %struct.timeval*, %struct.timeval** %4
%9 = icmp ne %struct.timeval* %8, null
br i1 %9, label %11, label %10
10: ; preds = %3
store %struct.timeval* %7, %struct.timeval** %4
br label %11
11: ; preds = %10, %3
%12 = load %struct.timeval*, %struct.timeval** %5
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
%14 = load i64, i64* %13
%15 = load %struct.timeval*, %struct.timeval** %6
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %15, i32 0, i32 1
%17 = load i64, i64* %16
%18 = sub nsw i64 %14, %17
%19 = load %struct.timeval*, %struct.timeval** %4
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %19, i32 0, i32 1
store i64 %18, i64* %20
%21 = load %struct.timeval*, %struct.timeval** %5
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 0
%23 = load i64, i64* %22
%24 = load %struct.timeval*, %struct.timeval** %6
%25 = getelementptr inbounds %struct.timeval, %struct.timeval* %24, i32 0, i32 0
%26 = load i64, i64* %25
%27 = sub nsw i64 %23, %26
%28 = load %struct.timeval*, %struct.timeval** %4
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
store i64 %27, i64* %29
%30 = load %struct.timeval*, %struct.timeval** %4
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %30, i32 0, i32 0
%32 = load i64, i64* %31
%33 = load %struct.timeval*, %struct.timeval** %5
%34 = getelementptr inbounds %struct.timeval, %struct.timeval* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = icmp sgt i64 %32, %35
br i1 %36, label %37, label %42
37: ; preds = %11
%38 = load %struct.timeval*, %struct.timeval** %4
%39 = getelementptr inbounds %struct.timeval, %struct.timeval* %38, i32 0, i32 1
%40 = load i64, i64* %39
%41 = sub nsw i64 %40, 1
store i64 %41, i64* %39
br label %42
42: ; preds = %37, %11
%43 = load %struct.timeval*, %struct.timeval** %4
%44 = getelementptr inbounds %struct.timeval, %struct.timeval* %43, i32 0, i32 1
%45 = load i64, i64* %44
%46 = sitofp i64 %45 to double
%47 = load %struct.timeval*, %struct.timeval** %4
%48 = getelementptr inbounds %struct.timeval, %struct.timeval* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = sitofp i64 %49 to double
%51 = fdiv double %50, 1.000000e+06
%52 = fadd double %46, %51
ret double %52
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @tv_diff(%struct.timeval* %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2) {
%4 = alloca i64
%5 = alloca i64
%6 = bitcast i64* %4 to i8*
%7 = bitcast i64* %5 to i8*
%8 = icmp eq %struct.timeval* %0, null
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sub nsw i64 %10, %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%15 = select i1 %8, i64* %5, i64* %14
store i64 %13, i64* %15
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%17 = load i64, i64* %16
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%19 = load i64, i64* %18
%20 = sub nsw i64 %17, %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%22 = select i1 %8, i64* %4, i64* %21
store i64 %20, i64* %22
%23 = load i64, i64* %16
%24 = icmp sgt i64 %20, %23
br i1 %24, label %25, label %27
25: ; preds = %3
%26 = add nsw i64 %13, -1
store i64 %26, i64* %15
br label %27
27: ; preds = %25, %3
%28 = phi i64 [ %26, %25 ], [ %13, %3 ]
%29 = sitofp i64 %28 to double
%30 = sitofp i64 %20 to double
%31 = fdiv double %30, 1.000000e+06
%32 = fadd double %31, %29
ret double %32
}