#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 difference_of_times(struct timeval *time2, struct timeval *time1) {
  struct timeval resultval;
  resultval.tv_sec = time2->tv_sec;
  resultval.tv_usec = time2->tv_usec;
  resultval.tv_sec -= time1->tv_sec;
  resultval.tv_usec -= time1->tv_usec;
  double diff = (double)resultval.tv_sec;
  diff += (double)resultval.tv_usec / 1000000.0;
  return diff;
}


x86 assembly (clang, -O0):
<difference_of_times>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
movsd  0xe9f(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<difference_of_times>:
mov    (%rdi),%rax
mov    0x8(%rdi),%rcx
sub    0x8(%rsi),%rcx
sub    (%rsi),%rax
cvtsi2sd %rcx,%xmm1
cvtsi2sd %rax,%xmm0
divsd  0xee0(%rip),%xmm0
addsd  %xmm1,%xmm0
ret

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

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @difference_of_times(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1) {
%3 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%8 = load i64, i64* %7
%9 = sub nsw i64 %4, %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%11 = load i64, i64* %10
%12 = sub nsw i64 %6, %11
%13 = sitofp i64 %9 to double
%14 = sitofp i64 %12 to double
%15 = fdiv double %14, 1.000000e+06
%16 = fadd double %15, %13
ret double %16
}