#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ display_restore();
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
scalar_t__ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *strerror(int);
double timeval_to_double(struct timeval *);
double gettime_to_double(void) {
  struct timeval tv;
  if (gettimeofday(&tv, NULL) < 0) {
    display_restore();
    (void)fprintf(stderr, "gettimeofday failed: errno=%d (%s)\n", errno,
                  strerror(errno));
    exit(EXIT_FAILURE);
  }
  return timeval_to_double(&tv);
}


x86 assembly (clang, -O0):
<gettime_to_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
cmp    $0x0,%rax
jge    11cf <gettime_to_double+0x6f>
mov    $0x0,%al
call   1070 <display_restore@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1080 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    %rax,%rcx
lea    0xe44(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
lea    -0x8(%rbp),%rdi
call   1040 <timeval_to_double@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime_to_double>:
push   %rbp
push   %rbx
push   %rax
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
test   %rax,%rax
js     1181 <gettime_to_double+0x21>
mov    %rsp,%rdi
call   1040 <timeval_to_double@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
xor    %eax,%eax
call   1070 <display_restore@plt>
mov    0x2e51(%rip),%rax
mov    (%rax),%ebx
mov    0x2e40(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,%edi
call   1080 <strerror@plt>
lea    0xe58(%rip),%rsi
mov    %ebx,%edi
mov    %ebp,%edx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@stderr = global i32 0
@.str = [36 x i8] c"gettimeofday failed: errno=%d (%s)\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define double @gettime_to_double() {
%1 = alloca %struct.timeval
%2 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%3 = icmp slt i64 %2, 0
br i1 %3, label %4, label %13
4: ; preds = %0
%5 = call i32 (...) @display_restore()
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = call double @timeval_to_double(%struct.timeval* %1)
ret double %14
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@stderr = global i32 0
@.str = [36 x i8] c"gettimeofday failed: errno=%d (%s)\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define double @gettime_to_double() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i64 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %13
5: ; preds = %0
%6 = tail call i32 (...) @display_restore()
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = call double @timeval_to_double(%struct.timeval* %1)
ret double %14
}