#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 */
typedef int /*<<< orphan*/ t2;
struct sockaddr_in {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ receive_packet(int *, int *, int, int /*<<< orphan*/ *,
                                  int /*<<< orphan*/ *);
int /*<<< orphan*/ send_packet(int *, char *, int, int *, struct sockaddr_in *);
long sync_packet(int *sock, struct sockaddr_in *slave) {
  int t1[2], t2[2];
  send_packet(sock, "sync_packet", 11, t1, slave);
  receive_packet(sock, t2, sizeof(t2), NULL, NULL);
  return ((((long)t2[0] * 1000000000L) + t2[1]) -
          (((long)t1[0] * 1000000000L) + t1[1]));
}


x86 assembly (clang, -O0):
<sync_packet>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xebd(%rip),%rsi
mov    $0xb,%edx
call   1040 <send_packet@plt>
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0x8,%edx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rcx
call   1030 <receive_packet@plt>
movslq -0x20(%rbp),%rax
imul   $0x3b9aca00,%rax,%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
movslq -0x18(%rbp),%rcx
imul   $0x3b9aca00,%rcx,%rcx
movslq -0x14(%rbp),%rdx
add    %rdx,%rcx
sub    %rcx,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sync_packet>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r8
mov    %rdi,%rbx
lea    0xece(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xb,%edx
call   1040 <send_packet@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x8,%edx
xor    %ecx,%ecx
xor    %r8d,%r8d
call   1030 <receive_packet@plt>
movslq (%rsp),%rax
movslq 0x4(%rsp),%rcx
movslq 0x8(%rsp),%rdx
sub    %rdx,%rax
movslq 0xc(%rsp),%rdx
sub    %rdx,%rcx
imul   $0x3b9aca00,%rax,%rax
add    %rcx,%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [12 x i8] c"sync_packet\00"
define i64 @sync_packet(i32* %0, %struct.sockaddr_in* %1) {
%3 = alloca i32*
%4 = alloca %struct.sockaddr_in*
%5 = alloca [2 x i32]
%6 = alloca [2 x i32]
store i32* %0, i32** %3
store %struct.sockaddr_in* %1, %struct.sockaddr_in** %4
%7 = load i32*, i32** %3
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %4
%10 = call i32 @send_packet(i32* %7, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11, i32* %8, %struct.sockaddr_in* %9)
%11 = load i32*, i32** %3
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%13 = call i32 @receive_packet(i32* %11, i32* %12, i32 8, i32* null, i32* null)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = mul nsw i64 %16, 1000000000
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%19 = load i32, i32* %18
%20 = sext i32 %19 to i64
%21 = add nsw i64 %17, %20
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%23 = load i32, i32* %22
%24 = sext i32 %23 to i64
%25 = mul nsw i64 %24, 1000000000
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%27 = load i32, i32* %26
%28 = sext i32 %27 to i64
%29 = add nsw i64 %25, %28
%30 = sub nsw i64 %21, %29
ret i64 %30
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@.str = [12 x i8] c"sync_packet\00"
define i64 @sync_packet(i32* %0, %struct.sockaddr_in* %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = bitcast [2 x i32]* %3 to i8*
%6 = bitcast [2 x i32]* %4 to i8*
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%8 = call i32 @send_packet(i32* %0, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 11, i32* %7, %struct.sockaddr_in* %1)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%10 = call i32 @receive_packet(i32* %0, i32* %9, i32 8, i32* null, i32* null)
%11 = load i32, i32* %9
%12 = sext i32 %11 to i64
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%14 = load i32, i32* %13
%15 = sext i32 %14 to i64
%16 = load i32, i32* %7
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%19 = load i32, i32* %18
%20 = sext i32 %19 to i64
%21 = sub nsw i64 %12, %17
%22 = mul nsw i64 %21, 1000000000
%23 = sub nsw i64 %15, %20
%24 = add nsw i64 %23, %22
ret i64 %24
}