#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*/ tvo;
typedef int /*<<< orphan*/ tvi;
struct timeval {
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ namesize;
typedef int /*<<< orphan*/ hostname;

/* Variables and functions */
int MAXHOSTNAMELEN;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ gethostname(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;
int strlen(char *);
void pong(int socket) {
  struct timeval tvi, tvo;
  int teste;
  int namesize;
  char hostname[MAXHOSTNAMELEN];
  gethostname(hostname, sizeof(hostname));
  namesize = strlen(hostname);
  send(socket, (char *)&namesize, sizeof(namesize), 0);
  send(socket, hostname, namesize, 0);
  do {
    recebe_mesmo(socket, (char *)&tvi, sizeof(tvi));
    gettimeofday(&tvo, NULL);
    teste = send(socket, (void *)&tvo, sizeof(tvo), 0);
    if (teste == -1) {
      fprintf(stderr, "[pong]: send failed at socket %d!\n", socket);
      exit(1);
    }
  } while (tvi.tv_sec != 0);
}


x86 assembly (clang, -O0):
<pong>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e66(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    %eax,%esi
call   1080 <gethostname@plt>
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x38(%rbp),%rsi
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x8,%edx
call   1070 <recebe_mesmo@plt>
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1050 <gettimeofday@plt>
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    123e <pong+0xce>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xdd1(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    1243 <pong+0xd3>
cmpq   $0x0,-0x10(%rbp)
jne    11de <pong+0x6e>
mov    -0x28(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pong>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %edi,%ebx
mov    %rsp,%r12
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
mov    %r14,%rdi
call   1080 <gethostname@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %eax,-0x24(%rbp)
lea    -0x24(%rbp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
mov    -0x24(%rbp),%edx
mov    %ebx,%edi
mov    %r14,%rsi
xor    %ecx,%ecx
call   1040 <send@plt>
lea    -0x30(%rbp),%r14
lea    -0x38(%rbp),%r15
nopl   (%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x8,%edx
call   1070 <recebe_mesmo@plt>
mov    %r15,%rdi
xor    %esi,%esi
call   1050 <gettimeofday@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x8,%edx
xor    %ecx,%ecx
call   1040 <send@plt>
cmp    $0xffffffff,%eax
je     1226 <pong+0xb6>
cmpq   $0x0,-0x30(%rbp)
jne    11e0 <pong+0x70>
mov    %r12,%rsp
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
mov    %ebx,%edx
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

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

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