#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_sec;
  int tv_usec;
};
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 (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    $0x40,%rsp
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    -0x28(%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    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x30(%rbp),%eax
sub    -0x28(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x34(%rbp)
mov    -0x2c(%rbp),%eax
sub    -0x24(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
add    %ecx,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sockPing>:
push   %rbx
sub    $0x30,%rsp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
lea    0x8(%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    0x4(%rsp),%ecx
sub    0x8(%rsp),%eax
imul   $0x3e8,%eax,%edx
sub    0xc(%rsp),%ecx
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
add    %edx,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
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 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = mul nsw i32 %16, 1000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %19, %21
%23 = sdiv i32 %22, 1000
%24 = add nsw i32 %17, %23
ret i32 %24
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
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 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%15 = load i32, i32* %14
%16 = sub nsw i32 %13, %15
%17 = mul nsw i32 %16, 1000
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%21 = load i32, i32* %20
%22 = sub nsw i32 %19, %21
%23 = sdiv i32 %22, 1000
%24 = add nsw i32 %23, %17
ret i32 %24
}