#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 */
typedef scalar_t__ time_t;
struct timeval {
  scalar_t__ tv_sec;
  scalar_t__ tv_usec;
};

/* Variables and functions */
double delta_time(struct timeval *now, struct timeval *before) {
  time_t delta_seconds;
  time_t delta_microseconds;
  delta_seconds = now->tv_sec - before->tv_sec;
  delta_microseconds = now->tv_usec - before->tv_usec;
  if (delta_microseconds < 0) {
    delta_microseconds += 1000000;
    --delta_seconds;
  }
  return ((double)(delta_seconds * 1000) + (double)delta_microseconds / 1000);
}


x86 assembly (clang, -O0):
<delta_time>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x10(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1157 <delta_time+0x57>
mov    -0x20(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x18(%rbp)
imul   $0x3e8,-0x18(%rbp),%rax
cvtsi2sd %rax,%xmm0
cvtsi2sdq -0x20(%rbp),%xmm1
movsd  0xe8e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<delta_time>:
mov    (%rdi),%rax
mov    0x8(%rdi),%rcx
sub    (%rsi),%rax
sub    0x8(%rsi),%rcx
lea    0xf4240(%rcx),%rdx
mov    %rcx,%rsi
sar    $0x3f,%rsi
add    %rax,%rsi
test   %rcx,%rcx
cmovns %rcx,%rdx
imul   $0x3e8,%rsi,%rax
cvtsi2sd %rax,%xmm1
cvtsi2sd %rdx,%xmm0
divsd  0xec1(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @delta_time(%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 = sub i64 %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 = add nsw i64 %12, 1000000
%15 = ashr i64 %12, 63
%16 = add nsw i64 %7, %15
%17 = select i1 %13, i64 %14, i64 %12
%18 = mul nsw i64 %16, 1000
%19 = sitofp i64 %18 to double
%20 = sitofp i64 %17 to double
%21 = fdiv double %20, 1.000000e+03
%22 = fadd double %21, %19
ret double %22
}