#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 {
  int dummy;
};

/* Variables and functions */
long long ts_to_nsec(struct timespec);
long long diff_timespec(struct timespec start, struct timespec mid,
                        struct timespec end) {
  long long start_ns, mid_ns, end_ns;
  start_ns = ts_to_nsec(start);
  mid_ns = ts_to_nsec(mid);
  end_ns = ts_to_nsec(end);
  start_ns = (start_ns + end_ns) / 2;
  return mid_ns - start_ns;
}


x86 assembly (clang, -O0):
<diff_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0x10(%rbp)
mov    %edx,-0x18(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <ts_to_nsec@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%edi
call   1030 <ts_to_nsec@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%edi
call   1030 <ts_to_nsec@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rax
add    -0x30(%rbp),%rax
mov    $0x2,%ecx
cqto
idiv   %rcx
mov    %rax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<diff_timespec>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%r14d
mov    %esi,%ebp
call   1030 <ts_to_nsec@plt>
mov    %rax,%rbx
mov    %ebp,%edi
call   1030 <ts_to_nsec@plt>
mov    %rax,%rbp
mov    %r14d,%edi
call   1030 <ts_to_nsec@plt>
add    %rbx,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
add    %rax,%rcx
sar    %rcx
sub    %rcx,%rbp
mov    %rbp,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32 }
define i64 @diff_timespec(i32 %0, i32 %1, i32 %2) {
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca %struct.timespec
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 %0, i32* %10
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
store i32 %1, i32* %11
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
store i32 %2, i32* %12
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%14 = load i32, i32* %13
%15 = call i64 @ts_to_nsec(i32 %14)
store i64 %15, i64* %7
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%17 = load i32, i32* %16
%18 = call i64 @ts_to_nsec(i32 %17)
store i64 %18, i64* %8
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %6, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i64 @ts_to_nsec(i32 %20)
store i64 %21, i64* %9
%22 = load i64, i64* %7
%23 = load i64, i64* %9
%24 = add nsw i64 %22, %23
%25 = sdiv i64 %24, 2
store i64 %25, i64* %7
%26 = load i64, i64* %8
%27 = load i64, i64* %7
%28 = sub nsw i64 %26, %27
ret i64 %28
}

LLVM IR (-O2):
define i64 @diff_timespec(i32 %0, i32 %1, i32 %2) {
%4 = tail call i64 @ts_to_nsec(i32 %0)
%5 = tail call i64 @ts_to_nsec(i32 %1)
%6 = tail call i64 @ts_to_nsec(i32 %2)
%7 = add nsw i64 %6, %4
%8 = sdiv i64 %7, -2
%9 = add i64 %8, %5
ret i64 %9
}