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

/* Variables and functions */
struct timespec time_diff(struct timespec start, struct timespec stop) {
  struct timespec time = {0, 0};
  if ((stop.tv_nsec - start.tv_nsec) < 0) {
    time.tv_sec = stop.tv_sec - start.tv_sec - 1;
    time.tv_nsec = 1000000000 + stop.tv_nsec - start.tv_nsec;
  } else {
    time.tv_sec = stop.tv_sec - start.tv_sec;
    time.tv_nsec = stop.tv_nsec - start.tv_nsec;
  }
  return time;
}


x86 assembly (clang, -O0):
<time_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x20(%rbp)
mov    %rdi,%rax
mov    %rax,-0x18(%rbp)
lea    0x28(%rbp),%rax
mov    %rax,-0x10(%rbp)
lea    0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
xor    %esi,%esi
mov    $0x18,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rax
mov    -0x8(%rbp),%rcx
mov    (%rax),%rax
sub    (%rcx),%rax
cmp    $0x0,%rax
jge    1188 <time_diff+0x78>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rsi
sub    0x8(%rdx),%rsi
sub    $0x1,%rsi
mov    %rsi,0x8(%rax)
mov    (%rcx),%rcx
add    $0x3b9aca00,%rcx
sub    (%rdx),%rcx
mov    %rcx,(%rax)
jmp    11a9 <time_diff+0x99>
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    0x8(%rcx),%rsi
sub    0x8(%rdx),%rsi
mov    %rsi,0x8(%rax)
mov    (%rcx),%rcx
sub    (%rdx),%rcx
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_diff>:
mov    %rdi,%rax
mov    0x20(%rsp),%rcx
mov    0x8(%rsp),%r8
mov    0x10(%rsp),%rsi
lea    0x3b9aca00(%rcx),%rdi
mov    %rsi,%rdx
neg    %rdx
cmp    %r8,%rcx
not    %rsi
cmovge %rdx,%rsi
cmovge %rcx,%rdi
add    0x28(%rsp),%rsi
movq   $0x0,0x10(%rax)
sub    %r8,%rdi
mov    %rsi,0x8(%rax)
mov    %rdi,(%rax)
ret

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

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