#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*/ nsectospec(long long, struct timespec *);
long long spectonsec(struct timespec *);
void tssub(struct timespec *minuend, struct timespec *subtrahend,
           struct timespec *difference) {
  long long m, s, d;
  m = spectonsec(minuend);
  s = spectonsec(subtrahend);
  if (s < 0) {
    d = 0;
  } else if (m < 0) {
    d = -1;
  } else {
    m -= s;
    d = m < 0 ? 0 : m;
  }
  nsectospec(d, difference);
  return;
}


x86 assembly (clang, -O0):
<tssub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <spectonsec@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <spectonsec@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1166 <tssub+0x46>
movq   $0x0,-0x30(%rbp)
jmp    11b8 <tssub+0x98>
cmpq   $0x0,-0x20(%rbp)
jge    117e <tssub+0x5e>
movq   $0xffffffffffffffff,-0x30(%rbp)
ff
jmp    11b3 <tssub+0x93>
mov    -0x28(%rbp),%rcx
mov    -0x20(%rbp),%rax
sub    %rcx,%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    11a3 <tssub+0x83>
xor    %eax,%eax
mov    %rax,-0x38(%rbp)
jmp    11ab <tssub+0x8b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11b8 <tssub+0x98>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <nsectospec@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tssub>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
call   1030 <spectonsec@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <spectonsec@plt>
test   %rax,%rax
js     1150 <tssub+0x30>
test   %rbx,%rbx
js     1154 <tssub+0x34>
xor    %edi,%edi
sub    %rax,%rbx
cmovns %rbx,%rdi
jmp    115b <tssub+0x3b>
xor    %edi,%edi
jmp    115b <tssub+0x3b>
mov    $0xffffffffffffffff,%rdi
mov    %r14,%rsi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <nsectospec@plt>

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

LLVM IR (-O2):
%struct.timespec = type { i32 }
define void @tssub(%struct.timespec* %0, %struct.timespec* %1, %struct.timespec* %2) {
%4 = tail call i64 @spectonsec(%struct.timespec* %0)
%5 = tail call i64 @spectonsec(%struct.timespec* %1)
%6 = icmp slt i64 %5, 0
br i1 %6, label %13, label %7
7: ; preds = %3
%8 = icmp slt i64 %4, 0
br i1 %8, label %13, label %9
9: ; preds = %7
%10 = sub nsw i64 %4, %5
%11 = icmp sgt i64 %10, 0
%12 = select i1 %11, i64 %10, i64 0
br label %13
13: ; preds = %7, %3, %9
%14 = phi i64 [ %12, %9 ], [ 0, %3 ], [ -1, %7 ]
%15 = tail call i32 @nsectospec(i64 %14, %struct.timespec* %2)
ret void
}