#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 {
  scalar_t__ tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
double nanotime() {
  struct timespec now;
  if (clock_gettime(CLOCK_MONOTONIC, &now)) {
    do {
      fprintf(stderr, "Can't read clock.\n");
      perror("");
      exit(1);
    } while (0);
  }
  return (double)now.tv_sec + 1e-9 * (double)now.tv_nsec;
}


x86 assembly (clang, -O0):
<nanotime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1194 <nanotime+0x54>
jmp    1169 <nanotime+0x29>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
lea    0xe8f(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe95(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
cvtsi2sdq -0x8(%rbp),%xmm1
cvtsi2sdq -0x10(%rbp),%xmm0
movsd  0xe58(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nanotime>:
sub    $0x18,%rsp
mov    0x2e9d(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
jne    117b <nanotime+0x3b>
cvtsi2sdq 0x10(%rsp),%xmm1
cvtsi2sdq 0x8(%rsp),%xmm0
mulsd  0xe8e(%rip),%xmm0
addsd  %xmm1,%xmm0
add    $0x18,%rsp
ret
mov    0x2e56(%rip),%rax
mov    (%rax),%edi
lea    0xe7d(%rip),%rsi
call   1040 <fprintf@plt>
lea    0xe83(%rip),%rdi
call   1050 <perror@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Can't read clock.\0A\00"
@.str.1 = [1 x i8] zeroinitializer
define double @nanotime() {
%1 = alloca %struct.timespec
%2 = load i32, i32* @CLOCK_MONOTONIC
%3 = call i64 @clock_gettime(i32 %2, %struct.timespec* %1)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %0
br label %6
6: ; preds = %5
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; No predecessors!
br label %12
12: ; preds = %11, %0
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%14 = load i64, i64* %13
%15 = sitofp i64 %14 to double
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = call double @llvm.fmuladd.f64(double 1.000000e-09, double %18, double %15)
ret double %19
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC = global i32 0
@stderr = global i32 0
@.str = [19 x i8] c"Can't read clock.\0A\00"
@.str.1 = [1 x i8] zeroinitializer
define double @nanotime() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = icmp eq i64 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %0
%7 = load i32, i32* @stderr
%8 = call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @perror(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%13 = load i64, i64* %12
%14 = sitofp i64 %13 to double
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%16 = load i64, i64* %15
%17 = sitofp i64 %16 to double
%18 = call double @llvm.fmuladd.f64(double %17, double 1.000000e-09, double %14)
ret double %18
}