#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ uint64_t;
typedef int /*<<< orphan*/ uint32_t;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ server_address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ gets(char *);
int /*<<< orphan*/ htonl(int);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int recv(int, char *, int, int /*<<< orphan*/);
int send(int, int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int main() {
  int sock = socket(AF_INET, SOCK_STREAM, 0);
  struct sockaddr_in server_address;
  struct hostent *server = gethostbyname("localhost");
  int port = 51717;
  int out;
  char reply[64] = "";
  uint32_t temp;
  bzero((char *)&server_address, sizeof(server_address));
  server_address.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&server_address.sin_addr.s_addr,
        server->h_length);
  server_address.sin_port = htons(port);
  connect(sock, (struct sockaddr *)&server_address, sizeof(server_address));
  int keyRequest = 0;
  char buffer[80];
  printf(
      "Buffer[0]: %p 	Buffer[79]: %p	 Buffer: %p 	keyRequest: %p\n",
      &buffer[0], &buffer[79], &buffer, &keyRequest);
  printf("Input: ");
  gets(buffer);
  temp = htonl(keyRequest);
  out = send(sock, &temp, sizeof(uint64_t), 0);
  out = recv(sock, reply, 64, 0);
  puts(reply);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
mov    0x2de6(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x8(%rbp)
lea    0xdfb(%rip),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
movl   $0xca05,-0x24(%rbp)
lea    -0x70(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1090 <memset@plt>
lea    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   10d0 <bzero@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x18(%rbp),%rsi
add    $0x4,%rsi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   10c0 <bcopy@plt>
mov    -0x24(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0xc,%edx
call   10e0 <connect@plt>
movl   $0x0,-0x78(%rbp)
lea    -0xd0(%rbp),%rsi
lea    -0xd0(%rbp),%rdx
add    $0x4f,%rdx
lea    0xd74(%rip),%rdi
lea    -0xd0(%rbp),%rcx
lea    -0x78(%rbp),%r8
mov    $0x0,%al
call   1070 <printf@plt>
lea    0xd96(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0xd0(%rbp),%rdi
call   10b0 <gets@plt>
mov    -0x78(%rbp),%edi
call   1080 <htonl@plt>
mov    %eax,-0x74(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x74(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
mov    %eax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x28(%rbp)
lea    -0x70(%rbp),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0xb8,%rsp
mov    0x2e14(%rip),%r15
mov    (%r15),%edi
mov    0x2dfa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
lea    0xe10(%rip),%rdi
call   1090 <gethostbyname@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   10c0 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbx),%rsi
lea    0x14(%rsp),%rdi
mov    (%rbx),%edx
call   10b0 <memmove@plt>
mov    $0xca05,%edi
call   1050 <htons@plt>
mov    %eax,0x10(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
movl   $0x0,0x8(%rsp)
lea    0xaf(%rsp),%rdx
lea    0xd9e(%rip),%rdi
lea    0x60(%rsp),%rbx
lea    0x8(%rsp),%r8
mov    %rbx,%rsi
mov    %rbx,%rcx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xdbb(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10a0 <gets@plt>
mov    0x8(%rsp),%edi
call   1080 <htonl@plt>
mov    %eax,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    %ebp,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
lea    0x20(%rsp),%rbx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rbx,%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0xb8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [59 x i8] c"Buffer[0]: %p \09Buffer[79]: %p\09 Buffer: %p \09keyRequest: %p\0A\00"
@.str.2 = [8 x i8] c"Input: \00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.hostent*
%5 = alloca i32
%6 = alloca i32
%7 = alloca [64 x i8]
%8 = alloca i32
%9 = alloca i32
%10 = alloca [80 x i8]
store i32 0, i32* %1
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %2
%14 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
store %struct.hostent* %14, %struct.hostent** %4
store i32 51717, i32* %5
%15 = bitcast [64 x i8]* %7 to i8*
%16 = bitcast %struct.sockaddr_in* %3 to i8*
%17 = call i32 @bzero(i8* %16, i32 12)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %18, i32* %19
%20 = load %struct.hostent*, %struct.hostent** %4
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %20, i32 0, i32 1
%22 = load i64, i64* %21
%23 = inttoptr i64 %22 to i8*
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
%25 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %24, i32 0, i32 0
%26 = bitcast i32* %25 to i8*
%27 = load %struct.hostent*, %struct.hostent** %4
%28 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i32 0, i32 0
%29 = load i32, i32* %28
%30 = call i32 @bcopy(i8* %23, i8* %26, i32 %29)
%31 = load i32, i32* %5
%32 = call i32 @htons(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
store i32 %32, i32* %33
%34 = load i32, i32* %2
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i32 @connect(i32 %34, %struct.sockaddr* %35, i32 12)
store i32 0, i32* %9
%37 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%38 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 79
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %37, i8* %38, [80 x i8]* %10, i32* %9)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%41 = getelementptr inbounds [80 x i8], [80 x i8]* %10, i64 0, i64 0
%42 = call i32 @gets(i8* %41)
%43 = load i32, i32* %9
%44 = call i32 @htonl(i32 %43)
store i32 %44, i32* %8
%45 = load i32, i32* %2
%46 = call i32 @send(i32 %45, i32* %8, i32 4, i32 0)
store i32 %46, i32* %6
%47 = load i32, i32* %2
%48 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%49 = call i32 @recv(i32 %47, i8* %48, i32 64, i32 0)
store i32 %49, i32* %6
%50 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%51 = call i32 @puts(i8* %50)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [59 x i8] c"Buffer[0]: %p \09Buffer[79]: %p\09 Buffer: %p \09keyRequest: %p\0A\00"
@.str.2 = [8 x i8] c"Input: \00"
define i32 @main() {
%1 = alloca %struct.sockaddr_in
%2 = alloca [64 x i8]
%3 = alloca i32
%4 = alloca i32
%5 = alloca [80 x i8]
%6 = load i32, i32* @AF_INET
%7 = load i32, i32* @SOCK_STREAM
%8 = tail call i32 @socket(i32 %6, i32 %7, i32 0)
%9 = bitcast %struct.sockaddr_in* %1 to i8*
%10 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%12 = bitcast i32* %3 to i8*
%13 = call i32 @bzero(i8* %9, i32 12)
%14 = load i32, i32* @AF_INET
%15 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 2
store i32 %14, i32* %15
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 1
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to i8*
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 1, i32 0
%20 = bitcast i32* %19 to i8*
%21 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i32 @htons(i32 51717)
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %1, i64 0, i32 0
store i32 %23, i32* %24
%25 = bitcast %struct.sockaddr_in* %1 to %struct.sockaddr*
%26 = call i32 @connect(i32 %8, %struct.sockaddr* %25, i32 12)
%27 = bitcast i32* %4 to i8*
store i32 0, i32* %4
%28 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 0
%29 = getelementptr inbounds [80 x i8], [80 x i8]* %5, i64 0, i64 79
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([59 x i8], [59 x i8]* @.str.1, i64 0, i64 0), i8* %28, i8* %29, [80 x i8]* %5, i32* %4)
%31 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @gets(i8* %28)
%33 = load i32, i32* %4
%34 = call i32 @htonl(i32 %33)
store i32 %34, i32* %3
%35 = call i32 @send(i32 %8, i32* %3, i32 4, i32 0)
%36 = call i32 @recv(i32 %8, i8* %11, i32 64, i32 0)
%37 = call i32 @puts(i8* %11)
ret i32 0
}