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

/* Variables and functions */
double Duration2(struct timeval *xt0, struct timeval *xt1) {
  double sec;
  if (xt0->tv_usec > xt1->tv_usec) {
    xt1->tv_usec += 1000000;
    xt1->tv_sec--;
  }
  sec = ((double)(xt1->tv_usec - xt0->tv_usec) * 0.000001) +
        (xt1->tv_sec - xt0->tv_sec);
  return (sec);
}


x86 assembly (clang, -O0):
<Duration2>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jle    1147 <Duration2+0x47>
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0xf4240,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
movsd  0xec3(%rip),%xmm0
addsd  0x8(%rax),%xmm0
movsd  %xmm0,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
cvtsi2sd %rax,%xmm0
mov    -0x10(%rbp),%rax
movsd  0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm1
movsd  0xe94(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<Duration2>:
mov    (%rdi),%rcx
mov    (%rsi),%rax
cmp    %rax,%rcx
jle    112b <Duration2+0x2b>
add    $0xf4240,%rax
mov    %rax,(%rsi)
movsd  0x8(%rsi),%xmm1
addsd  0xedf(%rip),%xmm1
movsd  %xmm1,0x8(%rsi)
mov    (%rdi),%rcx
jmp    1130 <Duration2+0x30>
movsd  0x8(%rsi),%xmm1
sub    %rcx,%rax
cvtsi2sd %rax,%xmm0
subsd  0x8(%rdi),%xmm1
mulsd  0xec3(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, double }
define double @Duration2(%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** %3
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%8 = load i64, i64* %7
%9 = load %struct.timeval*, %struct.timeval** %4
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = icmp sgt 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 double, double* %19
%21 = fadd double %20, -1.000000e+00
store double %21, double* %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
%31 = load %struct.timeval*, %struct.timeval** %4
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 1
%33 = load double, double* %32
%34 = load %struct.timeval*, %struct.timeval** %3
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %34, i32 0, i32 1
%36 = load double, double* %35
%37 = fsub double %33, %36
%38 = call double @llvm.fmuladd.f64(double %30, double 0x3EB0C6F7A0B5ED8D, double %37)
store double %38, double* %5
%39 = load double, double* %5
ret double %39
}

LLVM IR (-O2):
%struct.timeval = type { i64, double }
define double @Duration2(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = icmp sgt 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 double, double* %9
br label %17
11: ; preds = %2
%12 = add nsw i64 %6, 1000000
store i64 %12, i64* %5
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%14 = load double, double* %13
%15 = fadd double %14, -1.000000e+00
store double %15, double* %13
%16 = load i64, i64* %3
br label %17
17: ; preds = %8, %11
%18 = phi double [ %15, %11 ], [ %10, %8 ]
%19 = phi i64 [ %16, %11 ], [ %4, %8 ]
%20 = phi i64 [ %12, %11 ], [ %6, %8 ]
%21 = sub nsw i64 %20, %19
%22 = sitofp i64 %21 to double
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%24 = load double, double* %23
%25 = fsub double %18, %24
%26 = tail call double @llvm.fmuladd.f64(double %22, double 0x3EB0C6F7A0B5ED8D, double %25)
ret double %26
}