#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 timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};
typedef int __u64;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
__u64 gettime(void) {
  struct timespec t;
  int res;
  res = clock_gettime(CLOCK_MONOTONIC, &t);
  if (res < 0) {
    fprintf(stderr, "Error with gettimeofday! (%i)\n", res);
    exit(1);
  }
  return (__u64)t.tv_sec * 1000000000 + t.tv_nsec;
}


x86 assembly (clang, -O0):
<gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1179 <gettime+0x49>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    -0x14(%rbp),%edx
lea    0xe96(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x8(%rbp),%rax
imul   $0x3b9aca00,%eax,%eax
add    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime>:
sub    $0x18,%rsp
mov    0x2ead(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %eax,%eax
js     115c <gettime+0x2c>
imul   $0x3b9aca00,0x10(%rsp),%eax
3b
add    0x8(%rsp),%eax
add    $0x18,%rsp
ret
mov    0x2e75(%rip),%rcx
mov    (%rcx),%edi
lea    0xe94(%rip),%rsi
mov    %eax,%edx
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Error with gettimeofday! (%i)\0A\00"
define i32 @gettime() {
%1 = alloca %struct.timespec
%2 = alloca i32
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* %2
%10 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %9)
%11 = call i32 @exit(i32 1)
unreachable
12: ; preds = %0
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%14 = load i64, i64* %13
%15 = trunc i64 %14 to i32
%16 = mul nsw i32 %15, 1000000000
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%18 = load i32, i32* %17
%19 = add nsw i32 %16, %18
ret i32 %19
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"Error with gettimeofday! (%i)\0A\00"
define i32 @gettime() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %4)
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = mul nsw i32 %13, 1000000000
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = add nsw i32 %14, %16
ret i32 %17
}