#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 timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ RECV(char *, int, int);
int /*<<< orphan*/ SEND(char *, int, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int sockPing() {
  char data[32];
  struct timeval tv, tvn;
  memset(data, 0, sizeof(data));
  gettimeofday(&tv, NULL);
  SEND(data, 32, 0x00000000);
  RECV(data, 32, 0x00000000);
  gettimeofday(&tvn, NULL);
  return (int)(tvn.tv_sec - tv.tv_sec) * 1000 +
         (tvn.tv_usec - tv.tv_usec) / 1000;
}


x86 assembly (clang, -O0):
<sockPing>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
lea    -0x20(%rbp),%rdi
mov    $0x20,%esi
xor    %edx,%edx
call   1050 <SEND@plt>
lea    -0x20(%rbp),%rdi
mov    $0x20,%esi
xor    %edx,%edx
call   1060 <RECV@plt>
lea    -0x40(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x38(%rbp),%rax
sub    -0x28(%rbp),%rax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x44(%rbp)
mov    -0x40(%rbp),%eax
sub    -0x30(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x44(%rbp),%eax
add    %ecx,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockPing>:
push   %rbx
sub    $0x40,%rsp
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
xor    %edx,%edx
call   1050 <SEND@plt>
mov    %rbx,%rdi
mov    $0x20,%esi
xor    %edx,%edx
call   1060 <RECV@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    (%rsp),%eax
mov    0x8(%rsp),%ecx
sub    0x18(%rsp),%ecx
imul   $0x3e8,%ecx,%ecx
sub    0x10(%rsp),%eax
cltq
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rax
add    %edx,%eax
add    %ecx,%eax
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i64 }
define i32 @sockPing() {
%1 = alloca [32 x i8]
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = call i32 @memset(i8* %4, i32 0, i32 32)
%6 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%8 = call i32 @SEND(i8* %7, i32 32, i32 0)
%9 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%10 = call i32 @RECV(i8* %9, i32 32, i32 0)
%11 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%15 = load i64, i64* %14
%16 = sub nsw i64 %13, %15
%17 = trunc i64 %16 to i32
%18 = mul nsw i32 %17, 1000
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%22 = load i32, i32* %21
%23 = sub nsw i32 %20, %22
%24 = sdiv i32 %23, 1000
%25 = add nsw i32 %18, %24
ret i32 %25
}

LLVM IR (-O2):
%struct.timeval = type { i32, i64 }
define i32 @sockPing() {
%1 = alloca [32 x i8]
%2 = alloca %struct.timeval
%3 = alloca %struct.timeval
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = bitcast %struct.timeval* %2 to i8*
%6 = bitcast %struct.timeval* %3 to i8*
%7 = call i32 @memset(i8* %4, i32 0, i32 32)
%8 = call i32 @gettimeofday(%struct.timeval* %2, i32* null)
%9 = call i32 @SEND(i8* %4, i32 32, i32 0)
%10 = call i32 @RECV(i8* %4, i32 32, i32 0)
%11 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%13 = load i64, i64* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%15 = load i64, i64* %14
%16 = sub nsw i64 %13, %15
%17 = trunc i64 %16 to i32
%18 = mul nsw i32 %17, 1000
%19 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%20 = load i32, i32* %19
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%22 = load i32, i32* %21
%23 = sub nsw i32 %20, %22
%24 = sdiv i32 %23, 1000
%25 = add nsw i32 %24, %18
ret i32 %25
}