#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 */
void timespec_monodiff_lmr(struct timespec *ts_out,
                           const struct timespec *ts_in) {
  ts_out->tv_sec = ts_out->tv_sec - ts_in->tv_sec;
  ts_out->tv_nsec = ts_out->tv_nsec - ts_in->tv_nsec;
  if (ts_out->tv_nsec < 0) {
    ts_out->tv_sec = ts_out->tv_sec - 1;
    ts_out->tv_nsec = ts_out->tv_nsec + (1000000000);
  }
}


x86 assembly (clang, -O0):
<timespec_monodiff_lmr>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
sub    0x8(%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
mov    -0x10(%rbp),%rax
sub    (%rax),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x0,(%rax)
jge    1170 <timespec_monodiff_lmr+0x70>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    $0x1,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
add    $0x3b9aca00,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
pop    %rbp
ret

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

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define void @timespec_monodiff_lmr(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1) {
%3 = bitcast %struct.timespec* %0 to <2 x i64>*
%4 = load <2 x i64>, <2 x i64>* %3
%5 = bitcast %struct.timespec* %1 to <2 x i64>*
%6 = load <2 x i64>, <2 x i64>* %5
%7 = sub nsw <2 x i64> %4, %6
%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
}