#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 */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double cw_clock_lap(struct timeval *tv) {
  struct timeval lap;
  gettimeofday(&lap, NULL);
  return (((((1000000.0) * (double)((&lap)->tv_sec) +
             (double)(&lap)->tv_usec))) -
          ((((1000000.0) * (double)((tv)->tv_sec) + (double)(tv)->tv_usec)))) /
         1000000.0;
}


x86 assembly (clang, -O0):
<cw_clock_lap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xec3(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
cvtsi2sdq 0x8(%rax),%xmm1
mov    -0x8(%rbp),%rax
cvtsi2sdq (%rax),%xmm2
movsd  0xea0(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
movsd  0xe8c(%rip),%xmm1
divsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cw_clock_lap>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
cvtsi2sdq 0x8(%rsp),%xmm0
cvtsi2sdq (%rsp),%xmm1
movsd  0xec9(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x8(%rbx),%xmm1
cvtsi2sdq (%rbx),%xmm3
mulsd  %xmm2,%xmm1
addsd  %xmm3,%xmm1
subsd  %xmm1,%xmm0
divsd  %xmm2,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @cw_clock_lap(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
store %struct.timeval* %0, %struct.timeval** %2
%4 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%6 = load i64, i64* %5
%7 = sitofp i64 %6 to double
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%9 = load i64, i64* %8
%10 = sitofp i64 %9 to double
%11 = call double @llvm.fmuladd.f64(double 1.000000e+06, double %7, double %10)
%12 = load %struct.timeval*, %struct.timeval** %2
%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** %2
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %16, i32 0, i32 0
%18 = load i64, i64* %17
%19 = sitofp i64 %18 to double
%20 = call double @llvm.fmuladd.f64(double 1.000000e+06, double %15, double %19)
%21 = fsub double %11, %20
%22 = fdiv double %21, 1.000000e+06
ret double %22
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @cw_clock_lap(%struct.timeval* nocapture %0) {
%2 = alloca %struct.timeval
%3 = bitcast %struct.timeval* %2 to i8*
%4 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%6 = load i64, i64* %5
%7 = sitofp i64 %6 to double
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%9 = load i64, i64* %8
%10 = sitofp i64 %9 to double
%11 = tail call double @llvm.fmuladd.f64(double %7, double 1.000000e+06, double %10)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = tail call double @llvm.fmuladd.f64(double %14, double 1.000000e+06, double %17)
%19 = fsub double %11, %18
%20 = fdiv double %19, 1.000000e+06
ret double %20
}