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

/* Variables and functions */
int gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ perror(char *);
double wtime(void) {
  double now_time;
  struct timeval etstart;
  struct timezone tzp;
  if (gettimeofday(&etstart, &tzp) == -1)
    perror("Error: calling gettimeofday() not successful.\n");
  now_time = ((double)etstart.tv_sec) + ((double)etstart.tv_usec) / 1000000.0;
  return now_time;
}


x86 assembly (clang, -O0):
<wtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
jne    114a <wtime+0x2a>
lea    0xec3(%rip),%rdi
call   1040 <perror@plt>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xea2(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wtime>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <gettimeofday@plt>
cmp    $0xffffffff,%eax
je     1155 <wtime+0x35>
cvtsi2sdq 0x10(%rsp),%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
divsd  0xeb4(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret
lea    0xeac(%rip),%rdi
call   1040 <perror@plt>
jmp    1136 <wtime+0x16>

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@.str = [47 x i8] c"Error: calling gettimeofday() not successful.\0A\00"
define double @wtime() {
%1 = alloca double
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%10 = load i64, i64* %9
%11 = sitofp i64 %10 to double
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = fdiv double %14, 1.000000e+06
%16 = fadd double %11, %15
store double %16, double* %1
%17 = load double, double* %1
ret double %17
}

LLVM IR (-O2):
%struct.timeval = type { i64, i64 }
%struct.timezone = type { i32 }
@.str = [47 x i8] c"Error: calling gettimeofday() not successful.\0A\00"
define double @wtime() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timezone
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timezone* %2 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %1, %struct.timezone* %2)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%14 = load i64, i64* %13
%15 = sitofp i64 %14 to double
%16 = fdiv double %15, 1.000000e+06
%17 = fadd double %16, %12
ret double %17
}