#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 calcOffset(struct timeval *arrival, struct timeval *origintv,
                  struct timeval *transmittv, struct timeval *receivetv) {
  double oSec, oUsec;
  oSec = ((double)receivetv->tv_sec - (double)origintv->tv_sec) +
         ((double)transmittv->tv_sec - (double)arrival->tv_sec) / 2;
  oUsec = ((double)receivetv->tv_usec - (double)origintv->tv_usec) +
          ((double)transmittv->tv_usec - (double)arrival->tv_usec) / 2;
  double oTotal = oSec + (oUsec / 1000000);
  return oTotal;
}


x86 assembly (clang, -O0):
<calcOffset>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x20(%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    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm2
subsd  %xmm2,%xmm1
movsd  0xebc(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x20(%rbp),%rax
cvtsi2sdq (%rax),%xmm0
mov    -0x10(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
subsd  %xmm1,%xmm0
mov    -0x18(%rbp),%rax
cvtsi2sdq (%rax),%xmm1
mov    -0x8(%rbp),%rax
cvtsi2sdq (%rax),%xmm2
subsd  %xmm2,%xmm1
movsd  0xe7b(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  0xe54(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x38(%rbp),%xmm0
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @calcOffset(%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** %8
%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** %5
%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 = fdiv double %29, 2.000000e+00
%31 = fadd double %20, %30
store double %31, double* %9
%32 = load %struct.timeval*, %struct.timeval** %8
%33 = getelementptr inbounds %struct.timeval, %struct.timeval* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = sitofp i64 %34 to double
%36 = load %struct.timeval*, %struct.timeval** %6
%37 = getelementptr inbounds %struct.timeval, %struct.timeval* %36, i32 0, i32 0
%38 = load i64, i64* %37
%39 = sitofp i64 %38 to double
%40 = fsub double %35, %39
%41 = load %struct.timeval*, %struct.timeval** %7
%42 = getelementptr inbounds %struct.timeval, %struct.timeval* %41, i32 0, i32 0
%43 = load i64, i64* %42
%44 = sitofp i64 %43 to double
%45 = load %struct.timeval*, %struct.timeval** %5
%46 = getelementptr inbounds %struct.timeval, %struct.timeval* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = sitofp i64 %47 to double
%49 = fsub double %44, %48
%50 = fdiv double %49, 2.000000e+00
%51 = fadd double %40, %50
store double %51, double* %10
%52 = load double, double* %9
%53 = load double, double* %10
%54 = fdiv double %53, 1.000000e+06
%55 = fadd double %52, %54
store double %55, double* %11
%56 = load double, double* %11
ret double %56
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @calcOffset(%struct.timeval* nocapture %0, %struct.timeval* nocapture %1, %struct.timeval* nocapture %2, %struct.timeval* nocapture %3) {
%5 = bitcast %struct.timeval* %3 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* %0 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 = fmul <2 x double> %18, <double 5.000000e-01, double 5.000000e-01>
%20 = fadd <2 x double> %11, %19
%21 = extractelement <2 x double> %20, i64 0
%22 = fdiv double %21, 1.000000e+06
%23 = extractelement <2 x double> %20, i64 1
%24 = fadd double %23, %22
ret double %24
}