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

/* Variables and functions */
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double microtime() {
  struct timeval tp;
  long sec = 0L;
  double msec = 0.0;
  if (gettimeofday((struct timeval *)&tp, NULL) == 0) {
    msec = (double)(tp.tv_usec / 1000000.00);
    sec = tp.tv_sec;
    if (msec >= 1.0)
      msec -= (long)msec;
    return sec + msec;
  }
  return 0;
}


x86 assembly (clang, -O0):
<microtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movq   $0x0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jne    11a2 <microtime+0x92>
movsd  -0x18(%rbp),%xmm0
movsd  0xebc(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  0xe96(%rip),%xmm1
ucomisd %xmm1,%xmm0
jb     118d <microtime+0x7d>
cvttsd2si -0x28(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  -0x28(%rbp),%xmm0
subsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdq -0x20(%rbp),%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11aa <microtime+0x9a>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<microtime>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
xorps  %xmm0,%xmm0
test   %rax,%rax
je     112d <microtime+0x1d>
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm1
divsd  0xec5(%rip),%xmm1
cvttsd2si %xmm1,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  0xeb8(%rip),%xmm2
cmpnlesd %xmm1,%xmm2
andnpd %xmm0,%xmm2
subsd  %xmm2,%xmm1
xorps  %xmm0,%xmm0
cvtsi2sdq 0x10(%rsp),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timeval = type { double, i64 }
define double @microtime() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %18
5: ; preds = %0
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load double, double* %6
%8 = fdiv double %7, 1.000000e+06
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = fcmp ult double %8, 1.000000e+00
%12 = fptosi double %8 to i64
%13 = sitofp i64 %12 to double
%14 = select i1 %11, double 0.000000e+00, double %13
%15 = fsub double %8, %14
%16 = sitofp i64 %10 to double
%17 = fadd double %15, %16
br label %18
18: ; preds = %0, %5
%19 = phi double [ %17, %5 ], [ 0.000000e+00, %0 ]
ret double %19
}