#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;
};

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


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    1170 <gettime+0x40>
mov    -0x14(%rbp),%esi
lea    0xe9f(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
imul   $0x3b9aca00,-0x8(%rbp),%rax
3b
mov    -0x10(%rbp),%ecx
shl    $0x0,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
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     1161 <gettime+0x31>
imul   $0x3b9aca00,0x10(%rsp),%rcx
9a 3b
movslq 0x8(%rsp),%rax
add    %rcx,%rax
add    $0x18,%rsp
ret
lea    0xe98(%rip),%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [31 x i8] c"error with gettimeofday! (%i)\0A\00"
define i64 @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 %11
7: ; preds = %0
%8 = load i32, i32* %2
%9 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %8)
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%13 = load i64, i64* %12
%14 = mul i64 %13, 1000000000
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%16 = load i32, i32* %15
%17 = mul nsw i32 %16, 1
%18 = sext i32 %17 to i64
%19 = add i64 %14, %18
ret i64 %19
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_MONOTONIC = global i32 0
@.str = [31 x i8] c"error with gettimeofday! (%i)\0A\00"
define i64 @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 %9
6: ; preds = %0
%7 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %4)
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%11 = load i64, i64* %10
%12 = mul i64 %11, 1000000000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = add i64 %12, %15
ret i64 %16
}