#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__ member_1;
  scalar_t__ tv_nsec;
  int /*<<< orphan*/ member_0;
  scalar_t__ tv_sec;
};

/* Variables and functions */
struct timespec pdifftime(struct timespec before, struct timespec after) {
  struct timespec ts = {after.tv_sec - before.tv_sec -
                            (after.tv_nsec < before.tv_nsec ? 1 : 0),
                        after.tv_nsec < before.tv_nsec
                            ? 1000000000 + after.tv_nsec - before.tv_nsec
                            : after.tv_nsec - before.tv_nsec};
  return ts;
}


x86 assembly (clang, -O0):
<pdifftime>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x28(%rbp)
mov    %rdi,%rax
mov    %rax,-0x20(%rbp)
lea    0x30(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0x10(%rbp),%rcx
mov    %rcx,-0x10(%rbp)
mov    0x18(%rax),%rdx
sub    0x18(%rcx),%rdx
mov    0x8(%rax),%r9
mov    0x8(%rcx),%r10
xor    %esi,%esi
mov    $0x1,%r8d
cmp    %r10,%r9
cmovl  %r8d,%esi
movslq %esi,%rsi
sub    %rsi,%rdx
mov    %rdx,(%rdi)
add    $0x8,%rdi
mov    %rdi,-0x8(%rbp)
mov    0x8(%rax),%rax
cmp    0x8(%rcx),%rax
jge    117c <pdifftime+0x7c>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
add    $0x3b9aca00,%rax
sub    0x8(%rcx),%rax
mov    %rax,-0x30(%rbp)
jmp    1190 <pdifftime+0x90>
mov    -0x10(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    0x8(%rax),%rax
sub    0x8(%rcx),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rdx
mov    -0x30(%rbp),%rsi
mov    %rsi,(%rdx)
movl   $0x0,0x10(%rcx)
movq   $0x0,0x18(%rcx)
pop    %rbp
ret

x86 assembly (clang, -O2):
<pdifftime>:
mov    %rdi,%rax
mov    0x30(%rsp),%rcx
mov    0x40(%rsp),%rdx
sub    0x20(%rsp),%rdx
mov    0x10(%rsp),%r8
lea    0x3b9aca00(%rcx),%rdi
xor    %esi,%esi
cmp    %r8,%rcx
setl   %sil
cmovge %rcx,%rdi
sub    %rsi,%rdx
mov    %rdx,(%rax)
sub    %r8,%rdi
mov    %rdi,0x8(%rax)
movl   $0x0,0x10(%rax)
movq   $0x0,0x18(%rax)
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64, i32, i64 }
define void @pdifftime(%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* %0, i64 0, i32 0
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 3
%6 = load i64, i64* %5
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 3
%8 = load i64, i64* %7
%9 = sub i64 %6, %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%11 = load i64, i64* %10
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%13 = load i64, i64* %12
%14 = icmp slt i64 %11, %13
%15 = sext i1 %14 to i64
%16 = add i64 %9, %15
store i64 %16, i64* %4
%17 = add nsw i64 %11, 1000000000
%18 = select i1 %14, i64 %17, i64 %11
%19 = sub nsw i64 %18, %13
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %19, i64* %20
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 2
store i32 0, i32* %21
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 3
store i64 0, i64* %22
ret void
}