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

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


x86 assembly (clang, -O0):
<wtime>:
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>
cmpl   $0x0,0x2ef8(%rip)
jge    113f <wtime+0x2f>
mov    -0x18(%rbp),%eax
mov    %eax,0x2ee9(%rip)
mov    -0x18(%rbp),%eax
sub    0x2ee0(%rip),%eax
cvtsi2sd %eax,%xmm1
movsd  -0x10(%rbp),%xmm0
movsd  0xea7(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
mov    -0x8(%rbp),%rax
movsd  %xmm0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wtime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x2f00(%rip),%ecx
mov    (%rsp),%eax
test   %ecx,%ecx
jns    1137 <wtime+0x27>
mov    %eax,0x2ef3(%rip)
mov    %eax,%ecx
sub    %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  0x8(%rsp),%xmm1
mulsd  0xeb5(%rip),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

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

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