#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_MONOTONIC_RAW;
int UINT64_C(int);
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ panic(char *);
int /*<<< orphan*/ perror(char *);
uint64_t get_time_nanos() {
  struct timespec t;
  if (clock_gettime(CLOCK_MONOTONIC_RAW, &t) != 0) {
    perror("clock_gettime");
    panic("critical failure in timer subsystem");
  }
  return t.tv_sec * UINT64_C(1000000000) + t.tv_nsec;
}


x86 assembly (clang, -O0):
<get_time_nanos>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0x0,%rax
je     117c <get_time_nanos+0x3c>
lea    0xe95(%rip),%rdi
call   1060 <perror@plt>
lea    0xe97(%rip),%rdi
call   1050 <panic@plt>
mov    -0x10(%rbp),%eax
mov    %eax,-0x14(%rbp)
mov    $0x3b9aca00,%edi
call   1030 <UINT64_C@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
imul   %ecx,%eax
cltq
add    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_nanos>:
push   %rbx
sub    $0x10,%rsp
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1040 <clock_gettime@plt>
test   %rax,%rax
jne    117a <get_time_nanos+0x3a>
movslq (%rsp),%rbx
mov    $0x3b9aca00,%edi
call   1030 <UINT64_C@plt>
cltq
imul   %rbx,%rax
add    0x8(%rsp),%rax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe7f(%rip),%rdi
call   1060 <perror@plt>
lea    0xe81(%rip),%rdi
call   1050 <panic@plt>
jmp    115b <get_time_nanos+0x1b>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
@.str.1 = [36 x i8] c"critical failure in timer subsystem\00"
define i64 @get_time_nanos() {
%1 = alloca %struct.timespec
%2 = load i32, i32* @CLOCK_MONOTONIC_RAW
%3 = call i64 @clock_gettime(i32 %2, %struct.timespec* %1)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @panic(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %8
8: ; preds = %5, %0
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @UINT64_C(i32 1000000000)
%12 = mul nsw i32 %10, %11
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%15 = load i64, i64* %14
%16 = add nsw i64 %13, %15
ret i64 %16
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
@.str = [14 x i8] c"clock_gettime\00"
@.str.1 = [36 x i8] c"critical failure in timer subsystem\00"
define i64 @get_time_nanos() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC_RAW
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %9, label %6
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @panic(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %9
9: ; preds = %6, %0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = call i32 @UINT64_C(i32 1000000000)
%13 = mul nsw i32 %12, %11
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%16 = load i64, i64* %15
%17 = add nsw i64 %16, %14
ret i64 %17
}