#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 double time_t;
struct timeval {
  double tv_sec;
  double tv_usec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double current_time(void) {
  struct timeval tv;
  static time_t start;
  static time_t start_usec;
  gettimeofday(&tv, NULL);
  if (!start) {
    start = tv.tv_sec;
    start_usec = tv.tv_usec;
  }
  return (double)(tv.tv_sec) - start +
         ((double)(tv.tv_usec) - start_usec) / 1000000;
}


x86 assembly (clang, -O0):
<current_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
movsd  0x2f03(%rip),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    115a <current_time+0x4a>
jp     115a <current_time+0x4a>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,0x2ee3(%rip)
movsd  -0x8(%rbp),%xmm0
movsd  %xmm0,0x2ede(%rip)
movsd  -0x10(%rbp),%xmm0
subsd  0x2ec9(%rip),%xmm0
movsd  -0x8(%rbp),%xmm1
subsd  0x2ec4(%rip),%xmm1
movsd  0xe84(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_time>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movsd  0x2f08(%rip),%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
movsd  0x8(%rsp),%xmm1
jne    113a <current_time+0x2a>
jnp    114a <current_time+0x3a>
movsd  0x10(%rsp),%xmm0
movsd  0x2ef0(%rip),%xmm3
jmp    1168 <current_time+0x58>
movsd  %xmm1,0x2ede(%rip)
movsd  0x10(%rsp),%xmm3
movsd  %xmm3,0x2ed8(%rip)
movapd %xmm3,%xmm0
movapd %xmm1,%xmm2
subsd  %xmm3,%xmm0
subsd  %xmm2,%xmm1
divsd  0xe88(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { double, double }
@current_time.start = internal global double 0.000000e+00
@current_time.start_usec = internal global double 0.000000e+00
define double @current_time() {
%1 = alloca %struct.timeval
%2 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%3 = load double, double* @current_time.start
%4 = fcmp une double %3, 0.000000e+00
br i1 %4, label %10, label %5
5: ; preds = %0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%7 = load double, double* %6
store double %7, double* @current_time.start
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%9 = load double, double* %8
store double %9, double* @current_time.start_usec
br label %10
10: ; preds = %5, %0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 0
%12 = load double, double* %11
%13 = load double, double* @current_time.start
%14 = fsub double %12, %13
%15 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i32 0, i32 1
%16 = load double, double* %15
%17 = load double, double* @current_time.start_usec
%18 = fsub double %16, %17
%19 = fdiv double %18, 1.000000e+06
%20 = fadd double %14, %19
ret double %20
}

LLVM IR (-O2):
%struct.timeval = type { double, double }
@current_time.start = internal unnamed_addr global double 0.000000e+00
@current_time.start_usec = internal unnamed_addr global double 0.000000e+00
define double @current_time() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = load double, double* @current_time.start
%5 = fcmp une double %4, 0.000000e+00
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load double, double* %6
br i1 %5, label %8, label %12
8: ; preds = %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load double, double* %9
%11 = load double, double* @current_time.start_usec
br label %15
12: ; preds = %0
store double %7, double* @current_time.start
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%14 = load double, double* %13
store double %14, double* @current_time.start_usec
br label %15
15: ; preds = %8, %12
%16 = phi double [ %11, %8 ], [ %14, %12 ]
%17 = phi double [ %10, %8 ], [ %14, %12 ]
%18 = phi double [ %4, %8 ], [ %7, %12 ]
%19 = fsub double %7, %18
%20 = fsub double %17, %16
%21 = fdiv double %20, 1.000000e+06
%22 = fadd double %19, %21
ret double %22
}