#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 */
struct TYPE_2__ {
  unsigned long s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_addr;
};
typedef int /*<<< orphan*/ serveraddr;
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
scalar_t__ INADDR_NONE;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_ERROR;
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
char errno;
int /*<<< orphan*/ exit(int);
struct hostent *gethostbyname(char *);
int getsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/, char *, int *);
int h_errno;
int /*<<< orphan*/ htons(int);
unsigned long inet_addr(char *);
int /*<<< orphan*/ memcpy(TYPE_1__ *, int /*<<< orphan*/, int);
int /*<<< orphan*/ memset(struct sockaddr_in *, int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sd, rc, length = sizeof(int);
  struct sockaddr_in serveraddr;
  char buffer[257];
  char server[255];
  char temp;
  int totalcnt = 0;
  struct hostent *hostp;
  char data[100] = "Test string from client";
  if ((sd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("client-socket() error");
    exit(-1);
  } else
    printf("client-socket() OK\n");
  if (argc > 1) {
    strcpy(server, argv[1]);
    printf("connecting to the %s, port %d ... \n", server, 3111);
  } else
    strcpy(server, "the_server_name_or_ip");
  memset(&serveraddr, 0x00, sizeof(struct sockaddr_in));
  serveraddr.sin_family = AF_INET;
  serveraddr.sin_port = htons(3111);
  if ((serveraddr.sin_addr.s_addr = inet_addr(server)) ==
      (unsigned long)INADDR_NONE) {
    hostp = gethostbyname(server);
    if (hostp == (struct hostent *)NULL) {
      printf("host not found -->");
      printf("h_errno = %d\n", h_errno);
      printf("CLIENT PROGRAM\n");
      printf("command usage: %s <server name or ip>", argv[0]);
      close(sd);
      exit(-1);
    }
    memcpy(&serveraddr.sin_addr, hostp->h_addr, sizeof(serveraddr.sin_addr));
  }
  if ((rc = connect(sd, (struct sockaddr *)&serveraddr, sizeof(serveraddr))) <
      0) {
    perror("client-connect() error");
    close(sd);
    exit(-1);
  } else
    printf("connection established..\n");
  printf("sending some string to %s...\n", server);
  rc = write(sd, data, sizeof(data));
  if (rc < 0) {
    perror("client-write() error");
    rc = getsockopt(sd, SOL_SOCKET, SO_ERROR, &temp, &length);
    if (rc == 0) {
      errno = temp;
      perror("SO_ERROR wa");
    }
    close(sd);
    exit(-1);
  } else {
    printf("client-write is ok\n");
    printf("string successfully sent...ok\n");
    printf("waiting the %s to echo back...ok\n", server);
  }
  totalcnt = 0;
  while (totalcnt < 257) {
    rc = read(sd, &buffer[totalcnt], 257 - totalcnt);
    if (rc < 0) {
      perror("client-read error");
      close(sd);
      exit(-1);
    } else if (rc == 0) {
      printf("server has issed a close()\n");
      close(sd);
      exit(-1);
    } else
      totalcnt += rc;
  }
  printf("client-read is ok..\n");
  printf("echoed data from server: %s \n", buffer);
  close(sd);
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x4,-0x1c(%rbp)
movl   $0x0,-0x248(%rbp)
lea    -0x2c0(%rbp),%rdi
lea    0xdd8(%rip),%rsi
mov    $0x64,%edx
call   10d0 <memcpy@plt>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    126d <main+0x7d>
lea    0xe06(%rip),%rdi
call   10e0 <perror@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xe06(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
cmpl   $0x1,-0x8(%rbp)
jle    12b8 <main+0xc8>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x240(%rbp),%rsi
lea    0xde7(%rip),%rdi
mov    $0xc27,%edx
mov    $0x0,%al
call   1060 <printf@plt>
jmp    12cb <main+0xdb>
lea    -0x240(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1070 <memset@plt>
mov    0x2cfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0xc27,%edi
call   1050 <htons@plt>
mov    %eax,-0x28(%rbp)
lea    -0x240(%rbp),%rdi
call   10b0 <inet_addr@plt>
mov    %rax,-0x30(%rbp)
mov    0x2ccd(%rip),%rcx
cmp    (%rcx),%rax
jne    13a6 <main+0x1b6>
lea    -0x240(%rbp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x250(%rbp)
cmpq   $0x0,-0x250(%rbp)
jne    138f <main+0x19f>
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%esi
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xd88(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    -0x30(%rbp),%rdi
mov    -0x250(%rbp),%rax
mov    (%rax),%esi
mov    $0x8,%edx
call   10d0 <memcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x10,%edx
call   1100 <connect@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    13e1 <main+0x1f1>
lea    0xd55(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xd4e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x240(%rbp),%rsi
lea    0xd53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
lea    -0x2c0(%rbp),%rsi
mov    $0x64,%edx
call   1040 <write@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1490 <main+0x2a0>
lea    0xd42(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x14(%rbp),%edi
mov    0x2bad(%rip),%rax
mov    (%rax),%esi
mov    0x2b6c(%rip),%rax
mov    (%rax),%edx
lea    -0x241(%rbp),%rcx
lea    -0x1c(%rbp),%r8
call   10a0 <getsockopt@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    147e <main+0x28e>
mov    -0x241(%rbp),%cl
mov    0x2b48(%rip),%rax
mov    %cl,(%rax)
lea    0xd0a(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
lea    0xcf8(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xcfe(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x240(%rbp),%rsi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x248(%rbp)
cmpl   $0x101,-0x248(%rbp)
jge    156d <main+0x37d>
mov    -0x14(%rbp),%edi
movslq -0x248(%rbp),%rax
lea    -0x140(%rbp),%rsi
add    %rax,%rsi
mov    $0x101,%edx
sub    -0x248(%rbp),%edx
call   1090 <read@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    152a <main+0x33a>
lea    0xcd1(%rip),%rdi
call   10e0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1554 <main+0x364>
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>
mov    -0x18(%rbp),%eax
add    -0x248(%rbp),%eax
mov    %eax,-0x248(%rbp)
jmp    1568 <main+0x378>
jmp    14cb <main+0x2db>
lea    0xc9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x140(%rbp),%rsi
lea    0xc9e(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %edi,%edi
call   10f0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x298,%rsp
mov    %rsi,%r14
mov    %edi,%ebp
movl   $0x4,0xc(%rsp)
movaps 0xe2f(%rip),%xmm0
movaps %xmm0,0x70(%rsp)
movaps 0xe13(%rip),%xmm0
movaps %xmm0,0x60(%rsp)
movaps 0xdf7(%rip),%xmm0
movaps %xmm0,0x50(%rsp)
movaps 0xddb(%rip),%xmm0
movaps %xmm0,0x40(%rsp)
movaps 0xdbf(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
movaps 0xda3(%rip),%xmm0
movaps %xmm0,0x20(%rsp)
movl   $0x0,0x80(%rsp)
mov    0x2d6c(%rip),%r15
mov    (%r15),%edi
mov    0x2d42(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
test   %eax,%eax
js     1406 <main+0x206>
mov    %eax,%ebx
lea    0xf0b(%rip),%rdi
call   1040 <puts@plt>
cmp    $0x2,%ebp
jl     12ce <main+0xce>
mov    0x8(%r14),%rsi
lea    0x90(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <strcpy@plt>
lea    0xdbd(%rip),%rdi
mov    %rbp,%rsi
mov    $0xc27,%edx
xor    %eax,%eax
call   1070 <printf@plt>
jmp    12e2 <main+0xe2>
lea    0xdc9(%rip),%rsi
lea    0x90(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1080 <memset@plt>
mov    (%r15),%eax
mov    %eax,0x1c(%rsp)
mov    $0xc27,%edi
call   1060 <htons@plt>
mov    %eax,0x18(%rsp)
lea    0x90(%rsp),%rdi
call   10c0 <inet_addr@plt>
mov    %rax,0x10(%rsp)
mov    0x2cb7(%rip),%rcx
cmp    (%rcx),%rax
jne    134d <main+0x14d>
lea    0x90(%rsp),%rdi
call   10d0 <gethostbyname@plt>
test   %rax,%rax
je     14c4 <main+0x2c4>
mov    (%rax),%esi
lea    0x10(%rsp),%rdi
mov    $0x8,%edx
call   10e0 <memcpy@plt>
lea    0x10(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1110 <connect@plt>
test   %eax,%eax
js     141c <main+0x21c>
lea    0xe49(%rip),%rdi
call   1040 <puts@plt>
lea    0xd99(%rip),%rdi
xor    %ebp,%ebp
lea    0x90(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x64,%edx
call   1050 <write@plt>
test   %eax,%eax
jns    1425 <main+0x225>
lea    0xd86(%rip),%rdi
call   10f0 <perror@plt>
mov    0x2c32(%rip),%rax
mov    (%rax),%esi
mov    0x2bf1(%rip),%rax
mov    (%rax),%edx
lea    0x190(%rsp),%rcx
lea    0xc(%rsp),%r8
mov    %ebx,%edi
call   10b0 <getsockopt@plt>
test   %eax,%eax
jne    13f5 <main+0x1f5>
mov    0x190(%rsp),%al
mov    0x2bd1(%rip),%rcx
mov    %al,(%rcx)
lea    0xd55(%rip),%rdi
call   10f0 <perror@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    0xc57(%rip),%rdi
call   10f0 <perror@plt>
mov    $0xffffffff,%edi
call   1100 <exit@plt>
lea    0xcd8(%rip),%rdi
jmp    13f0 <main+0x1f0>
lea    0xda3(%rip),%rdi
call   1040 <puts@plt>
lea    0xdaa(%rip),%rdi
call   1040 <puts@plt>
lea    0xd0d(%rip),%rdi
lea    0x90(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movslq %ebp,%rax
lea    (%rsp,%rax,1),%rsi
add    $0x190,%rsi
mov    $0x101,%edx
sub    %eax,%edx
mov    %ebx,%edi
call   10a0 <read@plt>
test   %eax,%eax
js     150b <main+0x30b>
je     1517 <main+0x317>
add    %eax,%ebp
cmp    $0x100,%ebp
jle    1460 <main+0x260>
lea    0xd65(%rip),%rdi
call   1040 <puts@plt>
lea    0xcde(%rip),%rdi
lea    0x190(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1100 <exit@plt>
lea    0xbe9(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2af7(%rip),%rax
mov    (%rax),%esi
lea    0xbe5(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xd3f(%rip),%rdi
call   1040 <puts@plt>
mov    (%r14),%rsi
lea    0xbd6(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
jmp    13f5 <main+0x1f5>
lea    0xc61(%rip),%rdi
jmp    13f0 <main+0x1f0>
lea    0xcf6(%rip),%rdi
call   1040 <puts@plt>
jmp    13f5 <main+0x1f5>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.data = [100 x i8] c"Test string from client\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"client-socket() error\00"
@.str.1 = [20 x i8] c"client-socket() OK\0A\00"
@.str.2 = [36 x i8] c"connecting to the %s, port %d ... \0A\00"
@.str.3 = [22 x i8] c"the_server_name_or_ip\00"
@INADDR_NONE = global i64 0
@.str.4 = [19 x i8] c"host not found -->\00"
@.str.5 = [14 x i8] c"h_errno = %d\0A\00"
@h_errno = global i32 0
@.str.6 = [16 x i8] c"CLIENT PROGRAM\0A\00"
@.str.7 = [38 x i8] c"command usage: %s <server name or ip>\00"
@.str.8 = [23 x i8] c"client-connect() error\00"
@.str.9 = [26 x i8] c"connection established..\0A\00"
@.str.10 = [30 x i8] c"sending some string to %s...\0A\00"
@.str.11 = [21 x i8] c"client-write() error\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@errno = global i8 0
@.str.12 = [12 x i8] c"SO_ERROR wa\00"
@.str.13 = [20 x i8] c"client-write is ok\0A\00"
@.str.14 = [31 x i8] c"string successfully sent...ok\0A\00"
@.str.15 = [34 x i8] c"waiting the %s to echo back...ok\0A\00"
@.str.16 = [18 x i8] c"client-read error\00"
@.str.17 = [28 x i8] c"server has issed a close()\0A\00"
@.str.18 = [21 x i8] c"client-read is ok..\0A\00"
@.str.19 = [30 x i8] c"echoed data from server: %s \0A\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 i32
%9 = alloca %struct.sockaddr_in
%10 = alloca [257 x i8]
%11 = alloca [255 x i8]
%12 = alloca i8
%13 = alloca i32
%14 = alloca %struct.hostent*
%15 = alloca [100 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 4, i32* %8
store i32 0, i32* %13
%16 = bitcast [100 x i8]* %15 to i8*
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = call i32 @socket(i32 %17, i32 %18, i32 0)
store i32 %19, i32* %6
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %2
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %26
26: ; preds = %24
%27 = load i32, i32* %4
%28 = icmp sgt i32 %27, 1
br i1 %28, label %29, label %37
29: ; preds = %26
%30 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @strcpy(i8* %30, i8* %33)
%35 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %35, i32 3111)
br label %40
37: ; preds = %26
%38 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%39 = call i32 @strcpy(i8* %38, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %40
40: ; preds = %37, %29
%41 = call i32 @memset(%struct.sockaddr_in* %9, i32 0, i32 16)
%42 = load i32, i32* @AF_INET
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %42, i32* %43
%44 = call i32 @htons(i32 3111)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %44, i32* %45
%46 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%47 = call i64 @inet_addr(i8* %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
store i64 %47, i64* %49
%50 = load i64, i64* @INADDR_NONE
%51 = icmp eq i64 %47, %50
br i1 %51, label %52, label %75
52: ; preds = %40
%53 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%54 = call %struct.hostent* @gethostbyname(i8* %53)
store %struct.hostent* %54, %struct.hostent** %14
%55 = load %struct.hostent*, %struct.hostent** %14
%56 = icmp eq %struct.hostent* %55, null
br i1 %56, label %57, label %69
57: ; preds = %52
%58 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%59 = load i32, i32* @h_errno
%60 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %59)
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0))
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 0
%64 = load i8*, i8** %63
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %64)
%66 = load i32, i32* %6
%67 = call i32 @close(i32 %66)
%68 = call i32 @exit(i32 -1)
unreachable
69: ; preds = %52
%70 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
%71 = load %struct.hostent*, %struct.hostent** %14
%72 = getelementptr inbounds %struct.hostent, %struct.hostent* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @memcpy(%struct.TYPE_2__* %70, i32 %73, i32 8)
br label %75
75: ; preds = %69, %40
%76 = load i32, i32* %6
%77 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%78 = call i32 @connect(i32 %76, %struct.sockaddr* %77, i32 16)
store i32 %78, i32* %7
%79 = icmp slt i32 %78, 0
br i1 %79, label %80, label %85
80: ; preds = %75
%81 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%82 = load i32, i32* %6
%83 = call i32 @close(i32 %82)
%84 = call i32 @exit(i32 -1)
unreachable
85: ; preds = %75
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.9, i64 0, i64 0))
br label %87
87: ; preds = %85
%88 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%89 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i8* %88)
%90 = load i32, i32* %6
%91 = getelementptr inbounds [100 x i8], [100 x i8]* %15, i64 0, i64 0
%92 = call i32 @write(i32 %90, i8* %91, i32 100)
store i32 %92, i32* %7
%93 = load i32, i32* %7
%94 = icmp slt i32 %93, 0
br i1 %94, label %95, label %110
95: ; preds = %87
%96 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
%97 = load i32, i32* %6
%98 = load i32, i32* @SOL_SOCKET
%99 = load i32, i32* @SO_ERROR
%100 = call i32 @getsockopt(i32 %97, i32 %98, i32 %99, i8* %12, i32* %8)
store i32 %100, i32* %7
%101 = load i32, i32* %7
%102 = icmp eq i32 %101, 0
br i1 %102, label %103, label %106
103: ; preds = %95
%104 = load i8, i8* %12
store i8 %104, i8* @errno
%105 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
br label %106
106: ; preds = %103, %95
%107 = load i32, i32* %6
%108 = call i32 @close(i32 %107)
%109 = call i32 @exit(i32 -1)
unreachable
110: ; preds = %87
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.13, i64 0, i64 0))
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.14, i64 0, i64 0))
%113 = getelementptr inbounds [255 x i8], [255 x i8]* %11, i64 0, i64 0
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.15, i64 0, i64 0), i8* %113)
br label %115
115: ; preds = %110
store i32 0, i32* %13
br label %116
116: ; preds = %147, %115
%117 = load i32, i32* %13
%118 = icmp slt i32 %117, 257
br i1 %118, label %119, label %148
119: ; preds = %116
%120 = load i32, i32* %6
%121 = load i32, i32* %13
%122 = sext i32 %121 to i64
%123 = getelementptr inbounds [257 x i8], [257 x i8]* %10, i64 0, i64 %122
%124 = load i32, i32* %13
%125 = sub nsw i32 257, %124
%126 = call i32 @read(i32 %120, i8* %123, i32 %125)
store i32 %126, i32* %7
%127 = load i32, i32* %7
%128 = icmp slt i32 %127, 0
br i1 %128, label %129, label %134
129: ; preds = %119
%130 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
%131 = load i32, i32* %6
%132 = call i32 @close(i32 %131)
%133 = call i32 @exit(i32 -1)
unreachable
134: ; preds = %119
%135 = load i32, i32* %7
%136 = icmp eq i32 %135, 0
br i1 %136, label %137, label %142
137: ; preds = %134
%138 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.17, i64 0, i64 0))
%139 = load i32, i32* %6
%140 = call i32 @close(i32 %139)
%141 = call i32 @exit(i32 -1)
unreachable
142: ; preds = %134
%143 = load i32, i32* %7
%144 = load i32, i32* %13
%145 = add nsw i32 %144, %143
store i32 %145, i32* %13
br label %146
146: ; preds = %142
br label %147
147: ; preds = %146
br label %116
148: ; preds = %116
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.18, i64 0, i64 0))
%150 = getelementptr inbounds [257 x i8], [257 x i8]* %10, i64 0, i64 0
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.19, i64 0, i64 0), i8* %150)
%152 = load i32, i32* %6
%153 = call i32 @close(i32 %152)
%154 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.hostent = type { i32 }
%struct.sockaddr = type { i32 }
@__const.main.data = [100 x i8] c"Test string from client\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [22 x i8] c"client-socket() error\00"
@.str.2 = [36 x i8] c"connecting to the %s, port %d ... \0A\00"
@.str.3 = [22 x i8] c"the_server_name_or_ip\00"
@INADDR_NONE = global i64 0
@.str.4 = [19 x i8] c"host not found -->\00"
@.str.5 = [14 x i8] c"h_errno = %d\0A\00"
@h_errno = global i32 0
@.str.7 = [38 x i8] c"command usage: %s <server name or ip>\00"
@.str.8 = [23 x i8] c"client-connect() error\00"
@.str.10 = [30 x i8] c"sending some string to %s...\0A\00"
@.str.11 = [21 x i8] c"client-write() error\00"
@SOL_SOCKET = global i32 0
@SO_ERROR = global i32 0
@errno = global i8 0
@.str.12 = [12 x i8] c"SO_ERROR wa\00"
@.str.15 = [34 x i8] c"waiting the %s to echo back...ok\0A\00"
@.str.16 = [18 x i8] c"client-read error\00"
@.str.19 = [30 x i8] c"echoed data from server: %s \0A\00"
@str = [19 x i8] c"client-socket() OK\00"
@str.20 = [25 x i8] c"connection established..\00"
@str.21 = [19 x i8] c"client-write is ok\00"
@str.22 = [30 x i8] c"string successfully sent...ok\00"
@str.23 = [20 x i8] c"client-read is ok..\00"
@str.24 = [27 x i8] c"server has issed a close()\00"
@str.25 = [15 x i8] c"CLIENT PROGRAM\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca [257 x i8]
%6 = alloca [255 x i8]
%7 = alloca i8
%8 = alloca [100 x i8]
%9 = bitcast i32* %3 to i8*
store i32 4, i32* %3
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%14 = load i32, i32* @AF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = icmp slt i32 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = tail call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
%20 = tail call i32 @exit(i32 -1)
unreachable
21: ; preds = %2
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%23 = icmp sgt i32 %0, 1
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strcpy(i8* %12, i8* %26)
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %12, i32 3111)
br label %31
29: ; preds = %21
%30 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = call i32 @memset(%struct.sockaddr_in* %4, i32 0, i32 16)
%33 = load i32, i32* @AF_INET
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %33, i32* %34
%35 = call i32 @htons(i32 3111)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %35, i32* %36
%37 = call i64 @inet_addr(i8* %12)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0, i32 0
store i64 %37, i64* %39
%40 = load i64, i64* @INADDR_NONE
%41 = icmp eq i64 %37, %40
br i1 %41, label %42, label %58
42: ; preds = %31
%43 = call %struct.hostent* @gethostbyname(i8* %12)
%44 = icmp eq %struct.hostent* %43, null
br i1 %44, label %45, label %54
45: ; preds = %42
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32, i32* @h_errno
%48 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0), i32 %47)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.25, i64 0, i64 0))
%50 = load i8*, i8** %1
%51 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.7, i64 0, i64 0), i8* %50)
%52 = call i32 @close(i32 %16)
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %42
%55 = getelementptr inbounds %struct.hostent, %struct.hostent* %43, i64 0, i32 0
%56 = load i32, i32* %55
%57 = call i32 @memcpy(%struct.TYPE_2__* %38, i32 %56, i32 8)
br label %58
58: ; preds = %54, %31
%59 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%60 = call i32 @connect(i32 %16, %struct.sockaddr* %59, i32 16)
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %66
62: ; preds = %58
%63 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.8, i64 0, i64 0))
%64 = call i32 @close(i32 %16)
%65 = call i32 @exit(i32 -1)
unreachable
66: ; preds = %58
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.20, i64 0, i64 0))
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.10, i64 0, i64 0), i8* %12)
%69 = call i32 @write(i32 %16, i8* %13, i32 100)
%70 = icmp slt i32 %69, 0
br i1 %70, label %71, label %83
71: ; preds = %66
%72 = call i32 @perror(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.11, i64 0, i64 0))
%73 = load i32, i32* @SOL_SOCKET
%74 = load i32, i32* @SO_ERROR
%75 = call i32 @getsockopt(i32 %16, i32 %73, i32 %74, i8* %7, i32* %3)
%76 = icmp eq i32 %75, 0
br i1 %76, label %77, label %80
77: ; preds = %71
%78 = load i8, i8* %7
store i8 %78, i8* @errno
%79 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i64 0, i64 0))
br label %80
80: ; preds = %77, %71
%81 = call i32 @close(i32 %16)
%82 = call i32 @exit(i32 -1)
unreachable
83: ; preds = %66
%84 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.21, i64 0, i64 0))
%85 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.22, i64 0, i64 0))
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.15, i64 0, i64 0), i8* %12)
br label %89
87: ; preds = %100
%88 = icmp slt i32 %102, 257
br i1 %88, label %89, label %107
89: ; preds = %83, %87
%90 = phi i32 [ 0, %83 ], [ %102, %87 ]
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds [257 x i8], [257 x i8]* %5, i64 0, i64 %91
%93 = sub nsw i32 257, %90
%94 = call i32 @read(i32 %16, i8* %92, i32 %93)
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %89
%97 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.16, i64 0, i64 0))
%98 = call i32 @close(i32 %16)
%99 = call i32 @exit(i32 -1)
unreachable
100: ; preds = %89
%101 = icmp eq i32 %94, 0
%102 = add nsw i32 %94, %90
br i1 %101, label %103, label %87
103: ; preds = %100
%104 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @str.24, i64 0, i64 0))
%105 = call i32 @close(i32 %16)
%106 = call i32 @exit(i32 -1)
unreachable
107: ; preds = %87
%108 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.23, i64 0, i64 0))
%109 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.19, i64 0, i64 0), i8* %11)
%110 = call i32 @close(i32 %16)
%111 = call i32 @exit(i32 0)
unreachable
}