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

/* Variables and functions */
int gettimeofday(struct timeval *, int /*<<< orphan*/ *);
double get_time_of_day_in_secs(void) {
  struct timeval tp;
  int errno = gettimeofday(&tp, NULL);
  if (errno == 0) {
    double time_in_secs = (double)tp.tv_sec + (double)tp.tv_usec / 1000000;
    return time_in_secs;
  }
  return -1;
}


x86 assembly (clang, -O0):
<get_time_of_day_in_secs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1162 <get_time_of_day_in_secs+0x52>
cvtsi2sdq -0x10(%rbp),%xmm0
cvtsi2sdq -0x18(%rbp),%xmm1
movsd  0xec2(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    116f <get_time_of_day_in_secs+0x5f>
movsd  0xe96(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_of_day_in_secs>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %eax,%eax
je     1131 <get_time_of_day_in_secs+0x21>
movsd  0xed4(%rip),%xmm0
add    $0x18,%rsp
ret
cvtsi2sdq 0x10(%rsp),%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
divsd  0xec1(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timeval = type { i64, i64 }
define double @get_time_of_day_in_secs() {
%1 = alloca double
%2 = alloca %struct.timeval
%3 = alloca i32
%4 = alloca double
%5 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %18
8: ; preds = %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* %4
%17 = load double, double* %4
store double %17, double* %1
br label %19
18: ; preds = %0
store double -1.000000e+00, double* %1
br label %19
19: ; preds = %18, %8
%20 = load double, double* %1
ret double %20
}

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