#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 {
  unsigned long long tv_sec;
  scalar_t__ tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ 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 stamp(void) {
  struct timespec tspec;
  if (clock_gettime(CLOCK_MONOTONIC, &tspec)) {
    fprintf(stderr, "Error getting timestamp: %s\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
  return (tspec.tv_sec * 1000000000ULL) + tspec.tv_nsec;
}


x86 assembly (clang, -O0):
<stamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     119e <stamp+0x5e>
mov    0x2e6d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe75(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
imul   $0x3b9aca00,-0x10(%rbp),%rax
3b
add    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stamp>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    116e <stamp+0x2e>
imul   $0x3b9aca00,(%rsp),%rax
3b
add    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e63(%rip),%rax
mov    (%rax),%ebx
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe74(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Error getting timestamp: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i64 @stamp() {
%1 = alloca %struct.timespec
%2 = load i32, i32* @CLOCK_MONOTONIC
%3 = call i64 @clock_gettime(i32 %2, %struct.timespec* %1)
%4 = icmp ne i64 %3, 0
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 ([29 x i8], [29 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 i64, i64* %13
%15 = mul i64 %14, 1000000000
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%17 = load i64, i64* %16
%18 = add i64 %15, %17
ret i64 %18
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [29 x i8] c"Error getting timestamp: %s\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
define i64 @stamp() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %13, label %6
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 ([29 x i8], [29 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 i64, i64* %14
%16 = mul i64 %15, 1000000000
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%18 = load i64, i64* %17
%19 = add i64 %16, %18
ret i64 %19
}