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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double wtime() {
  static int sec = -1;
  struct timeval tv;
  gettimeofday(&tv, NULL);
  if (sec < 0) {
    sec = tv.tv_sec;
  }
  return (tv.tv_sec - sec) + 1.0e-6 * tv.tv_usec;
}


x86 assembly (clang, -O0):
<wtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x10(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmpl   $0x0,0x2efc(%rip)
jge    113b <wtime+0x2b>
mov    -0x10(%rbp),%eax
mov    %eax,0x2eed(%rip)
mov    -0x10(%rbp),%eax
sub    0x2ee4(%rip),%eax
cvtsi2sd %eax,%xmm1
movsd  -0x8(%rbp),%xmm0
movsd  0xeab(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wtime>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f02(%rip),%ecx
mov    0x8(%rsp),%eax
test   %ecx,%ecx
jns    1136 <wtime+0x26>
mov    %eax,0x2ef4(%rip)
mov    %eax,%ecx
sub    %ecx,%eax
cvtsi2sd %eax,%xmm1
movsd  0x10(%rsp),%xmm0
mulsd  0xeb6(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

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

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