#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*/ t0;
struct timeval {
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ remotenamelen;

/* Variables and functions */
int /*<<< orphan*/ ping1(int, long long *, long long *, long *);
int /*<<< orphan*/ recebe_mesmo(int, char *, int);
int /*<<< orphan*/ send(int, void *, int, int /*<<< orphan*/);
void ping(int socket, long long *mlocal, long long *mremote, char *remotename) {
  long delta;
  long long local, remote;
  long mdelta = 1e9;
  int i;
  struct timeval t0 = {0, 0};
  int remotenamelen;
  recebe_mesmo(socket, (char *)&remotenamelen, sizeof(remotenamelen));
  recebe_mesmo(socket, remotename, remotenamelen);
  remotename[remotenamelen] = '\0';
  for (i = 0; i < 1000; i++) {
    ping1(socket, &local, &remote, &delta);
    if (delta <= mdelta) {
      mdelta = delta;
      *mlocal = local;
      *mremote = remote;
    }
  }
  send(socket, (void *)&t0, sizeof(t0), 0);
}


x86 assembly (clang, -O0):
<ping>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x3b9aca00,-0x40(%rbp)
3b
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1050 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x54(%rbp),%rsi
mov    $0x4,%edx
call   1060 <recebe_mesmo@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x54(%rbp),%edx
call   1060 <recebe_mesmo@plt>
mov    -0x20(%rbp),%rax
movslq -0x54(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x44(%rbp)
cmpl   $0x3e8,-0x44(%rbp)
jge    1202 <ping+0xc2>
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x38(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1030 <ping1@plt>
mov    -0x28(%rbp),%rax
cmp    -0x40(%rbp),%rax
jg     11ef <ping+0xaf>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    11f4 <ping+0xb4>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    11a2 <ping+0x62>
mov    -0x4(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ping>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%rbp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %edi,%ebx
movq   $0x0,0x18(%rsp)
lea    0x4(%rsp),%rsi
mov    $0x4,%edx
call   1050 <recebe_mesmo@plt>
mov    0x4(%rsp),%edx
mov    %ebx,%edi
mov    %rbp,%rsi
call   1050 <recebe_mesmo@plt>
movslq 0x4(%rsp),%rax
movb   $0x0,0x0(%rbp,%rax,1)
mov    $0x3b9aca00,%r15d
mov    $0x3e8,%r14d
lea    0x28(%rsp),%r12
lea    0x20(%rsp),%r13
lea    0x30(%rsp),%rbp
jmp    11a6 <ping+0x76>
nopw   0x0(%rax,%rax,1)
add    $0xffffffff,%r14d
je     11df <ping+0xaf>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rbp,%rcx
call   1030 <ping1@plt>
mov    0x30(%rsp),%rax
cmp    %r15,%rax
jg     11a0 <ping+0x70>
mov    0x28(%rsp),%rcx
mov    0x8(%rsp),%rdx
mov    %rcx,(%rdx)
mov    0x20(%rsp),%rcx
mov    0x10(%rsp),%rdx
mov    %rcx,(%rdx)
mov    %rax,%r15
jmp    11a0 <ping+0x70>
lea    0x18(%rsp),%rsi
mov    %ebx,%edi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
define void @ping(i32 %0, i64* %1, i64* %2, i8* %3) {
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i64
%13 = alloca i32
%14 = alloca %struct.timeval
%15 = alloca i32
store i32 %0, i32* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i8* %3, i8** %8
store i64 1000000000, i64* %12
%16 = bitcast %struct.timeval* %14 to i8*
%17 = load i32, i32* %5
%18 = bitcast i32* %15 to i8*
%19 = call i32 @recebe_mesmo(i32 %17, i8* %18, i32 4)
%20 = load i32, i32* %5
%21 = load i8*, i8** %8
%22 = load i32, i32* %15
%23 = call i32 @recebe_mesmo(i32 %20, i8* %21, i32 %22)
%24 = load i8*, i8** %8
%25 = load i32, i32* %15
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
store i8 0, i8* %27
store i32 0, i32* %13
br label %28
28: ; preds = %44, %4
%29 = load i32, i32* %13
%30 = icmp slt i32 %29, 1000
br i1 %30, label %31, label %47
31: ; preds = %28
%32 = load i32, i32* %5
%33 = call i32 @ping1(i32 %32, i64* %10, i64* %11, i64* %9)
%34 = load i64, i64* %9
%35 = load i64, i64* %12
%36 = icmp sle i64 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %31
%38 = load i64, i64* %9
store i64 %38, i64* %12
%39 = load i64, i64* %10
%40 = load i64*, i64** %6
store i64 %39, i64* %40
%41 = load i64, i64* %11
%42 = load i64*, i64** %7
store i64 %41, i64* %42
br label %43
43: ; preds = %37, %31
br label %44
44: ; preds = %43
%45 = load i32, i32* %13
%46 = add nsw i32 %45, 1
store i32 %46, i32* %13
br label %28
47: ; preds = %28
%48 = load i32, i32* %5
%49 = bitcast %struct.timeval* %14 to i8*
%50 = call i32 @send(i32 %48, i8* %49, i32 8, i32 0)
ret void
}

LLVM IR (-O2):
define void @ping(i32 %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2, i8* %3) {
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i32
%10 = bitcast i64* %5 to i8*
%11 = bitcast i64* %6 to i8*
%12 = bitcast i64* %7 to i8*
%13 = bitcast i64* %8 to i8*
store i64 0, i64* %8
%14 = bitcast i32* %9 to i8*
%15 = call i32 @recebe_mesmo(i32 %0, i8* %14, i32 4)
%16 = load i32, i32* %9
%17 = call i32 @recebe_mesmo(i32 %0, i8* %3, i32 %16)
%18 = load i32, i32* %9
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %3, i64 %19
store i8 0, i8* %20
br label %21
21: ; preds = %4, %30
%22 = phi i32 [ 0, %4 ], [ %32, %30 ]
%23 = phi i64 [ 1000000000, %4 ], [ %31, %30 ]
%24 = call i32 @ping1(i32 %0, i64* %6, i64* %7, i64* %5)
%25 = load i64, i64* %5
%26 = icmp sgt i64 %25, %23
br i1 %26, label %30, label %27
27: ; preds = %21
%28 = load i64, i64* %6
store i64 %28, i64* %1
%29 = load i64, i64* %7
store i64 %29, i64* %2
br label %30
30: ; preds = %21, %27
%31 = phi i64 [ %25, %27 ], [ %23, %21 ]
%32 = add nuw nsw i32 %22, 1
%33 = icmp eq i32 %32, 1000
br i1 %33, label %34, label %21
34: ; preds = %30
%35 = call i32 @send(i32 %0, i8* %13, i32 8, i32 0)
ret void
}