#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 const tv_sec;
  int tv_nsec;
};
typedef int int64_t;

/* Variables and functions */
int64_t get_time_sync_error(const struct timespec *const master_start_time,
                            const struct timespec *const master_end_time,
                            const struct timespec *const slave_time) {
  const int64_t nsecs_per_sec = 1000000000;
  const int64_t master_start_time_ns =
      (master_start_time->tv_sec * nsecs_per_sec) + master_start_time->tv_nsec;
  const int64_t master_end_time_ns =
      (master_end_time->tv_sec * nsecs_per_sec) + master_end_time->tv_nsec;
  const int64_t round_trip_time_ns = master_end_time_ns - master_start_time_ns;
  const int64_t slave_time_ns =
      (slave_time->tv_sec * nsecs_per_sec) + slave_time->tv_nsec;
  const int64_t master_mid_time_ns =
      master_start_time_ns + (round_trip_time_ns / 2);
  return slave_time_ns - master_mid_time_ns;
}


x86 assembly (clang, -O0):
<get_time_sync_error>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x3b9aca00,-0x1c(%rbp)
mov    -0x8(%rbp),%rax
imul   $0x3b9aca00,(%rax),%eax
mov    -0x8(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
imul   $0x3b9aca00,(%rax),%eax
mov    -0x10(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sub    -0x20(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
imul   $0x3b9aca00,(%rax),%eax
mov    -0x18(%rbp),%rcx
add    0x4(%rcx),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x2c(%rbp),%eax
sub    -0x30(%rbp),%eax
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_time_sync_error>:
imul   $0xc4653600,(%rdi),%eax
sub    0x4(%rdi),%eax
imul   $0x3b9aca00,(%rsi),%ecx
mov    0x4(%rsi),%esi
add    %eax,%esi
imul   $0x3b9aca00,(%rdx),%edi
add    %ecx,%esi
mov    %esi,%ecx
shr    $0x1f,%ecx
add    %esi,%ecx
sar    %ecx
add    0x4(%rdx),%eax
add    %edi,%eax
sub    %ecx,%eax
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define i32 @get_time_sync_error(%struct.timespec* %0, %struct.timespec* %1, %struct.timespec* %2) {
%4 = alloca %struct.timespec*
%5 = alloca %struct.timespec*
%6 = alloca %struct.timespec*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
store %struct.timespec* %0, %struct.timespec** %4
store %struct.timespec* %1, %struct.timespec** %5
store %struct.timespec* %2, %struct.timespec** %6
store i32 1000000000, i32* %7
%13 = load %struct.timespec*, %struct.timespec** %4
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
%15 = load i32, i32* %14
%16 = mul nsw i32 %15, 1000000000
%17 = load %struct.timespec*, %struct.timespec** %4
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 1
%19 = load i32, i32* %18
%20 = add nsw i32 %16, %19
store i32 %20, i32* %8
%21 = load %struct.timespec*, %struct.timespec** %5
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %21, i32 0, i32 0
%23 = load i32, i32* %22
%24 = mul nsw i32 %23, 1000000000
%25 = load %struct.timespec*, %struct.timespec** %5
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %25, i32 0, i32 1
%27 = load i32, i32* %26
%28 = add nsw i32 %24, %27
store i32 %28, i32* %9
%29 = load i32, i32* %9
%30 = load i32, i32* %8
%31 = sub nsw i32 %29, %30
store i32 %31, i32* %10
%32 = load %struct.timespec*, %struct.timespec** %6
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = mul nsw i32 %34, 1000000000
%36 = load %struct.timespec*, %struct.timespec** %6
%37 = getelementptr inbounds %struct.timespec, %struct.timespec* %36, i32 0, i32 1
%38 = load i32, i32* %37
%39 = add nsw i32 %35, %38
store i32 %39, i32* %11
%40 = load i32, i32* %8
%41 = load i32, i32* %10
%42 = sdiv i32 %41, 2
%43 = add nsw i32 %40, %42
store i32 %43, i32* %12
%44 = load i32, i32* %11
%45 = load i32, i32* %12
%46 = sub nsw i32 %44, %45
ret i32 %46
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define i32 @get_time_sync_error(%struct.timespec* nocapture %0, %struct.timespec* nocapture %1, %struct.timespec* nocapture %2) {
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%5 = load i32, i32* %4
%6 = mul i32 %5, -1000000000
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%8 = load i32, i32* %7
%9 = sub i32 %6, %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%11 = load i32, i32* %10
%12 = mul nsw i32 %11, 1000000000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%14 = load i32, i32* %13
%15 = add i32 %14, %9
%16 = add i32 %15, %12
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%18 = load i32, i32* %17
%19 = mul nsw i32 %18, 1000000000
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%21 = load i32, i32* %20
%22 = sdiv i32 %16, -2
%23 = add i32 %21, %9
%24 = add i32 %23, %19
%25 = add i32 %24, %22
ret i32 %25
}