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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
uint64_t pk_time64_useconds() {
  struct timespec ts;
  if (clock_gettime(CLOCK_MONOTONIC, &ts)) {
    return 0;
  }
  return (uint64_t)(ts.tv_sec * (1e+6)) + (uint64_t)(ts.tv_nsec * 0.001);
}


x86 assembly (clang, -O0):
<pk_time64_useconds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
je     1141 <pk_time64_useconds+0x31>
movq   $0x0,-0x8(%rbp)
jmp    1170 <pk_time64_useconds+0x60>
cvtsi2sdl -0x18(%rbp),%xmm0
movsd  0xeba(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
movsd  0xea1(%rip),%xmm0
mulsd  -0x10(%rbp),%xmm0
cvttsd2si %xmm0,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pk_time64_useconds>:
sub    $0x18,%rsp
mov    0x2ecd(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
je     1133 <pk_time64_useconds+0x23>
xor    %eax,%eax
add    $0x18,%rsp
ret
cvtsi2sdl 0x8(%rsp),%xmm0
mulsd  0xebf(%rip),%xmm0
cvttsd2si %xmm0,%rcx
movsd  0x10(%rsp),%xmm0
mulsd  0xeb4(%rip),%xmm0
cvttsd2si %xmm0,%rax
add    %rcx,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, double }
@CLOCK_MONOTONIC = global i32 0
define i64 @pk_time64_useconds() {
%1 = alloca i64
%2 = alloca %struct.timespec
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i64 @clock_gettime(i32 %3, %struct.timespec* %2)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %7
6: ; preds = %0
store i64 0, i64* %1
br label %18
7: ; preds = %0
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%9 = load i32, i32* %8
%10 = sitofp i32 %9 to double
%11 = fmul double %10, 1.000000e+06
%12 = fptosi double %11 to i64
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%14 = load double, double* %13
%15 = fmul double %14, 1.000000e-03
%16 = fptosi double %15 to i64
%17 = add nsw i64 %12, %16
store i64 %17, i64* %1
br label %18
18: ; preds = %7, %6
%19 = load i64, i64* %1
ret i64 %19
}

LLVM IR (-O2):
%struct.timespec = type { i32, double }
@CLOCK_MONOTONIC = global i32 0
define i64 @pk_time64_useconds() {
%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 %6, label %17
6: ; preds = %0
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = sitofp i32 %8 to double
%10 = fmul double %9, 1.000000e+06
%11 = fptosi double %10 to i64
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%13 = load double, double* %12
%14 = fmul double %13, 1.000000e-03
%15 = fptosi double %14 to i64
%16 = add nsw i64 %11, %15
br label %17
17: ; preds = %0, %6
%18 = phi i64 [ %16, %6 ], [ 0, %0 ]
ret i64 %18
}