#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__ uint32_t;
struct timespec {
  unsigned long tv_sec;
  int tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
scalar_t__ clock_gettime(int /*<<< orphan*/, struct timespec *);
int plt_validateMonoTime() {
  extern int plt_monoValid;
  extern struct timespec plt_monoRef;
  extern uint32_t plt_monoTimeUS;
  if (!plt_monoValid) {
    if (clock_gettime(CLOCK_MONOTONIC, &plt_monoRef) < 0)
      return -1;
    plt_monoTimeUS = (uint32_t)((plt_monoRef.tv_sec * 1000000ul) +
                                (plt_monoRef.tv_nsec / 1000));
    plt_monoValid = 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<plt_validateMonoTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
cmpl   $0x0,(%rax)
jne    118f <plt_validateMonoTime+0x7f>
mov    0x2eb9(%rip),%rax
mov    (%rax),%edi
mov    0x2e98(%rip),%rsi
call   1030 <clock_gettime@plt>
cmp    $0x0,%rax
jge    1153 <plt_validateMonoTime+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    1196 <plt_validateMonoTime+0x86>
mov    0x2e76(%rip),%rax
imul   $0xf4240,(%rax),%rcx
mov    0x2e68(%rip),%rax
mov    0x8(%rax),%eax
mov    $0x3e8,%esi
cltd
idiv   %esi
cltq
add    %rax,%rcx
mov    0x2e61(%rip),%rax
mov    %rcx,(%rax)
mov    0x2e37(%rip),%rax
movl   $0x1,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<plt_validateMonoTime>:
push   %r15
push   %r14
push   %rbx
mov    0x2ea4(%rip),%r15
xor    %ebx,%ebx
cmpl   $0x0,(%r15)
jne    117e <plt_validateMonoTime+0x6e>
mov    0x2ebd(%rip),%rax
mov    (%rax),%edi
mov    0x2e9c(%rip),%r14
mov    %r14,%rsi
call   1030 <clock_gettime@plt>
test   %rax,%rax
js     1179 <plt_validateMonoTime+0x69>
imul   $0xf4240,(%r14),%rax
movslq 0x8(%r14),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rax,%rcx
mov    0x2e73(%rip),%rax
mov    %rcx,(%rax)
movl   $0x1,(%r15)
jmp    117e <plt_validateMonoTime+0x6e>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
@plt_monoValid = external global i32
@CLOCK_MONOTONIC = global i32 0
@plt_monoRef = external global %struct.timespec
@plt_monoTimeUS = external global i64
define i32 @plt_validateMonoTime() {
%1 = alloca i32
%2 = load i32, i32* @plt_monoValid
%3 = icmp ne i32 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %0
%5 = load i32, i32* @CLOCK_MONOTONIC
%6 = call i64 @clock_gettime(i32 %5, %struct.timespec* @plt_monoRef)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %4
store i32 -1, i32* %1
br label %17
9: ; preds = %4
%10 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @plt_monoRef, i32 0, i32 0)
%11 = mul i64 %10, 1000000
%12 = load i32, i32* getelementptr inbounds (%struct.timespec, %struct.timespec* @plt_monoRef, i32 0, i32 1)
%13 = sdiv i32 %12, 1000
%14 = sext i32 %13 to i64
%15 = add i64 %11, %14
store i64 %15, i64* @plt_monoTimeUS
store i32 1, i32* @plt_monoValid
br label %16
16: ; preds = %9, %0
store i32 0, i32* %1
br label %17
17: ; preds = %16, %8
%18 = load i32, i32* %1
ret i32 %18
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
@plt_monoValid = external global i32
@CLOCK_MONOTONIC = global i32 0
@plt_monoRef = external global %struct.timespec
@plt_monoTimeUS = external global i64
define i32 @plt_validateMonoTime() {
%1 = load i32, i32* @plt_monoValid
%2 = icmp eq i32 %1, 0
br i1 %2, label %3, label %14
3: ; preds = %0
%4 = load i32, i32* @CLOCK_MONOTONIC
%5 = tail call i64 @clock_gettime(i32 %4, %struct.timespec* @plt_monoRef)
%6 = icmp slt i64 %5, 0
br i1 %6, label %14, label %7
7: ; preds = %3
%8 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @plt_monoRef, i64 0, i32 0)
%9 = mul i64 %8, 1000000
%10 = load i32, i32* getelementptr inbounds (%struct.timespec, %struct.timespec* @plt_monoRef, i64 0, i32 1)
%11 = sdiv i32 %10, 1000
%12 = sext i32 %11 to i64
%13 = add i64 %9, %12
store i64 %13, i64* @plt_monoTimeUS
store i32 1, i32* @plt_monoValid
br label %14
14: ; preds = %0, %7, %3
%15 = phi i32 [ -1, %3 ], [ 0, %7 ], [ 0, %0 ]
ret i32 %15
}