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

/* Variables and functions */
void timespec_subtract(struct timespec *left, const struct timespec *right) {
  left->tv_sec -= right->tv_sec;
  left->tv_nsec -= right->tv_nsec;
  if (left->tv_nsec < 0L) {
    --left->tv_sec;
    left->tv_nsec += 1000000000L;
  }
}


x86 assembly (clang, -O0):
<timespec_subtract>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1166 <timespec_subtract+0x66>
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)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_subtract>:
movdqu (%rsi),%xmm1
movdqu (%rdi),%xmm0
psubq  %xmm1,%xmm0
movdqu %xmm0,(%rdi)
movq   %xmm0,%rax
test   %rax,%rax
js     111b <timespec_subtract+0x1b>
ret
paddq  0xedd(%rip),%xmm0
movdqu %xmm0,(%rdi)
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define void @timespec_subtract(%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** %4
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%7 = load i64, i64* %6
%8 = load %struct.timespec*, %struct.timespec** %3
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
%10 = load i64, i64* %9
%11 = sub nsw i64 %10, %7
store i64 %11, i64* %9
%12 = load %struct.timespec*, %struct.timespec** %4
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %12, i32 0, i32 0
%14 = load i64, i64* %13
%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 = sub nsw i64 %17, %14
store i64 %18, i64* %16
%19 = load %struct.timespec*, %struct.timespec** %3
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = icmp slt i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %2
%24 = load %struct.timespec*, %struct.timespec** %3
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i32 0, i32 1
%26 = load i64, i64* %25
%27 = add nsw i64 %26, -1
store i64 %27, i64* %25
%28 = load %struct.timespec*, %struct.timespec** %3
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = add nsw i64 %30, 1000000000
store i64 %31, i64* %29
br label %32
32: ; preds = %23, %2
ret void
}

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