#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 subtractTimeOfDay(struct timeval *begin, struct timeval *end) {
  double seconds;
  if (end->tv_usec < begin->tv_usec) {
    end->tv_usec += 1000000;
    end->tv_sec -= 1;
  }
  seconds = end->tv_usec - begin->tv_usec;
  seconds /= 1000000.0;
  seconds += (end->tv_sec - begin->tv_sec);
  return seconds;
}


x86 assembly (clang, -O0):
<subtractTimeOfDay>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jge    1141 <subtractTimeOfDay+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
cvtsi2sd %rax,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe9a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x8(%rbp),%rcx
sub    0x8(%rcx),%rax
cvtsi2sd %rax,%xmm0
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<subtractTimeOfDay>:
mov    (%rsi),%rax
mov    (%rdi),%rdx
cmp    %rdx,%rax
jge    1125 <subtractTimeOfDay+0x25>
add    $0xf4240,%rax
mov    %rax,(%rsi)
mov    0x8(%rsi),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rsi)
mov    (%rdi),%rdx
jmp    1129 <subtractTimeOfDay+0x29>
mov    0x8(%rsi),%rcx
sub    %rdx,%rax
cvtsi2sd %rax,%xmm1
divsd  0xec7(%rip),%xmm1
sub    0x8(%rdi),%rcx
cvtsi2sd %rcx,%xmm0
addsd  %xmm1,%xmm0
ret

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

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