#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_sec;
  scalar_t__ tv_nsec;
};
typedef int sqlite3_uint64;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ log_real_(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                             char *, int /*<<< orphan*/);
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
sqlite3_uint64 gettime(void) {
  sqlite3_uint64 timestamp;
  struct timespec now;
  if (clock_gettime(CLOCK_MONOTONIC, &now) == -1) {
    log_real_(0, "CRITICAL", 0,
              "getting time failed (clock_gettime): %s"
              "\n",
              strerror(errno));
    exit(1);
  }
  timestamp = now.tv_sec;
  timestamp *= 1000000000;
  timestamp += now.tv_nsec;
  return timestamp;
}


x86 assembly (clang, -O0):
<gettime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0xffffffff,%eax
jne    1195 <gettime+0x55>
mov    0x2e6e(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %eax,%r8d
xor    %edx,%edx
lea    0xe83(%rip),%rsi
lea    0xe85(%rip),%rcx
mov    %edx,%edi
call   1030 <log_real_@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x4(%rbp)
imul   $0x3b9aca00,-0x4(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x10(%rbp),%rcx
movslq -0x4(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gettime>:
sub    $0x18,%rsp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1040 <clock_gettime@plt>
cmp    $0xffffffff,%eax
je     116d <gettime+0x2d>
imul   $0x3b9aca00,0x8(%rsp),%eax
3b
add    0x10(%rsp),%eax
add    $0x18,%rsp
ret
mov    0x2e64(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
lea    0xe7e(%rip),%rsi
lea    0xe80(%rip),%rcx
xor    %edi,%edi
xor    %edx,%edx
mov    %eax,%r8d
call   1030 <log_real_@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [9 x i8] c"CRITICAL\00"
@.str.1 = [41 x i8] c"getting time failed (clock_gettime): %s\0A\00"
@errno = global i32 0
define i32 @gettime() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %2)
%5 = icmp eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @log_real_(i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%13 = load i32, i32* %12
store i32 %13, i32* %1
%14 = load i32, i32* %1
%15 = mul nsw i32 %14, 1000000000
store i32 %15, i32* %1
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%17 = load i64, i64* %16
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = add nsw i64 %19, %17
%21 = trunc i64 %20 to i32
store i32 %21, i32* %1
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [9 x i8] c"CRITICAL\00"
@.str.1 = [41 x i8] c"getting time failed (clock_gettime): %s\0A\00"
@errno = global i32 0
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 eq i32 %4, -1
br i1 %5, label %6, label %11
6: ; preds = %0
%7 = load i32, i32* @errno
%8 = call i32 @strerror(i32 %7)
%9 = call i32 @log_real_(i32 0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 0, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 1000000000
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = add i32 %14, %17
ret i32 %18
}