#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;
  double tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double timerGet(struct timeval *start) {
  struct timeval time;
  gettimeofday(&time, NULL);
  double r;
  if (time.tv_usec < start->tv_usec) {
    time.tv_usec += 1000000;
    time.tv_sec -= 1;
  }
  r = time.tv_sec - start->tv_sec;
  r += (time.tv_usec - start->tv_usec) / 1000000.0;
  return r;
}


x86 assembly (clang, -O0):
<timerGet>:
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>
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
cmp    (%rcx),%rax
jge    115e <timerGet+0x4e>
mov    -0x18(%rbp),%rax
add    $0xf4240,%rax
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xeab(%rip),%xmm1
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
mov    -0x8(%rbp),%rax
subsd  0x8(%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
cvtsi2sd %rax,%xmm0
movsd  0xe7f(%rip),%xmm1
divsd  %xmm1,%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timerGet>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%rdx
mov    (%rbx),%rax
lea    0xf4240(%rdx),%rcx
movsd  0x8(%rsp),%xmm1
cmp    %rax,%rdx
cmovge %rdx,%rcx
jge    1147 <timerGet+0x37>
addsd  0xeb9(%rip),%xmm1
subsd  0x8(%rbx),%xmm1
sub    %rax,%rcx
cvtsi2sd %rcx,%xmm0
divsd  0xeac(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i64, double }
define double @timerGet(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timeval
%4 = alloca double
store %struct.timeval* %0, %struct.timeval** %2
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%7 = load i64, i64* %6
%8 = load %struct.timeval*, %struct.timeval** %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp slt i64 %7, %10
br i1 %11, label %12, label %19
12: ; preds = %1
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%14 = load i64, i64* %13
%15 = add nsw i64 %14, 1000000
store i64 %15, i64* %13
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%17 = load double, double* %16
%18 = fsub double %17, 1.000000e+00
store double %18, double* %16
br label %19
19: ; preds = %12, %1
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%21 = load double, double* %20
%22 = load %struct.timeval*, %struct.timeval** %2
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 1
%24 = load double, double* %23
%25 = fsub double %21, %24
store double %25, double* %4
%26 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load %struct.timeval*, %struct.timeval** %2
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = sub nsw i64 %27, %30
%32 = sitofp i64 %31 to double
%33 = fdiv double %32, 1.000000e+06
%34 = load double, double* %4
%35 = fadd double %34, %33
store double %35, double* %4
%36 = load double, double* %4
ret double %36
}

LLVM IR (-O2):
%struct.timeval = type { i64, double }
define double @timerGet(%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 0
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%8 = load i64, i64* %7
%9 = icmp slt i64 %6, %8
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%11 = load double, double* %10
%12 = add nsw i64 %6, 1000000
%13 = fadd double %11, -1.000000e+00
%14 = select i1 %9, i64 %12, i64 %6
%15 = select i1 %9, double %13, double %11
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
%17 = load double, double* %16
%18 = fsub double %15, %17
%19 = sub nsw i64 %14, %8
%20 = sitofp i64 %19 to double
%21 = fdiv double %20, 1.000000e+06
%22 = fadd double %18, %21
ret double %22
}