#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_sec;
  long tv_nsec;
  long member_0;
  long member_1;
};

/* Variables and functions */
struct timespec timespec_diff(struct timespec a, struct timespec b) {
  long sec = a.tv_sec - b.tv_sec;
  long nsec = a.tv_nsec - b.tv_nsec;
  if (nsec < 0) {
    nsec = 1000000000 + nsec;
    sec--;
  }
  struct timespec tmp = {sec, nsec};
  return tmp;
}


x86 assembly (clang, -O0):
<timespec_diff>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x20(%rbp)
mov    %rdi,-0x18(%rbp)
lea    0x30(%rbp),%rcx
lea    0x10(%rbp),%rax
mov    (%rax),%rdx
sub    (%rcx),%rdx
mov    %rdx,-0x8(%rbp)
mov    0x8(%rax),%rax
sub    0x8(%rcx),%rax
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    114f <timespec_diff+0x4f>
mov    -0x10(%rbp),%rax
add    $0x3b9aca00,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rdx
mov    %rdx,(%rcx)
mov    -0x10(%rbp),%rdx
mov    %rdx,0x8(%rcx)
movq   $0x0,0x10(%rcx)
movq   $0x0,0x18(%rcx)
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_diff>:
mov    %rdi,%rax
mov    0x8(%rsp),%rcx
mov    0x10(%rsp),%rdx
sub    0x28(%rsp),%rcx
sub    0x30(%rsp),%rdx
lea    0x3b9aca00(%rdx),%rsi
mov    %rdx,%rdi
sar    $0x3f,%rdi
add    %rcx,%rdi
test   %rdx,%rdx
cmovns %rdx,%rsi
mov    %rdi,(%rax)
mov    %rsi,0x8(%rax)
xorps  %xmm0,%xmm0
movups %xmm0,0x10(%rax)
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64, i64, i64 }
define void @timespec_diff(%struct.timespec* noalias sret(%struct.timespec) align 8 %0, %struct.timespec* byval(%struct.timespec) align 8 %1, %struct.timespec* byval(%struct.timespec) align 8 %2) {
%4 = alloca i64
%5 = alloca i64
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%9 = load i64, i64* %8
%10 = sub nsw i64 %7, %9
store i64 %10, i64* %4
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%12 = load i64, i64* %11
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%14 = load i64, i64* %13
%15 = sub nsw i64 %12, %14
store i64 %15, i64* %5
%16 = load i64, i64* %5
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %23
18: ; preds = %3
%19 = load i64, i64* %5
%20 = add nsw i64 1000000000, %19
store i64 %20, i64* %5
%21 = load i64, i64* %4
%22 = add nsw i64 %21, -1
store i64 %22, i64* %4
br label %23
23: ; preds = %18, %3
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 0
%25 = load i64, i64* %4
store i64 %25, i64* %24
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 1
%27 = load i64, i64* %5
store i64 %27, i64* %26
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 2
store i64 0, i64* %28
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i32 0, i32 3
store i64 0, i64* %29
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64, i64, i64 }
define void @timespec_diff(%struct.timespec* noalias nocapture writeonly sret(%struct.timespec) align 8 %0, %struct.timespec* nocapture byval(%struct.timespec) align 8 %1, %struct.timespec* nocapture byval(%struct.timespec) align 8 %2) {
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%5 = load i64, i64* %4
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%7 = load i64, i64* %6
%8 = sub i64 %5, %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sub nsw i64 %10, %12
%14 = icmp slt i64 %13, 0
%15 = add nsw i64 %13, 1000000000
%16 = ashr i64 %13, 63
%17 = add nsw i64 %8, %16
%18 = select i1 %14, i64 %15, i64 %13
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i64 %17, i64* %19
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %18, i64* %20
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 2
%22 = bitcast i64* %21 to i8*
ret void
}