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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ bzero(int /*<<< orphan*/ *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd, sendbytes;
  char buf[1024];
  struct hostent *host;
  struct sockaddr_in serv_addr;
  if (argc < 3) {
    fprintf(stderr, "USAGE: ./client Hostname(or ip address) Text\n");
    exit(1);
  }
  if ((host = gethostbyname(argv[1])) == NULL) {
    perror("gethostbyname");
    exit(1);
  }
  memset(buf, 0, sizeof(buf));
  sprintf(buf, "%s", argv[2]);
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    exit(1);
  }
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(4321);
  serv_addr.sin_addr = *((struct in_addr *)host->h_addr);
  bzero(&(serv_addr.sin_zero), 8);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(struct sockaddr)) ==
      -1) {
    perror("connect");
    exit(1);
  }
  if ((sendbytes = send(sockfd, buf, strlen(buf), 0)) == -1) {
    perror("send");
    exit(1);
  }
  close(sockfd);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    1212 <main+0x42>
mov    0x2dde(%rip),%rax
mov    (%rax),%edi
lea    0xdfd(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <gethostbyname@plt>
mov    %rax,-0x428(%rbp)
cmp    $0x0,%rax
jne    1246 <main+0x76>
lea    0xdf7(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xdcd(%rip),%rsi
call   10c0 <sprintf@plt>
mov    0x2d6d(%rip),%rax
mov    (%rax),%edi
mov    0x2d4c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12af <main+0xdf>
lea    0xd9f(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x42c(%rbp)
mov    $0x10e1,%edi
call   1040 <htons@plt>
mov    %eax,-0x430(%rbp)
mov    -0x428(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%eax
mov    %eax,-0x434(%rbp)
lea    -0x438(%rbp),%rdi
mov    $0x8,%esi
call   10b0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x438(%rbp),%rsi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    1324 <main+0x154>
lea    0xd31(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x444(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x440(%rbp)
lea    -0x420(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x444(%rbp),%edi
mov    -0x440(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1050 <send@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    137f <main+0x1af>
lea    0xcde(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x410,%rsp
cmp    $0x2,%edi
jg     11ff <main+0x2f>
mov    0x2df1(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
call   1090 <gethostbyname@plt>
test   %rax,%rax
jne    121c <main+0x4c>
lea    0xe17(%rip),%rdi
jmp    12db <main+0x10b>
mov    %rax,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
mov    0x10(%rbp),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    0x2da2(%rip),%r14
mov    (%r14),%edi
mov    0x2d80(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   10f0 <socket@plt>
cmp    $0xffffffff,%eax
jne    1267 <main+0x97>
lea    0xdd7(%rip),%rdi
jmp    12db <main+0x10b>
mov    %eax,%ebp
mov    (%r14),%eax
mov    %eax,0xc(%rsp)
mov    $0x10e1,%edi
call   1050 <htons@plt>
mov    %eax,0x8(%rsp)
mov    (%rbx),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rsp)
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x8,%esi
call   10c0 <bzero@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10e0 <connect@plt>
cmp    $0xffffffff,%eax
jne    12b4 <main+0xe4>
lea    0xd91(%rip),%rdi
jmp    12db <main+0x10b>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
cmp    $0xffffffff,%eax
jne    12ea <main+0x11a>
lea    0xd70(%rip),%rdi
call   10b0 <perror@plt>
mov    $0x1,%edi
call   10d0 <exit@plt>
mov    %ebp,%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [46 x i8] c"USAGE: ./client Hostname(or ip address) Text\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@.str.2 = [3 x i8] c"%s\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [5 x i8] c"send\00"
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.hostent*
%10 = alloca %struct.sockaddr_in
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call %struct.hostent* @gethostbyname(i8* %20)
store %struct.hostent* %21, %struct.hostent** %9
%22 = icmp eq %struct.hostent* %21, null
br i1 %22, label %23, label %26
23: ; preds = %17
%24 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %17
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%28 = call i32 @memset(i8* %27, i32 0, i32 1024)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = load i32, i32* @AF_INET
%35 = load i32, i32* @SOCK_STREAM
%36 = call i32 @socket(i32 %34, i32 %35, i32 0)
store i32 %36, i32* %6
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %26
%39 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %26
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %42, i32* %43
%44 = call i32 @htons(i32 4321)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %44, i32* %45
%46 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%47 = load %struct.hostent*, %struct.hostent** %9
%48 = getelementptr inbounds %struct.hostent, %struct.hostent* %47, i32 0, i32 0
%49 = load i64, i64* %48
%50 = inttoptr i64 %49 to %struct.in_addr*
%51 = bitcast %struct.in_addr* %46 to i8*
%52 = bitcast %struct.in_addr* %50 to i8*
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%54 = call i32 @bzero(i32* %53, i32 8)
%55 = load i32, i32* %6
%56 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%57 = call i32 @connect(i32 %55, %struct.sockaddr* %56, i32 4)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %62
59: ; preds = %41
%60 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %41
%63 = load i32, i32* %6
%64 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%66 = call i32 @strlen(i8* %65)
%67 = call i32 @send(i32 %63, i8* %64, i32 %66, i32 0)
store i32 %67, i32* %7
%68 = icmp eq i32 %67, -1
br i1 %68, label %69, label %72
69: ; preds = %62
%70 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%71 = call i32 @exit(i32 1)
unreachable
72: ; preds = %62
%73 = load i32, i32* %6
%74 = call i32 @close(i32 %73)
%75 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.in_addr, i32, i32 }
%struct.in_addr = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [46 x i8] c"USAGE: ./client Hostname(or ip address) Text\0A\00"
@.str.1 = [14 x i8] c"gethostbyname\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [7 x i8] c"socket\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [5 x i8] c"send\00"
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 = icmp slt i32 %0, 3
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit(i32 1)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call %struct.hostent* @gethostbyname(i8* %14)
%16 = icmp eq %struct.hostent* %15, null
br i1 %16, label %17, label %20
17: ; preds = %12
%18 = tail call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %12
%21 = call i32 @memset(i8* %5, i32 0, i32 1024)
%22 = getelementptr inbounds i8*, i8** %1, i64 2
%23 = load i8*, i8** %22
%24 = call i8* @strcpy(i8* %5, i8* dereferenceable(1) %23)
%25 = load i32, i32* @AF_INET
%26 = load i32, i32* @SOCK_STREAM
%27 = call i32 @socket(i32 %25, i32 %26, i32 0)
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %20
%30 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %20
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 3
store i32 %33, i32* %34
%35 = call i32 @htons(i32 4321)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %35, i32* %36
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i64 0, i32 0
%38 = load i64, i64* %37
%39 = inttoptr i64 %38 to i32*
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
%41 = load i32, i32* %39
store i32 %41, i32* %40
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%43 = call i32 @bzero(i32* %42, i32 8)
%44 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%45 = call i32 @connect(i32 %27, %struct.sockaddr* %44, i32 4)
%46 = icmp eq i32 %45, -1
br i1 %46, label %47, label %50
47: ; preds = %32
%48 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %32
%51 = call i32 @strlen(i8* %5)
%52 = call i32 @send(i32 %27, i8* %5, i32 %51, i32 0)
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %57
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%56 = call i32 @exit(i32 1)
unreachable
57: ; preds = %50
%58 = call i32 @close(i32 %27)
%59 = call i32 @exit(i32 0)
unreachable
}