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

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ recebe_mesmo(int, char *, int);
int send(int, void *, int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
long timerabs(struct timeval);
long timerdiff(struct timeval, struct timeval);
void ping1(int socket, long long *local, long long *remote, long *delta) {
  struct timeval t0, t1, tremote;
  int teste;
  gettimeofday(&t0, NULL);
  teste = send(socket, (void *)&t0, sizeof(t0), 0);
  if (teste == -1) {
    fprintf(stderr, "[ping]: send failed at socket %d!\n", socket);
    exit(1);
  }
  recebe_mesmo(socket, (char *)&tremote, sizeof(tremote));
  gettimeofday(&t1, NULL);
  *delta = timerdiff(t1, t0);
  *local = timerabs(t0) + *delta / 2;
  *remote = timerabs(tremote);
}


x86 assembly (clang, -O0):
<ping1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    11d6 <ping1+0x66>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe39(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x4(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   1080 <recebe_mesmo@plt>
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x30(%rbp),%edi
mov    -0x28(%rbp),%esi
call   1030 <timerdiff@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%edi
call   1070 <timerabs@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    $0x2,%esi
cqto
idiv   %rsi
add    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x38(%rbp),%edi
call   1070 <timerabs@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ping1>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     1213 <ping1+0xa3>
lea    0x10(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
call   1080 <recebe_mesmo@plt>
lea    0x18(%rsp),%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    0x18(%rsp),%edi
mov    0x8(%rsp),%esi
call   1030 <timerdiff@plt>
mov    %rax,(%r12)
mov    0x8(%rsp),%edi
call   1070 <timerabs@plt>
mov    (%r12),%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
add    %rcx,%rdx
sar    %rdx
add    %rax,%rdx
mov    %rdx,(%r15)
mov    0x10(%rsp),%edi
call   1070 <timerabs@plt>
mov    %rax,(%r14)
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    %ebp,%edx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"[ping]: send failed at socket %d!\0A\00"
define void @ping1(i32 %0, i64* %1, i64* %2, i64* %3) {
%5 = alloca i32
%6 = alloca i64*
%7 = alloca i64*
%8 = alloca i64*
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca %struct.timeval
%12 = alloca i32
store i32 %0, i32* %5
store i64* %1, i64** %6
store i64* %2, i64** %7
store i64* %3, i64** %8
%13 = call i32 @gettimeofday(%struct.timeval* %9, i32* null)
%14 = load i32, i32* %5
%15 = bitcast %struct.timeval* %9 to i8*
%16 = call i32 @send(i32 %14, i8* %15, i32 4, i32 0)
store i32 %16, i32* %12
%17 = load i32, i32* %12
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %24
19: ; preds = %4
%20 = load i32, i32* @stderr
%21 = load i32, i32* %5
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %21)
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %4
%25 = load i32, i32* %5
%26 = bitcast %struct.timeval* %11 to i8*
%27 = call i32 @recebe_mesmo(i32 %25, i8* %26, i32 4)
%28 = call i32 @gettimeofday(%struct.timeval* %10, i32* null)
%29 = getelementptr inbounds %struct.timeval, %struct.timeval* %10, i32 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%32 = load i32, i32* %31
%33 = call i64 @timerdiff(i32 %30, i32 %32)
%34 = load i64*, i64** %8
store i64 %33, i64* %34
%35 = getelementptr inbounds %struct.timeval, %struct.timeval* %9, i32 0, i32 0
%36 = load i32, i32* %35
%37 = call i64 @timerabs(i32 %36)
%38 = load i64*, i64** %8
%39 = load i64, i64* %38
%40 = sdiv i64 %39, 2
%41 = add nsw i64 %37, %40
%42 = load i64*, i64** %6
store i64 %41, i64* %42
%43 = getelementptr inbounds %struct.timeval, %struct.timeval* %11, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i64 @timerabs(i32 %44)
%46 = load i64*, i64** %7
store i64 %45, i64* %46
ret void
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
@stderr = global i32 0
@.str = [35 x i8] c"[ping]: send failed at socket %d!\0A\00"
define void @ping1(i32 %0, i64* nocapture writeonly %1, i64* nocapture writeonly %2, i64* nocapture %3) {
%5 = alloca %struct.timeval
%6 = alloca %struct.timeval
%7 = alloca %struct.timeval
%8 = bitcast %struct.timeval* %5 to i8*
%9 = bitcast %struct.timeval* %6 to i8*
%10 = bitcast %struct.timeval* %7 to i8*
%11 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%12 = call i32 @send(i32 %0, i8* %8, i32 4, i32 0)
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %18
14: ; preds = %4
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %0)
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %4
%19 = call i32 @recebe_mesmo(i32 %0, i8* %10, i32 4)
%20 = call i32 @gettimeofday(%struct.timeval* %6, i32* null)
%21 = getelementptr inbounds %struct.timeval, %struct.timeval* %6, i64 0, i32 0
%22 = load i32, i32* %21
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i64 0, i32 0
%24 = load i32, i32* %23
%25 = call i64 @timerdiff(i32 %22, i32 %24)
store i64 %25, i64* %3
%26 = load i32, i32* %23
%27 = call i64 @timerabs(i32 %26)
%28 = load i64, i64* %3
%29 = sdiv i64 %28, 2
%30 = add nsw i64 %29, %27
store i64 %30, i64* %1
%31 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i64 0, i32 0
%32 = load i32, i32* %31
%33 = call i64 @timerabs(i32 %32)
store i64 %33, i64* %2
ret void
}