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

/* Variables and functions */
int /*<<< orphan*/ pn_timespec_check(struct timespec *);
void pn_timespec_subtract(struct timespec *result, struct timespec *a,
                          struct timespec *b) {
  pn_timespec_check(a);
  pn_timespec_check(b);
  result->tv_sec = a->tv_sec - b->tv_sec;
  result->tv_nsec = a->tv_nsec - b->tv_nsec;
  if (result->tv_nsec < 0) {
    result->tv_sec--;
    result->tv_nsec += 1000000000;
  }
  pn_timespec_check(result);
}


x86 assembly (clang, -O0):
<pn_timespec_subtract>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <pn_timespec_check@plt>
mov    -0x18(%rbp),%rdi
call   1030 <pn_timespec_check@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x18(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1192 <pn_timespec_subtract+0x82>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x3b9aca00,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <pn_timespec_check@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pn_timespec_subtract>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1030 <pn_timespec_check@plt>
mov    %r15,%rdi
call   1030 <pn_timespec_check@plt>
movdqu (%rbx),%xmm0
movdqu (%r15),%xmm1
psubq  %xmm1,%xmm0
movdqu %xmm0,(%r14)
movq   %xmm0,%rax
test   %rax,%rax
jns    1157 <pn_timespec_subtract+0x47>
paddq  0xeae(%rip),%xmm0
movdqu %xmm0,(%r14)
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1030 <pn_timespec_check@plt>

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define void @pn_timespec_subtract(%struct.timespec* %0, %struct.timespec* %1, %struct.timespec* %2) {
%4 = tail call i32 @pn_timespec_check(%struct.timespec* %1)
%5 = tail call i32 @pn_timespec_check(%struct.timespec* %2)
%6 = bitcast %struct.timespec* %1 to <2 x i64>*
%7 = load <2 x i64>, <2 x i64>* %6
%8 = bitcast %struct.timespec* %2 to <2 x i64>*
%9 = load <2 x i64>, <2 x i64>* %8
%10 = sub nsw <2 x i64> %7, %9
%11 = bitcast %struct.timespec* %0 to <2 x i64>*
store <2 x i64> %10, <2 x i64>* %11
%12 = extractelement <2 x i64> %10, i64 0
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = add nsw <2 x i64> %10, <i64 1000000000, i64 -1>
%16 = bitcast %struct.timespec* %0 to <2 x i64>*
store <2 x i64> %15, <2 x i64>* %16
br label %17
17: ; preds = %14, %3
%18 = tail call i32 @pn_timespec_check(%struct.timespec* %0)
ret void
}