#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 StopWatch(double started) {
  double now, elapsedTime;
  struct timeval time;
  gettimeofday(&time, NULL);
  now = (double)((double)time.tv_sec * 1000.0) +
        (double)((double)time.tv_usec / 1000.0);
  if (started == 0.0)
    return now;
  elapsedTime = now - started;
  return elapsedTime;
}


x86 assembly (clang, -O0):
<StopWatch>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cvtsi2sdq -0x28(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
movsd  0xec2(%rip),%xmm2
divsd  %xmm2,%xmm1
movsd  0xeb6(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    117e <StopWatch+0x6e>
jp     117e <StopWatch+0x6e>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1197 <StopWatch+0x87>
movsd  -0x18(%rbp),%xmm0
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<StopWatch>:
sub    $0x28,%rsp
movaps %xmm0,0x10(%rsp)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xorps  %xmm0,%xmm0
cvtsi2sdq 0x8(%rsp),%xmm0
cvtsi2sdq (%rsp),%xmm1
movsd  0xec5(%rip),%xmm2
divsd  %xmm2,%xmm1
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xorpd  %xmm1,%xmm1
movapd 0x10(%rsp),%xmm2
cmpeqsd %xmm2,%xmm1
andnpd %xmm2,%xmm1
subsd  %xmm1,%xmm0
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @StopWatch(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca %struct.timeval
store double %0, double* %3
%7 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 1
%9 = load i64, i64* %8
%10 = sitofp i64 %9 to double
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i32 0, i32 0
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = fdiv double %13, 1.000000e+03
%15 = call double @llvm.fmuladd.f64(double %10, double 1.000000e+03, double %14)
store double %15, double* %4
%16 = load double, double* %3
%17 = fcmp oeq double %16, 0.000000e+00
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = load double, double* %4
store double %19, double* %2
br label %25
20: ; preds = %1
%21 = load double, double* %4
%22 = load double, double* %3
%23 = fsub double %21, %22
store double %23, double* %5
%24 = load double, double* %5
store double %24, double* %2
br label %25
25: ; preds = %20, %18
%26 = load double, double* %2
ret double %26
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
define double @StopWatch(double %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 = fdiv double %10, 1.000000e+03
%12 = tail call double @llvm.fmuladd.f64(double %7, double 1.000000e+03, double %11)
%13 = fcmp oeq double %0, 0.000000e+00
%14 = select i1 %13, double 0.000000e+00, double %0
%15 = fsub double %12, %14
ret double %15
}