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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC_RAW;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int ap_utils_timespec_cmp_to_now(struct timespec *ts) {
  struct timespec now;
  clock_gettime(CLOCK_MONOTONIC_RAW, &now);
  if (ts->tv_sec > now.tv_sec)
    return 1;
  if (ts->tv_sec < now.tv_sec)
    return -1;
  if (ts->tv_nsec > now.tv_nsec)
    return 1;
  if (ts->tv_nsec < now.tv_nsec)
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<ap_utils_timespec_cmp_to_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jle    114b <ap_utils_timespec_cmp_to_now+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    11ab <ap_utils_timespec_cmp_to_now+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
cmp    -0x20(%rbp),%rax
jge    1168 <ap_utils_timespec_cmp_to_now+0x58>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <ap_utils_timespec_cmp_to_now+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmp    -0x18(%rbp),%rax
jle    1186 <ap_utils_timespec_cmp_to_now+0x76>
movl   $0x1,-0x4(%rbp)
jmp    11ab <ap_utils_timespec_cmp_to_now+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
cmp    -0x18(%rbp),%rax
jge    11a4 <ap_utils_timespec_cmp_to_now+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ab <ap_utils_timespec_cmp_to_now+0x9b>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ap_utils_timespec_cmp_to_now>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    (%rsp),%rcx
mov    $0x1,%eax
cmp    %rcx,(%rbx)
jg     1156 <ap_utils_timespec_cmp_to_now+0x46>
mov    $0xffffffff,%eax
jl     1156 <ap_utils_timespec_cmp_to_now+0x46>
mov    0x8(%rsp),%rcx
mov    $0x1,%eax
cmp    %rcx,0x8(%rbx)
jg     1156 <ap_utils_timespec_cmp_to_now+0x46>
setl   %al
movzbl %al,%eax
neg    %eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
define i32 @ap_utils_timespec_cmp_to_now(%struct.timespec* %0) {
%2 = alloca i32
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %3
%5 = load i32, i32* @CLOCK_MONOTONIC_RAW
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %4)
%7 = load %struct.timespec*, %struct.timespec** %3
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%11 = load i64, i64* %10
%12 = icmp sgt i64 %9, %11
br i1 %12, label %13, label %14
13: ; preds = %1
store i32 1, i32* %2
br label %39
14: ; preds = %1
%15 = load %struct.timespec*, %struct.timespec** %3
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%19 = load i64, i64* %18
%20 = icmp slt i64 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %14
store i32 -1, i32* %2
br label %39
22: ; preds = %14
%23 = load %struct.timespec*, %struct.timespec** %3
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%27 = load i64, i64* %26
%28 = icmp sgt i64 %25, %27
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 1, i32* %2
br label %39
30: ; preds = %22
%31 = load %struct.timespec*, %struct.timespec** %3
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 1
%33 = load i64, i64* %32
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%35 = load i64, i64* %34
%36 = icmp slt i64 %33, %35
br i1 %36, label %37, label %38
37: ; preds = %30
store i32 -1, i32* %2
br label %39
38: ; preds = %30
store i32 0, i32* %2
br label %39
39: ; preds = %38, %37, %29, %21, %13
%40 = load i32, i32* %2
ret i32 %40
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_MONOTONIC_RAW = global i32 0
define i32 @ap_utils_timespec_cmp_to_now(%struct.timespec* nocapture %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = load i32, i32* @CLOCK_MONOTONIC_RAW
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%9 = load i64, i64* %8
%10 = icmp sgt i64 %7, %9
br i1 %10, label %22, label %11
11: ; preds = %1
%12 = icmp slt i64 %7, %9
br i1 %12, label %22, label %13
13: ; preds = %11
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%15 = load i64, i64* %14
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%17 = load i64, i64* %16
%18 = icmp sgt i64 %15, %17
br i1 %18, label %22, label %19
19: ; preds = %13
%20 = icmp slt i64 %15, %17
%21 = sext i1 %20 to i32
br label %22
22: ; preds = %19, %13, %11, %1
%23 = phi i32 [ 1, %1 ], [ -1, %11 ], [ 1, %13 ], [ %21, %19 ]
ret i32 %23
}