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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_COARSE;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ slick_fatal(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
uint64_t sched_time_now(void) {
  struct timespec ts;
  if (clock_gettime(CLOCK_MONOTONIC_COARSE, &ts) != 0) {
    slick_fatal("sched_time_now(): clock_gettime() failed with: %s",
                strerror(errno));
    return 0;
  }
  return (((uint64_t)ts.tv_sec * 1000000000ULL) + (uint64_t)ts.tv_nsec);
}


x86 assembly (clang, -O0):
<sched_time_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     117d <sched_time_now+0x4d>
mov    0x2e7d(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    %eax,%esi
lea    0xe95(%rip),%rdi
call   1040 <slick_fatal@plt>
movq   $0x0,-0x8(%rbp)
jmp    118d <sched_time_now+0x5d>
imul   $0x3b9aca00,-0x10(%rbp),%rax
3b
add    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sched_time_now>:
sub    $0x18,%rsp
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
je     116f <sched_time_now+0x3f>
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe9f(%rip),%rdi
mov    %eax,%esi
call   1040 <slick_fatal@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret
imul   $0x3b9aca00,0x10(%rsp),%rax
9a 3b
add    0x8(%rsp),%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_COARSE = global i32 0
@.str = [50 x i8] c"sched_time_now(): clock_gettime() failed with: %s\00"
@errno = global i32 0
define i64 @sched_time_now() {
%1 = alloca i64
%2 = alloca %struct.timespec
%3 = load i32, i32* @CLOCK_MONOTONIC_COARSE
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @slick_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %8)
store i64 0, i64* %1
br label %17
10: ; preds = %0
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%12 = load i64, i64* %11
%13 = mul i64 %12, 1000000000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%15 = load i64, i64* %14
%16 = add i64 %13, %15
store i64 %16, i64* %1
br label %17
17: ; preds = %10, %6
%18 = load i64, i64* %1
ret i64 %18
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_COARSE = global i32 0
@.str = [50 x i8] c"sched_time_now(): clock_gettime() failed with: %s\00"
@errno = global i32 0
define i64 @sched_time_now() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC_COARSE
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %10, label %6
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @slick_fatal(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str, i64 0, i64 0), i32 %8)
br label %17
10: ; preds = %0
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = mul i64 %12, 1000000000
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%15 = load i64, i64* %14
%16 = add i64 %13, %15
br label %17
17: ; preds = %10, %6
%18 = phi i64 [ 0, %6 ], [ %16, %10 ]
ret i64 %18
}