#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__ {
  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*/ serveraddr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bcopy(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ error(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
char *strchr(char *, char);
scalar_t__ strlen(char *);
scalar_t__ strncpy(char *, char *, int);
int write(int, char *, scalar_t__);
int main(int argc, char **argv) {
  int sockfd, portno, n;
  struct sockaddr_in serveraddr;
  struct hostent *server;
  char *hostname;
  char *localhost = "127.0.0.1";
  char buf[128];
  int repeat = 0;
  if (argc != 4 && argc != 3) {
    fprintf(stderr,
            "usage: %s <hostname> <port> <msg>\nor usage: %s <hostname> <port>",
            argv[0], argv[0]);
    exit(0);
  }
  hostname = argv[1];
  portno = atoi(argv[2]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  server = gethostbyname(hostname);
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host as %s\n", hostname);
    exit(0);
  }
  bzero((char *)&serveraddr, sizeof(serveraddr));
  serveraddr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serveraddr.sin_addr.s_addr,
        server->h_length);
  serveraddr.sin_port = htons(portno);
  if (connect(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0)
    error("ERROR connecting");
  printf("Host %s connecting to %s\n", localhost, hostname);
  if (argc == 3) {
    repeat = 1;
    printf(
        "Please enter the character messages to be checked (CTRL-Z to exit): ");
    bzero(buf, 128);
    fgets(buf, 128, stdin);
    char *pos;
    if ((pos = strchr(buf, '\n')) != NULL)
      *pos = '\0';
    if (strlen(buf) == 0) {
      printf("Please enter a nonempty string.\n");
      close(sockfd);
      exit(0);
    }
  } else if (strncpy(buf, argv[3], 128) < 0)
    error("ERROR line 67");
  n = write(sockfd, buf, strlen(buf));
  if (n < 0)
    error("ERROR writing to socket");
  bzero(buf, 128);
  n = read(sockfd, buf, 128);
  if (n < 0)
    error("ERROR reading from socket");
  printf("Echo from server: %s\n", buf);
  close(sockfd);
  if (repeat)
    main(argc, argv);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdb0(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x0,-0xc4(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     129e <main+0x6e>
cmpl   $0x3,-0x8(%rbp)
je     129e <main+0x6e>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
lea    0xd7a(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1120 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
mov    0x2cfe(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12ec <main+0xbc>
lea    0xd64(%rip),%rdi
call   1100 <error@plt>
mov    -0x38(%rbp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1326 <main+0xf6>
mov    0x2cc5(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
lea    0xd48(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
xor    %edi,%edi
call   1130 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x2cad(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x30(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x4,%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%edx
call   10f0 <bcopy@plt>
mov    -0x18(%rbp),%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1140 <connect@plt>
cmp    $0x0,%rax
jge    138d <main+0x15d>
lea    0xcf3(%rip),%rdi
call   1100 <error@plt>
mov    -0x40(%rbp),%rsi
mov    -0x38(%rbp),%rdx
lea    0xcf0(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x3,-0x8(%rbp)
jne    1454 <main+0x224>
movl   $0x1,-0xc4(%rbp)
lea    0xce8(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x80,%esi
call   1110 <bzero@plt>
lea    -0xc0(%rbp),%rdi
mov    0x2bfc(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   10b0 <fgets@plt>
lea    -0xc0(%rbp),%rdi
mov    $0xa,%esi
call   1070 <strchr@plt>
mov    %rax,-0xd0(%rbp)
cmp    $0x0,%rax
je     141c <main+0x1ec>
mov    -0xd0(%rbp),%rax
movb   $0x0,(%rax)
lea    -0xc0(%rbp),%rdi
call   1050 <strlen@plt>
cmp    $0x0,%rax
jne    144f <main+0x21f>
lea    0xcb2(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
xor    %edi,%edi
call   1130 <exit@plt>
jmp    1488 <main+0x258>
lea    -0xc0(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    $0x80,%edx
call   1030 <strncpy@plt>
cmp    $0x0,%rax
jge    1483 <main+0x253>
lea    0xc8e(%rip),%rdi
call   1100 <error@plt>
jmp    1488 <main+0x258>
mov    -0x14(%rbp),%eax
mov    %eax,-0xdc(%rbp)
lea    -0xc0(%rbp),%rax
mov    %rax,-0xd8(%rbp)
lea    -0xc0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0xdc(%rbp),%edi
mov    -0xd8(%rbp),%rsi
mov    %rax,%rdx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14d9 <main+0x2a9>
lea    0xc46(%rip),%rdi
call   1100 <error@plt>
lea    -0xc0(%rbp),%rdi
mov    $0x80,%esi
call   1110 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x80,%edx
call   10a0 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1517 <main+0x2e7>
lea    0xc20(%rip),%rdi
call   1100 <error@plt>
lea    -0xc0(%rbp),%rsi
lea    0xc27(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
cmpl   $0x0,-0xc4(%rbp)
je     154d <main+0x31d>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10e0 <main@plt>
mov    -0x4(%rbp),%eax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xa8,%rsp
mov    %rsi,%rbp
mov    %rdi,0x18(%rsp)
lea    -0x5(%rdi),%eax
cmp    $0xfffffffd,%eax
jbe    1452 <main+0x212>
mov    0x8(%rbp),%r12
mov    0x10(%rbp),%rdi
call   1130 <atoi@plt>
mov    %eax,%ebx
mov    0x2d6d(%rip),%r15
mov    (%r15),%edi
mov    0x2d43(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,%r13d
test   %eax,%eax
jns    12a1 <main+0x61>
lea    0xdaf(%rip),%rdi
call   1110 <error@plt>
mov    %rbp,0x10(%rsp)
mov    %r12,%rdi
call   10d0 <gethostbyname@plt>
test   %rax,%rax
je     1477 <main+0x237>
mov    %rax,%rbp
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0xc,%esi
call   1120 <bzero@plt>
mov    (%r15),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbp),%rsi
lea    0x4(%rsp),%rdi
mov    0x0(%rbp),%edx
call   1100 <memmove@plt>
mov    %ebx,%edi
call   1070 <htons@plt>
mov    %eax,(%rsp)
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
test   %rax,%rax
jns    130d <main+0xcd>
lea    0xd73(%rip),%rdi
call   1110 <error@plt>
lea    0xd78(%rip),%rdi
lea    0xce5(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x18(%rsp),%r15
cmp    $0x3,%r15d
mov    0x10(%rsp),%r14
jne    138f <main+0x14f>
lea    0xd6a(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1120 <bzero@plt>
mov    0x2c84(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1080 <strchr@plt>
test   %rax,%rax
je     1380 <main+0x140>
movb   $0x0,(%rax)
cmpb   $0x0,0x20(%rsp)
je     1498 <main+0x258>
xor    %ebp,%ebp
jmp    13b6 <main+0x176>
mov    0x18(%r14),%rsi
lea    0x20(%rsp),%rdi
mov    $0x80,%edx
call   1030 <strncpy@plt>
mov    $0x1,%bpl
test   %rax,%rax
jns    13b6 <main+0x176>
lea    0xd3a(%rip),%rdi
call   1110 <error@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
call   1050 <write@plt>
test   %eax,%eax
jns    13e1 <main+0x1a1>
lea    0xd1d(%rip),%rdi
call   1110 <error@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1120 <bzero@plt>
mov    %r13d,%edi
mov    %rbx,%rsi
mov    $0x80,%edx
call   10b0 <read@plt>
test   %eax,%eax
jns    1413 <main+0x1d3>
lea    0xd03(%rip),%rdi
call   1110 <error@plt>
lea    0xd11(%rip),%rdi
lea    0x20(%rsp),%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
test   %bpl,%bpl
jne    143e <main+0x1fe>
mov    %r15d,%edi
mov    %r14,%rsi
call   10f0 <main@plt>
xor    %eax,%eax
add    $0xa8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b77(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rcx
lea    0xba4(%rip),%rsi
mov    %rcx,%rdx
xor    %eax,%eax
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
mov    0x2b52(%rip),%rax
mov    (%rax),%edi
lea    0xbd9(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1140 <exit@plt>
lea    0xca2(%rip),%rdi
call   1040 <puts@plt>
mov    %r13d,%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   1140 <exit@plt>

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 }
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [65 x i8] c"usage: %s <hostname> <port> <msg>\0Aor usage: %s <hostname> <port>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [27 x i8] c"ERROR, no such host as %s\0A\00"
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [26 x i8] c"Host %s connecting to %s\0A\00"
@.str.6 = [69 x i8] c"Please enter the character messages to be checked (CTRL-Z to exit): \00"
@stdin = global i32 0
@.str.7 = [33 x i8] c"Please enter a nonempty string.\0A\00"
@.str.8 = [14 x i8] c"ERROR line 67\00"
@.str.9 = [24 x i8] c"ERROR writing to socket\00"
@.str.10 = [26 x i8] c"ERROR reading from socket\00"
@.str.11 = [22 x i8] c"Echo 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 %struct.hostent*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca [128 x i8]
%14 = alloca i32
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8** %12
store i32 0, i32* %14
%16 = load i32, i32* %4
%17 = icmp ne i32 %16, 4
br i1 %17, label %18, label %31
18: ; preds = %2
%19 = load i32, i32* %4
%20 = icmp ne i32 %19, 3
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i32, i32* @stderr
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 0
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 0
%28 = load i8*, i8** %27
%29 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %28)
%30 = call i32 @exit(i32 0)
unreachable
31: ; preds = %18, %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
store i8* %34, i8** %11
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 2
%37 = load i8*, i8** %36
%38 = call i32 @atoi(i8* %37)
store i32 %38, i32* %7
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %6
%42 = load i32, i32* %6
%43 = icmp slt i32 %42, 0
br i1 %43, label %44, label %46
44: ; preds = %31
%45 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %46
46: ; preds = %44, %31
%47 = load i8*, i8** %11
%48 = call %struct.hostent* @gethostbyname(i8* %47)
store %struct.hostent* %48, %struct.hostent** %10
%49 = load %struct.hostent*, %struct.hostent** %10
%50 = icmp eq %struct.hostent* %49, null
br i1 %50, label %51, label %56
51: ; preds = %46
%52 = load i32, i32* @stderr
%53 = load i8*, i8** %11
%54 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %53)
%55 = call i32 @exit(i32 0)
unreachable
56: ; preds = %46
%57 = bitcast %struct.sockaddr_in* %9 to i8*
%58 = call i32 @bzero(i8* %57, i32 12)
%59 = load i32, i32* @AF_INET
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %59, i32* %60
%61 = load %struct.hostent*, %struct.hostent** %10
%62 = getelementptr inbounds %struct.hostent, %struct.hostent* %61, i32 0, i32 1
%63 = load i64, i64* %62
%64 = inttoptr i64 %63 to i8*
%65 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%66 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %65, i32 0, i32 0
%67 = bitcast i32* %66 to i8*
%68 = load %struct.hostent*, %struct.hostent** %10
%69 = getelementptr inbounds %struct.hostent, %struct.hostent* %68, i32 0, i32 0
%70 = load i32, i32* %69
%71 = call i32 @bcopy(i8* %64, i8* %67, i32 %70)
%72 = load i32, i32* %7
%73 = call i32 @htons(i32 %72)
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %73, i32* %74
%75 = load i32, i32* %6
%76 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%77 = call i64 @connect(i32 %75, %struct.sockaddr* %76, i32 12)
%78 = icmp slt i64 %77, 0
br i1 %78, label %79, label %81
79: ; preds = %56
%80 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %81
81: ; preds = %79, %56
%82 = load i8*, i8** %12
%83 = load i8*, i8** %11
%84 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* %82, i8* %83)
%85 = load i32, i32* %4
%86 = icmp eq i32 %85, 3
br i1 %86, label %87, label %109
87: ; preds = %81
store i32 1, i32* %14
%88 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0))
%89 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%90 = call i32 @bzero(i8* %89, i32 128)
%91 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%92 = load i32, i32* @stdin
%93 = call i32 @fgets(i8* %91, i32 128, i32 %92)
%94 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%95 = call i8* @strchr(i8* %94, i8 signext 10)
store i8* %95, i8** %15
%96 = icmp ne i8* %95, null
br i1 %96, label %97, label %99
97: ; preds = %87
%98 = load i8*, i8** %15
store i8 0, i8* %98
br label %99
99: ; preds = %97, %87
%100 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%101 = call i64 @strlen(i8* %100)
%102 = icmp eq i64 %101, 0
br i1 %102, label %103, label %108
103: ; preds = %99
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%105 = load i32, i32* %6
%106 = call i32 @close(i32 %105)
%107 = call i32 @exit(i32 0)
unreachable
108: ; preds = %99
br label %119
109: ; preds = %81
%110 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%111 = load i8**, i8*** %5
%112 = getelementptr inbounds i8*, i8** %111, i64 3
%113 = load i8*, i8** %112
%114 = call i64 @strncpy(i8* %110, i8* %113, i32 128)
%115 = icmp slt i64 %114, 0
br i1 %115, label %116, label %118
116: ; preds = %109
%117 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %118
118: ; preds = %116, %109
br label %119
119: ; preds = %118, %108
%120 = load i32, i32* %6
%121 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%122 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%123 = call i64 @strlen(i8* %122)
%124 = call i32 @write(i32 %120, i8* %121, i64 %123)
store i32 %124, i32* %8
%125 = load i32, i32* %8
%126 = icmp slt i32 %125, 0
br i1 %126, label %127, label %129
127: ; preds = %119
%128 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %129
129: ; preds = %127, %119
%130 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%131 = call i32 @bzero(i8* %130, i32 128)
%132 = load i32, i32* %6
%133 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%134 = call i32 @read(i32 %132, i8* %133, i32 128)
store i32 %134, i32* %8
%135 = load i32, i32* %8
%136 = icmp slt i32 %135, 0
br i1 %136, label %137, label %139
137: ; preds = %129
%138 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %139
139: ; preds = %137, %129
%140 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %140)
%142 = load i32, i32* %6
%143 = call i32 @close(i32 %142)
%144 = load i32, i32* %14
%145 = icmp ne i32 %144, 0
br i1 %145, label %146, label %150
146: ; preds = %139
%147 = load i32, i32* %4
%148 = load i8**, i8*** %5
%149 = call i32 @main(i32 %147, i8** %148)
br label %150
150: ; preds = %146, %139
%151 = load i32, i32* %3
ret i32 %151
}

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 }
@.str = [10 x i8] c"127.0.0.1\00"
@stderr = global i32 0
@.str.1 = [65 x i8] c"usage: %s <hostname> <port> <msg>\0Aor usage: %s <hostname> <port>\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [21 x i8] c"ERROR opening socket\00"
@.str.3 = [27 x i8] c"ERROR, no such host as %s\0A\00"
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [26 x i8] c"Host %s connecting to %s\0A\00"
@.str.6 = [69 x i8] c"Please enter the character messages to be checked (CTRL-Z to exit): \00"
@stdin = global i32 0
@.str.8 = [14 x i8] c"ERROR line 67\00"
@.str.9 = [24 x i8] c"ERROR writing to socket\00"
@.str.10 = [26 x i8] c"ERROR reading from socket\00"
@.str.11 = [22 x i8] c"Echo from server: %s\0A\00"
@str = [32 x i8] c"Please enter a nonempty string.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [128 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = add i32 %0, -5
%8 = icmp ult i32 %7, -2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.1, i64 0, i64 0), i8* %11, i8* %11)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = getelementptr inbounds i8*, i8** %1, i64 1
%16 = load i8*, i8** %15
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = tail call i32 @atoi(i8* %18)
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = tail call i32 @socket(i32 %20, i32 %21, i32 0)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %14
%25 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %14
%27 = tail call %struct.hostent* @gethostbyname(i8* %16)
%28 = icmp eq %struct.hostent* %27, null
br i1 %28, label %29, label %33
29: ; preds = %26
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%32 = tail call i32 @exit(i32 0)
unreachable
33: ; preds = %26
%34 = call i32 @bzero(i8* %5, i32 12)
%35 = load i32, i32* @AF_INET
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %35, i32* %36
%37 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i64 0, i32 1
%38 = load i64, i64* %37
%39 = inttoptr i64 %38 to i8*
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%41 = bitcast i32* %40 to i8*
%42 = getelementptr inbounds %struct.hostent, %struct.hostent* %27, i64 0, i32 0
%43 = load i32, i32* %42
%44 = tail call i32 @htons(i32 %19)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %44, i32* %45
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%47 = call i64 @connect(i32 %22, %struct.sockaddr* %46, i32 12)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %51
49: ; preds = %33
%50 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %51
51: ; preds = %49, %33
%52 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %16)
%53 = icmp eq i32 %0, 3
br i1 %53, label %54, label %69
54: ; preds = %51
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([69 x i8], [69 x i8]* @.str.6, i64 0, i64 0))
%56 = call i32 @bzero(i8* %6, i32 128)
%57 = load i32, i32* @stdin
%58 = call i32 @fgets(i8* %6, i32 128, i32 %57)
%59 = call i8* @strchr(i8* %6, i8 signext 10)
%60 = icmp eq i8* %59, null
br i1 %60, label %62, label %61
61: ; preds = %54
store i8 0, i8* %59
br label %62
62: ; preds = %61, %54
%63 = load i8, i8* %6
%64 = icmp eq i8 %63, 0
br i1 %64, label %65, label %76
65: ; preds = %62
%66 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str, i64 0, i64 0))
%67 = call i32 @close(i32 %22)
%68 = call i32 @exit(i32 0)
unreachable
69: ; preds = %51
%70 = getelementptr inbounds i8*, i8** %1, i64 3
%71 = load i8*, i8** %70
%72 = call i64 @strncpy(i8* %6, i8* %71, i32 128)
%73 = icmp slt i64 %72, 0
br i1 %73, label %74, label %76
74: ; preds = %69
%75 = call i32 @error(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0))
br label %76
76: ; preds = %62, %69, %74
%77 = phi i1 [ true, %69 ], [ true, %74 ], [ false, %62 ]
%78 = call i64 @strlen(i8* %6)
%79 = call i32 @write(i32 %22, i8* %6, i64 %78)
%80 = icmp slt i32 %79, 0
br i1 %80, label %81, label %83
81: ; preds = %76
%82 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %83
83: ; preds = %81, %76
%84 = call i32 @bzero(i8* %6, i32 128)
%85 = call i32 @read(i32 %22, i8* %6, i32 128)
%86 = icmp slt i32 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %83
%88 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %89
89: ; preds = %87, %83
%90 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.11, i64 0, i64 0), i8* %6)
%91 = call i32 @close(i32 %22)
br i1 %77, label %94, label %92
92: ; preds = %89
%93 = call i32 @main(i32 %0, i8** %1)
br label %94
94: ; preds = %92, %89
ret i32 0
}