#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 */
typedef scalar_t__ time_t;
struct timeval {
  double tv_usec;
  scalar_t__ tv_sec;
};
typedef double ds;

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double curtime() {
  static time_t base = 0;
  struct timeval tv;
  time_t ds;
  gettimeofday(&tv, NULL);
  if (!base)
    base = tv.tv_sec;
  ds = tv.tv_sec - base;
  return ((ds) + (tv.tv_usec * 0.000001));
}


x86 assembly (clang, -O0):
<curtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpq   $0x0,0x2f03(%rip)
jne    113e <curtime+0x2e>
mov    -0x8(%rbp),%rax
mov    %rax,0x2ef2(%rip)
mov    -0x8(%rbp),%rax
sub    0x2ee7(%rip),%rax
mov    %rax,-0x18(%rbp)
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  0xea0(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<curtime>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f09(%rip),%rcx
mov    0x10(%rsp),%rax
test   %rcx,%rcx
jne    113b <curtime+0x2b>
mov    %rax,0x2ef8(%rip)
mov    %rax,%rcx
sub    %rcx,%rax
cvtsi2sd %rax,%xmm1
movsd  0x8(%rsp),%xmm0
mulsd  0xeaf(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { double, i64 }
@curtime.base = internal global i64 0
define double @curtime() {
%1 = alloca %struct.timeval
%2 = alloca i64
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = load i64, i64* @curtime.base
%5 = icmp ne i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%8 = load i64, i64* %7
store i64 %8, i64* @curtime.base
br label %9
9: ; preds = %6, %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%11 = load i64, i64* %10
%12 = load i64, i64* @curtime.base
%13 = sub nsw i64 %11, %12
store i64 %13, i64* %2
%14 = load i64, i64* %2
%15 = sitofp i64 %14 to double
%16 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%17 = load double, double* %16
%18 = call double @llvm.fmuladd.f64(double %17, double 0x3EB0C6F7A0B5ED8D, double %15)
ret double %18
}

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
@curtime.base = internal unnamed_addr global i64 0
define double @curtime() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = load i64, i64* @curtime.base
%5 = icmp eq i64 %4, 0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%7 = load i64, i64* %6
br i1 %5, label %8, label %9
8: ; preds = %0
store i64 %7, i64* @curtime.base
br label %9
9: ; preds = %0, %8
%10 = phi i64 [ %7, %8 ], [ %4, %0 ]
%11 = sub nsw i64 %7, %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%14 = load double, double* %13
%15 = tail call double @llvm.fmuladd.f64(double %14, double 0x3EB0C6F7A0B5ED8D, double %12)
ret double %15
}