#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_nsec;
  int tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ ensure(int, char *);
void timespec_sub(struct timespec *t1, const struct timespec *t2) {
  if (t1->tv_nsec < t2->tv_nsec) {
    ensure(t1->tv_sec >= 1, "No negative time possible");
    t1->tv_sec -= 1;
    t1->tv_nsec += 1000000000;
  }
  ensure(t1->tv_sec >= t2->tv_sec, "No negative time possible");
  t1->tv_nsec -= t2->tv_nsec;
  t1->tv_sec -= t2->tv_sec;
}


x86 assembly (clang, -O0):
<timespec_sub>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
jge    116e <timespec_sub+0x5e>
mov    -0x8(%rbp),%rax
cmpl   $0x1,0x8(%rax)
setge  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xeb5(%rip),%rsi
call   1030 <ensure@plt>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
sub    $0x1,%ecx
mov    %ecx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x3b9aca00,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%eax
mov    -0x10(%rbp),%rcx
cmp    0x8(%rcx),%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
lea    0xe75(%rip),%rsi
call   1030 <ensure@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%ecx
sub    %edx,%ecx
mov    %ecx,0x8(%rax)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_sub>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rdi),%rcx
mov    0x8(%rdi),%eax
cmp    (%rsi),%rcx
jge    1149 <timespec_sub+0x39>
xor    %edi,%edi
test   %eax,%eax
setg   %dil
lea    0xecc(%rip),%rsi
call   1030 <ensure@plt>
mov    0x8(%rbx),%eax
add    $0xffffffff,%eax
mov    %eax,0x8(%rbx)
addq   $0x3b9aca00,(%rbx)
xor    %edi,%edi
cmp    0x8(%r14),%eax
setge  %dil
lea    0xea6(%rip),%rsi
call   1030 <ensure@plt>
mov    (%r14),%rax
sub    %rax,(%rbx)
mov    0x8(%r14),%eax
sub    %eax,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i32 }
@.str = [26 x i8] c"No negative time possible\00"
define void @timespec_sub(%struct.timespec* %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec*
%4 = alloca %struct.timespec*
store %struct.timespec* %0, %struct.timespec** %3
store %struct.timespec* %1, %struct.timespec** %4
%5 = load %struct.timespec*, %struct.timespec** %3
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%7 = load i64, i64* %6
%8 = load %struct.timespec*, %struct.timespec** %4
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 0
%10 = load i64, i64* %9
%11 = icmp slt i64 %7, %10
br i1 %11, label %12, label %27
12: ; preds = %2
%13 = load %struct.timespec*, %struct.timespec** %3
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 1
%15 = load i32, i32* %14
%16 = icmp sge i32 %15, 1
%17 = zext i1 %16 to i32
%18 = call i32 @ensure(i32 %17, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%19 = load %struct.timespec*, %struct.timespec** %3
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %21, 1
store i32 %22, i32* %20
%23 = load %struct.timespec*, %struct.timespec** %3
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %23, i32 0, i32 0
%25 = load i64, i64* %24
%26 = add nsw i64 %25, 1000000000
store i64 %26, i64* %24
br label %27
27: ; preds = %12, %2
%28 = load %struct.timespec*, %struct.timespec** %3
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 1
%30 = load i32, i32* %29
%31 = load %struct.timespec*, %struct.timespec** %4
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %31, i32 0, i32 1
%33 = load i32, i32* %32
%34 = icmp sge i32 %30, %33
%35 = zext i1 %34 to i32
%36 = call i32 @ensure(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%37 = load %struct.timespec*, %struct.timespec** %4
%38 = getelementptr inbounds %struct.timespec, %struct.timespec* %37, i32 0, i32 0
%39 = load i64, i64* %38
%40 = load %struct.timespec*, %struct.timespec** %3
%41 = getelementptr inbounds %struct.timespec, %struct.timespec* %40, i32 0, i32 0
%42 = load i64, i64* %41
%43 = sub nsw i64 %42, %39
store i64 %43, i64* %41
%44 = load %struct.timespec*, %struct.timespec** %4
%45 = getelementptr inbounds %struct.timespec, %struct.timespec* %44, i32 0, i32 1
%46 = load i32, i32* %45
%47 = load %struct.timespec*, %struct.timespec** %3
%48 = getelementptr inbounds %struct.timespec, %struct.timespec* %47, i32 0, i32 1
%49 = load i32, i32* %48
%50 = sub nsw i32 %49, %46
store i32 %50, i32* %48
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i32 }
@.str = [26 x i8] c"No negative time possible\00"
define void @timespec_sub(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%6 = load i64, i64* %5
%7 = icmp slt i64 %4, %6
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%9 = load i32, i32* %8
br i1 %7, label %10, label %18
10: ; preds = %2
%11 = icmp sgt i32 %9, 0
%12 = zext i1 %11 to i32
%13 = tail call i32 @ensure(i32 %12, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %8
%15 = add nsw i32 %14, -1
store i32 %15, i32* %8
%16 = load i64, i64* %3
%17 = add nsw i64 %16, 1000000000
store i64 %17, i64* %3
br label %18
18: ; preds = %2, %10
%19 = phi i32 [ %15, %10 ], [ %9, %2 ]
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%22 = load i32, i32* %21
%23 = icmp sge i32 %19, %22
%24 = zext i1 %23 to i32
%25 = tail call i32 @ensure(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
%26 = load i64, i64* %5
%27 = load i64, i64* %3
%28 = sub nsw i64 %27, %26
store i64 %28, i64* %3
%29 = load i32, i32* %21
%30 = load i32, i32* %20
%31 = sub nsw i32 %30, %29
store i32 %31, i32* %20
ret void
}