#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 calcDelay(struct timeval *arrival, struct timeval *origintv,
                 struct timeval *transmittv, struct timeval *receivetv) {
  double dSec, dUsec;
  dSec = ((double)arrival->tv_sec - (double)origintv->tv_sec) -
         ((double)transmittv->tv_sec - (double)receivetv->tv_sec);
  dUsec = ((double)arrival->tv_usec - (double)origintv->tv_usec) -
          ((double)transmittv->tv_usec - (double)receivetv->tv_usec);
  double dTotal = dSec + (dUsec / 1000000);
  return dTotal;
}


x86 assembly (clang, -O0):
<calcDelay>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm0
mov    -0x10(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
subsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
mov    -0x20(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm2
subsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x8(%rbp),%rax
cvtsi2sdq (%rax),%xmm0
mov    -0x10(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
subsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
mov    -0x20(%rbp),%rax
cvtsi2sdq (%rax),%xmm2
subsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xe6c(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<calcDelay>:
movdqu (%rdi),%xmm1
movq   %xmm1,%rax
cvtsi2sd %rax,%xmm0
pshufd $0xee,%xmm1,%xmm1
movq   %xmm1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
unpcklpd %xmm1,%xmm0
movdqu (%rsi),%xmm1
movq   %xmm1,%rax
cvtsi2sd %rax,%xmm2
pshufd $0xee,%xmm1,%xmm1
movq   %xmm1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
unpcklpd %xmm1,%xmm2
subpd  %xmm2,%xmm0
movdqu (%rdx),%xmm1
movq   %xmm1,%rax
xorps  %xmm2,%xmm2
cvtsi2sd %rax,%xmm2
pshufd $0xee,%xmm1,%xmm1
movq   %xmm1,%rax
xorps  %xmm1,%xmm1
cvtsi2sd %rax,%xmm1
movdqu (%rcx),%xmm3
movq   %xmm3,%rax
cvtsi2sd %rax,%xmm4
pshufd $0xee,%xmm3,%xmm3
movq   %xmm3,%rax
xorps  %xmm3,%xmm3
cvtsi2sd %rax,%xmm3
unpcklpd %xmm1,%xmm2
unpcklpd %xmm3,%xmm4
subpd  %xmm4,%xmm2
subpd  %xmm2,%xmm0
movapd %xmm0,%xmm1
divsd  0xe55(%rip),%xmm1
unpckhpd %xmm0,%xmm0
addsd  %xmm1,%xmm0
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @calcDelay(%struct.timeval* %0, %struct.timeval* %1, %struct.timeval* %2, %struct.timeval* %3) {
%5 = alloca %struct.timeval*
%6 = alloca %struct.timeval*
%7 = alloca %struct.timeval*
%8 = alloca %struct.timeval*
%9 = alloca double
%10 = alloca double
%11 = alloca double
store %struct.timeval* %0, %struct.timeval** %5
store %struct.timeval* %1, %struct.timeval** %6
store %struct.timeval* %2, %struct.timeval** %7
store %struct.timeval* %3, %struct.timeval** %8
%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 = sitofp i64 %14 to double
%16 = load %struct.timeval*, %struct.timeval** %6
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 1
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = fsub double %15, %19
%21 = load %struct.timeval*, %struct.timeval** %7
%22 = getelementptr inbounds %struct.timeval, %struct.timeval* %21, i32 0, i32 1
%23 = load i64, i64* %22
%24 = sitofp i64 %23 to double
%25 = load %struct.timeval*, %struct.timeval** %8
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %25, i32 0, i32 1
%27 = load i64, i64* %26
%28 = sitofp i64 %27 to double
%29 = fsub double %24, %28
%30 = fsub double %20, %29
store double %30, double* %9
%31 = load %struct.timeval*, %struct.timeval** %5
%32 = getelementptr inbounds %struct.timeval, %struct.timeval* %31, i32 0, i32 0
%33 = load i64, i64* %32
%34 = sitofp i64 %33 to double
%35 = load %struct.timeval*, %struct.timeval** %6
%36 = getelementptr inbounds %struct.timeval, %struct.timeval* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = sitofp i64 %37 to double
%39 = fsub double %34, %38
%40 = load %struct.timeval*, %struct.timeval** %7
%41 = getelementptr inbounds %struct.timeval, %struct.timeval* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = sitofp i64 %42 to double
%44 = load %struct.timeval*, %struct.timeval** %8
%45 = getelementptr inbounds %struct.timeval, %struct.timeval* %44, i32 0, i32 0
%46 = load i64, i64* %45
%47 = sitofp i64 %46 to double
%48 = fsub double %43, %47
%49 = fsub double %39, %48
store double %49, double* %10
%50 = load double, double* %9
%51 = load double, double* %10
%52 = fdiv double %51, 1.000000e+06
%53 = fadd double %50, %52
store double %53, double* %11
%54 = load double, double* %11
ret double %54
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @calcDelay(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2, %struct.timeval* nocapture %3) {
%5 = bitcast %struct.timeval* %0 to <2 x i64>*
%6 = load <2 x i64>, <2 x i64>* %5
%7 = sitofp <2 x i64> %6 to <2 x double>
%8 = bitcast %struct.timeval* %1 to <2 x i64>*
%9 = load <2 x i64>, <2 x i64>* %8
%10 = sitofp <2 x i64> %9 to <2 x double>
%11 = fsub <2 x double> %7, %10
%12 = bitcast %struct.timeval* %2 to <2 x i64>*
%13 = load <2 x i64>, <2 x i64>* %12
%14 = sitofp <2 x i64> %13 to <2 x double>
%15 = bitcast %struct.timeval* %3 to <2 x i64>*
%16 = load <2 x i64>, <2 x i64>* %15
%17 = sitofp <2 x i64> %16 to <2 x double>
%18 = fsub <2 x double> %14, %17
%19 = fsub <2 x double> %11, %18
%20 = extractelement <2 x double> %19, i64 0
%21 = fdiv double %20, 1.000000e+06
%22 = extractelement <2 x double> %19, i64 1
%23 = fadd double %22, %21
ret double %23
}