#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 in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ serv_addr;
typedef int /*<<< orphan*/ line_buff;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_FAILURE;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
int connect(int, struct sockaddr *, int);
int /*<<< orphan*/ exit(int);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, struct in_addr *, int);
int /*<<< orphan*/ perror(char *);
int read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int strlen(char *);
scalar_t__ strncmp(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int sockfd;
  struct hostent *hptr;
  struct sockaddr_in serv_addr;
  struct in_addr *paddr;
  char line_buff[2048];
  int nread;
  FILE *networkR, *networkW;
  if (argc < 3) {
    fprintf(stderr, "Usage: %s host port\n", argv[0]);
    exit(1);
  }
  fprintf(stderr, "Making connection to server %s port %d\n", argv[1],
          atoi(argv[2]));
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    perror("socket");
    return (EXIT_FAILURE);
  }
  hptr = gethostbyname(argv[1]);
  paddr = (struct in_addr *)hptr->h_addr;
  bzero(&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(atoi(argv[2]));
  memcpy(&serv_addr.sin_addr, paddr, sizeof(struct in_addr));
  fprintf(stderr, "Trying %s port %d\n", inet_ntoa(serv_addr.sin_addr),
          atoi(argv[2]));
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1) {
    perror("connect");
    return (EXIT_FAILURE);
  }
  fprintf(stderr, "Connected. Sending object:\n");
  while (fgets(line_buff, sizeof(line_buff), stdin)) {
    if (strncmp(line_buff, "%", 1) == 0)
      break;
    write(sockfd, line_buff, strlen(line_buff));
  }
  fprintf(stderr, "waiting for ack, Ctrl-C to exit\n");
  while ((nread = read(sockfd, line_buff, sizeof(line_buff))) > 0)
    write(2, line_buff, nread);
  fprintf(stderr, "read %d bytes\n", nread);
  if (nread == -1)
    perror("read socket");
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x890,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    124b <main+0x4b>
mov    0x2da6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xdc6(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2d7e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x864(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x860(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    -0x864(%rbp),%edi
mov    -0x860(%rbp),%rdx
mov    %eax,%ecx
lea    0xd89(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d4e(%rip),%rax
mov    (%rax),%edi
mov    0x2d25(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    12d5 <main+0xd5>
lea    0xdec(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2cf5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14e4 <main+0x2e4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,-0x2c(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    $0x4,%edx
call   10c0 <memcpy@plt>
mov    0x2c95(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x874(%rbp)
mov    -0x30(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,-0x870(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10f0 <atoi@plt>
mov    -0x874(%rbp),%edi
mov    -0x870(%rbp),%rdx
mov    %eax,%ecx
lea    0xcc8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
jne    13b3 <main+0x1b3>
lea    0xcb3(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2c17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    14e4 <main+0x2e4>
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    0xc95(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x840(%rbp),%rdi
mov    0x2c08(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1090 <fgets@plt>
cmp    $0x0,%rax
je     1451 <main+0x251>
lea    -0x840(%rbp),%rdi
lea    0xc78(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1415 <main+0x215>
jmp    1451 <main+0x251>
mov    -0x14(%rbp),%eax
mov    %eax,-0x884(%rbp)
lea    -0x840(%rbp),%rax
mov    %rax,-0x880(%rbp)
lea    -0x840(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x884(%rbp),%edi
mov    -0x880(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
jmp    13ca <main+0x1ca>
mov    0x2b78(%rip),%rax
mov    (%rax),%edi
lea    0xc15(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x14(%rbp),%edi
lea    -0x840(%rbp),%rsi
mov    $0x800,%edx
call   1080 <read@plt>
mov    %eax,-0x844(%rbp)
cmp    $0x0,%eax
jle    14a7 <main+0x2a7>
lea    -0x840(%rbp),%rsi
mov    -0x844(%rbp),%edx
mov    $0x2,%edi
call   1040 <write@plt>
jmp    1468 <main+0x268>
mov    0x2b22(%rip),%rax
mov    (%rax),%edi
mov    -0x844(%rbp),%edx
lea    0xbda(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
cmpl   $0xffffffff,-0x844(%rbp)
jne    14dd <main+0x2dd>
lea    0xbce(%rip),%rdi
call   10d0 <perror@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x890,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r14
mov    0x2db5(%rip),%r13
mov    0x0(%r13),%ebx
cmp    $0x2,%edi
jle    1432 <main+0x232>
mov    0x8(%r14),%rbp
mov    0x10(%r14),%rdi
call   10f0 <atoi@plt>
lea    0xdd9(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2d97(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d6d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
cmp    $0xffffffff,%eax
je     1403 <main+0x203>
mov    %eax,%r15d
mov    0x8(%r14),%rdi
call   10a0 <gethostbyname@plt>
mov    (%rax),%rbx
mov    %rsp,%r12
mov    %r12,%rdi
mov    $0xc,%esi
call   10e0 <bzero@plt>
mov    0x0(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    0x10(%r14),%rdi
call   10f0 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x4(%rsp)
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x4,%edx
call   10c0 <memcpy@plt>
mov    0x0(%r13),%ebx
mov    (%rsp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rbp
mov    0x10(%r14),%rdi
call   10f0 <atoi@plt>
lea    0xd67(%rip),%rsi
mov    %ebx,%edi
mov    %rbp,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    %r15d,%edi
mov    %r12,%rsi
mov    $0xc,%edx
call   1110 <connect@plt>
cmp    $0xffffffff,%eax
je     140c <main+0x20c>
mov    0x0(%r13),%edi
lea    0xd50(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x2cca(%rip),%rbx
mov    (%rbx),%edx
lea    0x10(%rsp),%rdi
mov    $0x800,%esi
call   1090 <fgets@plt>
test   %rax,%rax
je     137e <main+0x17e>
lea    0xd41(%rip),%r14
lea    0x10(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
je     137e <main+0x17e>
mov    %rbp,%rdi
call   1060 <strlen@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    (%rbx),%edx
mov    %rbp,%rdi
mov    $0x800,%esi
call   1090 <fgets@plt>
test   %rax,%rax
jne    1340 <main+0x140>
mov    0x0(%r13),%edi
lea    0xced(%rip),%rsi
xor    %r14d,%r14d
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0x800,%edx
call   1080 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    13d5 <main+0x1d5>
lea    0x10(%rsp),%rbx
mov    $0x2,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
call   1040 <write@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1080 <read@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     13b0 <main+0x1b0>
mov    0x0(%r13),%edi
lea    0xcb7(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   10b0 <fprintf@plt>
cmp    $0xffffffff,%ebp
je     1424 <main+0x224>
mov    %r14d,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xca1(%rip),%rdi
jmp    1413 <main+0x213>
lea    0xc3d(%rip),%rdi
call   10d0 <perror@plt>
mov    0x2ba1(%rip),%rax
mov    (%rax),%r14d
jmp    13ee <main+0x1ee>
lea    0xc7b(%rip),%rdi
call   10d0 <perror@plt>
jmp    13ee <main+0x1ee>
mov    (%r14),%rdx
lea    0xbc4(%rip),%rsi
mov    %ebx,%edi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s host port\0A\00"
@.str.1 = [40 x i8] c"Making connection to server %s port %d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"Trying %s port %d\0A\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [28 x i8] c"Connected. Sending object:\0A\00"
@stdin = global i32 0
@.str.6 = [2 x i8] c"%\00"
@.str.7 = [33 x i8] c"waiting for ack, Ctrl-C to exit\0A\00"
@.str.8 = [15 x i8] c"read %d bytes\0A\00"
@.str.9 = [12 x i8] c"read socket\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.sockaddr_in
%9 = alloca %struct.in_addr*
%10 = alloca [2048 x i8]
%11 = alloca i32
%12 = alloca i32*
%13 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* %4
%15 = icmp slt i32 %14, 3
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 2
%30 = load i8*, i8** %29
%31 = call i32 @atoi(i8* %30)
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %27, i32 %31)
%33 = load i32, i32* @AF_INET
%34 = load i32, i32* @SOCK_STREAM
%35 = call i32 @socket(i32 %33, i32 %34, i32 0)
store i32 %35, i32* %6
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %23
%38 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @EXIT_FAILURE
store i32 %39, i32* %3
br label %117
40: ; preds = %23
%41 = load i8**, i8*** %5
%42 = getelementptr inbounds i8*, i8** %41, i64 1
%43 = load i8*, i8** %42
%44 = call %struct.hostent* @gethostbyname(i8* %43)
store %struct.hostent* %44, %struct.hostent** %7
%45 = load %struct.hostent*, %struct.hostent** %7
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %45, i32 0, i32 0
%47 = load i64, i64* %46
%48 = inttoptr i64 %47 to %struct.in_addr*
store %struct.in_addr* %48, %struct.in_addr** %9
%49 = call i32 @bzero(%struct.sockaddr_in* %8, i32 12)
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 2
%54 = load i8*, i8** %53
%55 = call i32 @atoi(i8* %54)
%56 = call i32 @htons(i32 %55)
%57 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %56, i32* %57
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%59 = load %struct.in_addr*, %struct.in_addr** %9
%60 = call i32 @memcpy(i32* %58, %struct.in_addr* %59, i32 4)
%61 = load i32, i32* @stderr
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%63 = load i32, i32* %62
%64 = call i8* @inet_ntoa(i32 %63)
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 2
%67 = load i8*, i8** %66
%68 = call i32 @atoi(i8* %67)
%69 = call i32 (i32, i8*, ...) @fprintf(i32 %61, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %64, i32 %68)
%70 = load i32, i32* %6
%71 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%72 = call i32 @connect(i32 %70, %struct.sockaddr* %71, i32 12)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %77
74: ; preds = %40
%75 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%76 = load i32, i32* @EXIT_FAILURE
store i32 %76, i32* %3
br label %117
77: ; preds = %40
%78 = load i32, i32* @stderr
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %78, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
br label %80
80: ; preds = %90, %77
%81 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%82 = load i32, i32* @stdin
%83 = call i64 @fgets(i8* %81, i32 2048, i32 %82)
%84 = icmp ne i64 %83, 0
br i1 %84, label %85, label %96
85: ; preds = %80
%86 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%87 = call i64 @strncmp(i8* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %90
89: ; preds = %85
br label %96
90: ; preds = %85
%91 = load i32, i32* %6
%92 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%93 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%94 = call i32 @strlen(i8* %93)
%95 = call i32 @write(i32 %91, i8* %92, i32 %94)
br label %80
96: ; preds = %89, %80
%97 = load i32, i32* @stderr
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %97, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
br label %99
99: ; preds = %104, %96
%100 = load i32, i32* %6
%101 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%102 = call i32 @read(i32 %100, i8* %101, i32 2048)
store i32 %102, i32* %11
%103 = icmp sgt i32 %102, 0
br i1 %103, label %104, label %108
104: ; preds = %99
%105 = getelementptr inbounds [2048 x i8], [2048 x i8]* %10, i64 0, i64 0
%106 = load i32, i32* %11
%107 = call i32 @write(i32 2, i8* %105, i32 %106)
br label %99
108: ; preds = %99
%109 = load i32, i32* @stderr
%110 = load i32, i32* %11
%111 = call i32 (i32, i8*, ...) @fprintf(i32 %109, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %110)
%112 = load i32, i32* %11
%113 = icmp eq i32 %112, -1
br i1 %113, label %114, label %116
114: ; preds = %108
%115 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %116
116: ; preds = %114, %108
store i32 0, i32* %3
br label %117
117: ; preds = %116, %74, %37
%118 = load i32, i32* %3
ret i32 %118
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [21 x i8] c"Usage: %s host port\0A\00"
@.str.1 = [40 x i8] c"Making connection to server %s port %d\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.2 = [7 x i8] c"socket\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [19 x i8] c"Trying %s port %d\0A\00"
@.str.4 = [8 x i8] c"connect\00"
@.str.5 = [28 x i8] c"Connected. Sending object:\0A\00"
@stdin = global i32 0
@.str.6 = [2 x i8] c"%\00"
@.str.7 = [33 x i8] c"waiting for ack, Ctrl-C to exit\0A\00"
@.str.8 = [15 x i8] c"read %d bytes\0A\00"
@.str.9 = [12 x i8] c"read socket\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [2048 x i8]
%5 = bitcast %struct.sockaddr_in* %3 to i8*
%6 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%7 = icmp slt i32 %0, 3
%8 = load i32, i32* @stderr
br i1 %7, label %9, label %13
9: ; preds = %2
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 2
%17 = load i8*, i8** %16
%18 = tail call i32 @atoi(i8* %17)
%19 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.1, i64 0, i64 0), i8* %15, i32 %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 eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %13
%25 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
br label %86
27: ; preds = %13
%28 = load i8*, i8** %14
%29 = tail call %struct.hostent* @gethostbyname(i8* %28)
%30 = getelementptr inbounds %struct.hostent, %struct.hostent* %29, i64 0, i32 0
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to %struct.in_addr*
%33 = call i32 @bzero(%struct.sockaddr_in* %3, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %34, i32* %35
%36 = load i8*, i8** %16
%37 = tail call i32 @atoi(i8* %36)
%38 = tail call i32 @htons(i32 %37)
%39 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %38, i32* %39
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%41 = call i32 @memcpy(i32* %40, %struct.in_addr* %32, i32 4)
%42 = load i32, i32* @stderr
%43 = load i32, i32* %40
%44 = call i8* @inet_ntoa(i32 %43)
%45 = load i8*, i8** %16
%46 = call i32 @atoi(i8* %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %44, i32 %46)
%48 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%49 = call i32 @connect(i32 %22, %struct.sockaddr* %48, i32 12)
%50 = icmp eq i32 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %27
%52 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%53 = load i32, i32* @EXIT_FAILURE
br label %86
54: ; preds = %27
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* @stdin
%58 = call i64 @fgets(i8* %6, i32 2048, i32 %57)
%59 = icmp eq i64 %58, 0
br i1 %59, label %69, label %60
60: ; preds = %54, %63
%61 = call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0), i32 1)
%62 = icmp eq i64 %61, 0
br i1 %62, label %69, label %63
63: ; preds = %60
%64 = call i32 @strlen(i8* %6)
%65 = call i32 @write(i32 %22, i8* %6, i32 %64)
%66 = load i32, i32* @stdin
%67 = call i64 @fgets(i8* %6, i32 2048, i32 %66)
%68 = icmp eq i64 %67, 0
br i1 %68, label %69, label %60
69: ; preds = %63, %60, %54
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0))
%72 = call i32 @read(i32 %22, i8* %6, i32 2048)
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %79
74: ; preds = %69, %74
%75 = phi i32 [ %77, %74 ], [ %72, %69 ]
%76 = call i32 @write(i32 2, i8* %6, i32 %75)
%77 = call i32 @read(i32 %22, i8* %6, i32 2048)
%78 = icmp sgt i32 %77, 0
br i1 %78, label %74, label %79
79: ; preds = %74, %69
%80 = phi i32 [ %72, %69 ], [ %77, %74 ]
%81 = load i32, i32* @stderr
%82 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.8, i64 0, i64 0), i32 %80)
%83 = icmp eq i32 %80, -1
br i1 %83, label %84, label %86
84: ; preds = %79
%85 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i64 0, i64 0))
br label %86
86: ; preds = %79, %84, %51, %24
%87 = phi i32 [ %26, %24 ], [ %53, %51 ], [ 0, %84 ], [ 0, %79 ]
ret i32 %87
}