#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 sockaddr_in {
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(int /*<<< orphan*/);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int sd, msg_len;
  char message[1024];
  struct sockaddr_in addr;
  struct hostent *hostent;
  sd = socket(PF_INET, SOCK_STREAM, 0);
  hostent = gethostbyname(argv[1]);
  addr.sin_family = AF_INET;
  addr.sin_port = htons(7);
  memcpy(&addr.sin_addr, hostent->h_addr, hostent->h_length);
  connect(sd, (struct sockaddr *)&addr, sizeof(addr));
  msg_len = strlen(fgets(message, 1024, stdin));
  write(sd, message, msg_len);
  memset(message, 0, 1024);
  msg_len = read(sd, message, 1024);
  write(STDOUT_FILENO, message, msg_len);
  close(sd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2de0(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x438(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x428(%rbp)
mov    $0x7,%edi
call   1050 <htons@plt>
mov    %eax,-0x42c(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x438(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x438(%rbp),%rax
mov    (%rax),%edx
call   10b0 <memcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
lea    -0x420(%rbp),%rdi
mov    0x2d6f(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    %eax,%edi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d2e(%rip),%rax
mov    (%rax),%edi
lea    -0x420(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    0x2ded(%rip),%rax
mov    (%rax),%edi
mov    0x2dec(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10e0 <socket@plt>
mov    %eax,%ebp
mov    0x8(%rbx),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,%rbx
mov    0x2de6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
mov    $0x7,%edi
call   1050 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10b0 <memcpy@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   10d0 <connect@plt>
mov    0x2da4(%rip),%rax
mov    (%rax),%edx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1090 <fgets@plt>
mov    %eax,%edi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1080 <read@plt>
mov    0x2d70(%rip),%rcx
mov    (%rcx),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %ebp,%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@stdin = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [1024 x i8]
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.hostent*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @PF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = call i32 @socket(i32 %11, i32 %12, i32 0)
store i32 %13, i32* %6
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call %struct.hostent* @gethostbyname(i8* %16)
store %struct.hostent* %17, %struct.hostent** %10
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %18, i32* %19
%20 = call i32 @htons(i32 7)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %20, i32* %21
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%23 = load %struct.hostent*, %struct.hostent** %10
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 1
%25 = load i32, i32* %24
%26 = load %struct.hostent*, %struct.hostent** %10
%27 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i32 0, i32 0
%28 = load i32, i32* %27
%29 = call i32 @memcpy(i32* %22, i32 %25, i32 %28)
%30 = load i32, i32* %6
%31 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%32 = call i32 @connect(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%34 = load i32, i32* @stdin
%35 = call i32 @fgets(i8* %33, i32 1024, i32 %34)
%36 = call i32 @strlen(i32 %35)
store i32 %36, i32* %7
%37 = load i32, i32* %6
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%39 = load i32, i32* %7
%40 = call i32 @write(i32 %37, i8* %38, i32 %39)
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%42 = call i32 @memset(i8* %41, i32 0, i32 1024)
%43 = load i32, i32* %6
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%45 = call i32 @read(i32 %43, i8* %44, i32 1024)
store i32 %45, i32* %7
%46 = load i32, i32* @STDOUT_FILENO
%47 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%48 = load i32, i32* %7
%49 = call i32 @write(i32 %46, i8* %47, i32 %48)
%50 = load i32, i32* %6
%51 = call i32 @close(i32 %50)
%52 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@stdin = global i32 0
@STDOUT_FILENO = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = load i32, i32* @PF_INET
%8 = load i32, i32* @SOCK_STREAM
%9 = tail call i32 @socket(i32 %7, i32 %8, i32 0)
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = tail call %struct.hostent* @gethostbyname(i8* %11)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 7)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %15, i32* %16
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 1
%19 = load i32, i32* %18
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %12, i64 0, i32 0
%21 = load i32, i32* %20
%22 = call i32 @memcpy(i32* %17, i32 %19, i32 %21)
%23 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%24 = call i32 @connect(i32 %9, %struct.sockaddr* %23, i32 12)
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %5, i32 1024, i32 %25)
%27 = call i32 @strlen(i32 %26)
%28 = call i32 @write(i32 %9, i8* %5, i32 %27)
%29 = call i32 @memset(i8* %5, i32 0, i32 1024)
%30 = call i32 @read(i32 %9, i8* %5, i32 1024)
%31 = load i32, i32* @STDOUT_FILENO
%32 = call i32 @write(i32 %31, i8* %5, i32 %30)
%33 = call i32 @close(i32 %9)
%34 = call i32 @exit(i32 0)
unreachable
}