#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 */
typedef scalar_t__ uint64_t;
struct timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ EXIT_FAILURE;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
uint64_t get_time() {
  struct timespec ts;
  if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
    fprintf(stderr, "Unable to retrieve current time: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  return ts.tv_sec * 1000000000 + ts.tv_nsec;
}


x86 assembly (clang, -O0):
<get_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    119d <get_time+0x5d>
mov    0x2e76(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e62(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe76(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
imul   $0x3b9aca00,-0x10(%rbp),%eax
cltq
add    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e7c(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     1171 <get_time+0x31>
movslq (%rsp),%rax
imul   $0x3b9aca00,%rax,%rax
add    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e68(%rip),%rax
mov    (%rax),%ebx
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe71(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Unable to retrieve current time: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i64 @get_time() {
%1 = alloca %struct.timespec
%2 = load i32, i32* @CLOCK_REALTIME
%3 = call i32 @clock_gettime(i32 %2, %struct.timespec* %1)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %12
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = call i8* @strerror(i32 %7)
%9 = call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = call i32 @exit(i32 %10)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%14 = load i32, i32* %13
%15 = mul nsw i32 %14, 1000000000
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%18 = load i64, i64* %17
%19 = add nsw i64 %16, %18
ret i64 %19
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@stderr = global i32 0
@.str = [37 x i8] c"Unable to retrieve current time: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i64 @get_time() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_REALTIME
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %13
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = call i8* @strerror(i32 %8)
%10 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %0
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%15 = load i32, i32* %14
%16 = mul nsw i32 %15, 1000000000
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%19 = load i64, i64* %18
%20 = add nsw i64 %19, %17
ret i64 %20
}