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

/* Variables and functions */
int /*<<< orphan*/ MAX(long long, int);
long long MIN(int /*<<< orphan*/, int);
long long spectonsec(struct timespec *);
int tscmp(struct timespec *a, struct timespec *b) {
  long long m, s;
  long long rc;
  m = spectonsec(a);
  s = spectonsec(b);
  if (s < 0) {
    rc = 1;
    if (m < 0)
      rc = 0;
  } else if (m < 0) {
    rc = -1;
  } else {
    rc = MIN(MAX(s - m, -1), 1);
  }
  return rc;
}


x86 assembly (clang, -O0):
<tscmp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <spectonsec@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <spectonsec@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1185 <tscmp+0x55>
movq   $0x1,-0x28(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    1180 <tscmp+0x50>
movq   $0x0,-0x28(%rbp)
jmp    11c4 <tscmp+0x94>
cmpq   $0x0,-0x18(%rbp)
jge    119d <tscmp+0x6d>
movq   $0xffffffffffffffff,-0x28(%rbp)
ff
jmp    11bf <tscmp+0x8f>
mov    -0x20(%rbp),%rdi
sub    -0x18(%rbp),%rdi
mov    $0xffffffff,%esi
call   1050 <MAX@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <MIN@plt>
mov    %rax,-0x28(%rbp)
jmp    11c4 <tscmp+0x94>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tscmp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
call   1040 <spectonsec@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <spectonsec@plt>
test   %rax,%rax
js     1172 <tscmp+0x42>
test   %rbx,%rbx
js     117b <tscmp+0x4b>
sub    %rbx,%rax
mov    %rax,%rdi
mov    $0xffffffff,%esi
call   1050 <MAX@plt>
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <MIN@plt>
mov    %rax,%rbx
jmp    1182 <tscmp+0x52>
not    %rbx
shr    $0x3f,%rbx
jmp    1182 <tscmp+0x52>
mov    $0xffffffffffffffff,%rbx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i32 @tscmp(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
%8 = load %struct.timespec*, %struct.timespec** %3
%9 = call i64 @spectonsec(%struct.timespec* %8)
store i64 %9, i64* %5
%10 = load %struct.timespec*, %struct.timespec** %4
%11 = call i64 @spectonsec(%struct.timespec* %10)
store i64 %11, i64* %6
%12 = load i64, i64* %6
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %19
14: ; preds = %2
store i64 1, i64* %7
%15 = load i64, i64* %5
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %14
store i64 0, i64* %7
br label %18
18: ; preds = %17, %14
br label %30
19: ; preds = %2
%20 = load i64, i64* %5
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %19
store i64 -1, i64* %7
br label %29
23: ; preds = %19
%24 = load i64, i64* %6
%25 = load i64, i64* %5
%26 = sub nsw i64 %24, %25
%27 = call i32 @MAX(i64 %26, i32 -1)
%28 = call i64 @MIN(i32 %27, i32 1)
store i64 %28, i64* %7
br label %29
29: ; preds = %23, %22
br label %30
30: ; preds = %29, %18
%31 = load i64, i64* %7
%32 = trunc i64 %31 to i32
ret i32 %32
}

LLVM IR (-O2):
%struct.timespec = type { i32 }
define i32 @tscmp(%struct.timespec* %0, %struct.timespec* %1) {
%3 = tail call i64 @spectonsec(%struct.timespec* %0)
%4 = tail call i64 @spectonsec(%struct.timespec* %1)
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = xor i64 %3, -1
%8 = lshr i64 %7, 63
br label %15
9: ; preds = %2
%10 = icmp slt i64 %3, 0
br i1 %10, label %15, label %11
11: ; preds = %9
%12 = sub nsw i64 %4, %3
%13 = tail call i32 @MAX(i64 %12, i32 -1)
%14 = tail call i64 @MIN(i32 %13, i32 1)
br label %15
15: ; preds = %9, %11, %6
%16 = phi i64 [ %8, %6 ], [ %14, %11 ], [ -1, %9 ]
%17 = trunc i64 %16 to i32
ret i32 %17
}