#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 ptp_clock_time {
  long long sec;
  long long nsec;
};

/* Variables and functions */
long long ptpclock_delta(const struct ptp_clock_time *pc1,
                         const struct ptp_clock_time *pc2) {
  long long s;
  long long n;
  long long delta;
  s = (long long)pc2->sec - pc1->sec;
  n = (long long)pc2->nsec - pc1->nsec;
  if (n < 0) {
    s -= 1;
    n += (1000000000L);
  }
  delta = s * (1000000000L) + n;
  return (delta);
}


x86 assembly (clang, -O0):
<ptpclock_delta>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x8(%rbp),%rcx
sub    (%rcx),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x8(%rbp),%rcx
sub    0x8(%rcx),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1157 <ptpclock_delta+0x57>
mov    -0x18(%rbp),%rax
sub    $0x1,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
add    $0x3b9aca00,%rax
mov    %rax,-0x20(%rbp)
imul   $0x3b9aca00,-0x18(%rbp),%rax
3b
add    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptpclock_delta>:
mov    (%rsi),%rax
mov    0x8(%rsi),%rcx
sub    (%rdi),%rax
sub    0x8(%rdi),%rcx
lea    0x3b9aca00(%rcx),%rdx
test   %rcx,%rcx
cmovns %rcx,%rdx
sar    $0x3f,%rcx
add    %rax,%rcx
imul   $0x3b9aca00,%rcx,%rax
add    %rdx,%rax
ret

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

LLVM IR (-O2):
%struct.ptp_clock_time = type { i64, i64 }
define i64 @ptpclock_delta(%struct.ptp_clock_time* nocapture %0, %struct.ptp_clock_time* nocapture %1) {
%3 = getelementptr inbounds %struct.ptp_clock_time, %struct.ptp_clock_time* %1, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.ptp_clock_time, %struct.ptp_clock_time* %0, i64 0, i32 0
%6 = load i64, i64* %5
%7 = sub i64 %4, %6
%8 = getelementptr inbounds %struct.ptp_clock_time, %struct.ptp_clock_time* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = getelementptr inbounds %struct.ptp_clock_time, %struct.ptp_clock_time* %0, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sub nsw i64 %9, %11
%13 = icmp slt i64 %12, 0
%14 = add nsw i64 %12, 1000000000
%15 = select i1 %13, i64 %14, i64 %12
%16 = ashr i64 %12, 63
%17 = add nsw i64 %7, %16
%18 = mul nsw i64 %17, 1000000000
%19 = add nsw i64 %18, %15
ret i64 %19
}