#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_port;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ PF_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*/ exit(int);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ herror(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int strlen(char *);
scalar_t__ write(int, char *, int);
main(int argc, char *argv[]) {
  int port, sock, serverlen;
  char buf[256 * 8];
  struct sockaddr_in server;
  struct sockaddr *serverptr;
  struct hostent *rem;
  if (argc < 3) {
    printf("Please give host name and port number\n");
    exit(1);
  }
  if ((sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
    perror("socket");
    exit(1);
  }
  if ((rem = gethostbyname(argv[1])) == NULL) {
    herror("gethostbyname");
    exit(1);
  }
  port = atoi(argv[2]);
  server.sin_family = PF_INET;
  bcopy((char *)rem->h_addr, (char *)&server.sin_addr, rem->h_length);
  server.sin_port = htons(port);
  serverptr = (struct sockaddr *)&server;
  serverlen = sizeof(server);
  FILE *fp;
  if ((fp = fopen(argv[3], "r")) == NULL) {
    printf("File not found!");
    return 1;
  }
  if (connect(sock, serverptr, serverlen) < 0) {
    perror("connect");
    exit(1);
  }
  printf("Requested connection to host %s port %d\n", argv[1], port);
  bzero(buf, sizeof buf);
  while (!feof(fp))
    fgets(&buf[strlen(buf)], sizeof buf, fp);
  buf[strlen(buf)] = '\r';
  buf[strlen(buf) + 1] = '\n';
  buf[strlen(buf) + 2] = '\0';
  printf("Sending:\n%s\n", buf);
  if (write(sock, buf, sizeof buf) < 0) {
    perror("write");
    exit(1);
  }
  bzero(buf, sizeof buf);
  sleep(2);
  if (read(sock, buf, sizeof buf) < 0) {
    perror("read");
    exit(1);
  }
  close(sock);
  printf("Got:\n%s", buf);
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    126b <main+0x3b>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    0x2d65(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    12a6 <main+0x76>
lea    0xd90(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x840(%rbp)
cmp    $0x0,%rax
jne    12da <main+0xaa>
lea    0xd63(%rip),%rdi
call   10c0 <herror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x14(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x828(%rbp)
mov    -0x840(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x830(%rbp),%rsi
add    $0x4,%rsi
mov    -0x840(%rbp),%rax
mov    (%rax),%edx
call   10d0 <bcopy@plt>
mov    -0x14(%rbp),%edi
call   1050 <htons@plt>
mov    %eax,-0x830(%rbp)
lea    -0x830(%rbp),%rax
mov    %rax,-0x838(%rbp)
movl   $0xc,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xced(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x848(%rbp)
cmp    $0x0,%rax
jne    1381 <main+0x151>
lea    0xcd2(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%eax
add    $0x850,%rsp
pop    %rbp
ret
mov    -0x18(%rbp),%edi
mov    -0x838(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
jge    13b3 <main+0x183>
lea    0xcaa(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x14(%rbp),%edx
lea    0xc91(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x820(%rbp),%rdi
mov    $0x800,%esi
call   1100 <bzero@plt>
mov    -0x848(%rbp),%rdi
call   10b0 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    13fe <main+0x1ce>
jmp    142c <main+0x1fc>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
cltq
lea    -0x820(%rbp),%rdi
add    %rax,%rdi
mov    -0x848(%rbp),%rdx
mov    $0x800,%esi
call   1090 <fgets@plt>
jmp    13dd <main+0x1ad>
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
cltq
movb   $0xd,-0x820(%rbp,%rax,1)
0d
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
cltq
movb   $0xa,-0x820(%rbp,%rax,1)
0a
lea    -0x820(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x2,%eax
cltq
movb   $0x0,-0x820(%rbp,%rax,1)
lea    -0x820(%rbp),%rsi
lea    0xbfd(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1030 <write@plt>
cmp    $0x0,%rax
jge    14bd <main+0x28d>
lea    0xbde(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x820(%rbp),%rdi
mov    $0x800,%esi
call   1100 <bzero@plt>
mov    $0x2,%edi
call   1140 <sleep@plt>
mov    -0x18(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x800,%edx
call   1080 <read@plt>
cmp    $0x0,%rax
jge    150c <main+0x2dc>
lea    0xb95(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
lea    -0x820(%rbp),%rsi
lea    0xb75(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   1120 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x810,%rsp
cmp    $0x2,%edi
jle    12fe <main+0xbe>
mov    %rsi,%rbx
mov    0x2d76(%rip),%r12
mov    (%r12),%edi
mov    0x2d73(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
test   %eax,%eax
js     1314 <main+0xd4>
mov    %eax,%r14d
mov    0x8(%rbx),%rdi
call   10b0 <gethostbyname@plt>
test   %rax,%rax
je     1320 <main+0xe0>
mov    %rax,%rbp
mov    0x10(%rbx),%rdi
call   1120 <atoi@plt>
mov    %eax,%r15d
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    0x8(%rbp),%rsi
lea    0x4(%rsp),%rdi
mov    0x0(%rbp),%edx
call   10e0 <memmove@plt>
mov    %r15d,%edi
call   1060 <htons@plt>
mov    %eax,(%rsp)
mov    0x18(%rbx),%rdi
lea    0xdc9(%rip),%rsi
call   10f0 <fopen@plt>
test   %rax,%rax
jne    1336 <main+0xf6>
lea    0xd33(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    $0x1,%eax
add    $0x810,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd71(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
lea    0xce5(%rip),%rdi
jmp    1461 <main+0x221>
lea    0xce0(%rip),%rdi
call   10d0 <herror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    %rax,%rbp
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   1140 <connect@plt>
test   %rax,%rax
jns    135a <main+0x11a>
lea    0xcd0(%rip),%rdi
jmp    1461 <main+0x221>
mov    0x8(%rbx),%rsi
lea    0xcc8(%rip),%rdi
mov    %r15d,%edx
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x10(%rsp),%r15
mov    %r15,%rdi
mov    $0x800,%esi
call   1110 <bzero@plt>
mov    %rbp,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
jne    13cb <main+0x18b>
lea    0x10(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1050 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x10,%rdi
mov    $0x800,%esi
mov    %rbp,%rdx
call   10a0 <fgets@plt>
mov    %rbp,%rdi
call   10c0 <feof@plt>
test   %eax,%eax
je     13a0 <main+0x160>
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0xd,0x10(%rsp,%rax,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0xa,0x1(%rax,%r15,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
cltq
movb   $0x0,0x2(%rax,%r15,1)
lea    0xc55(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x800,%edx
call   1040 <write@plt>
test   %rax,%rax
jns    1429 <main+0x1e9>
lea    0xc3c(%rip),%rdi
jmp    1461 <main+0x221>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x800,%esi
call   1110 <bzero@plt>
mov    $0x2,%edi
call   1150 <sleep@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    $0x800,%edx
call   1090 <read@plt>
test   %rax,%rax
jns    1470 <main+0x230>
lea    0xc08(%rip),%rdi
call   1100 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    %r14d,%edi
call   1080 <close@plt>
lea    0xbef(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %edi,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.sockaddr = type { i32 }
%struct.hostent = type { i32, i64 }
@.str = [39 x i8] c"Please give host name and port number\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [16 x i8] c"File not found!\00"
@.str.5 = [8 x i8] c"connect\00"
@.str.6 = [41 x i8] c"Requested connection to host %s port %d\0A\00"
@.str.7 = [13 x i8] c"Sending:\0A%s\0A\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [5 x i8] c"read\00"
@.str.10 = [8 x i8] c"Got:\0A%s\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 [2048 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr*
%12 = alloca %struct.hostent*
%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 %19
16: ; preds = %2
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i32, i32* @PF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %7
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%26 = call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call %struct.hostent* @gethostbyname(i8* %30)
store %struct.hostent* %31, %struct.hostent** %12
%32 = icmp eq %struct.hostent* %31, null
br i1 %32, label %33, label %36
33: ; preds = %27
%34 = call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%35 = call i32 @exit(i32 1)
unreachable
36: ; preds = %27
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 2
%39 = load i8*, i8** %38
%40 = call i32 @atoi(i8* %39)
store i32 %40, i32* %6
%41 = load i32, i32* @PF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %41, i32* %42
%43 = load %struct.hostent*, %struct.hostent** %12
%44 = getelementptr inbounds %struct.hostent, %struct.hostent* %43, i32 0, i32 1
%45 = load i64, i64* %44
%46 = inttoptr i64 %45 to i8*
%47 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%48 = bitcast i32* %47 to i8*
%49 = load %struct.hostent*, %struct.hostent** %12
%50 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i32 0, i32 0
%51 = load i32, i32* %50
%52 = call i32 @bcopy(i8* %46, i8* %48, i32 %51)
%53 = load i32, i32* %6
%54 = call i32 @htons(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
store i32 %54, i32* %55
%56 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
store %struct.sockaddr* %56, %struct.sockaddr** %11
store i32 12, i32* %8
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 3
%59 = load i8*, i8** %58
%60 = call i32* @fopen(i8* %59, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %60, i32** %13
%61 = icmp eq i32* %60, null
br i1 %61, label %62, label %64
62: ; preds = %36
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
ret i32 1
64: ; preds = %36
%65 = load i32, i32* %7
%66 = load %struct.sockaddr*, %struct.sockaddr** %11
%67 = load i32, i32* %8
%68 = call i64 @connect(i32 %65, %struct.sockaddr* %66, i32 %67)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = load i8**, i8*** %5
%75 = getelementptr inbounds i8*, i8** %74, i64 1
%76 = load i8*, i8** %75
%77 = load i32, i32* %6
%78 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8* %76, i32 %77)
%79 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%80 = call i32 @bzero(i8* %79, i32 2048)
br label %81
81: ; preds = %86, %73
%82 = load i32*, i32** %13
%83 = call i32 @feof(i32* %82)
%84 = icmp ne i32 %83, 0
%85 = xor i1 %84, true
br i1 %85, label %86, label %93
86: ; preds = %81
%87 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%88 = call i32 @strlen(i8* %87)
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 %89
%91 = load i32*, i32** %13
%92 = call i32 @fgets(i8* %90, i32 2048, i32* %91)
br label %81
93: ; preds = %81
%94 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%95 = call i32 @strlen(i8* %94)
%96 = sext i32 %95 to i64
%97 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 %96
store i8 13, i8* %97
%98 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%99 = call i32 @strlen(i8* %98)
%100 = add nsw i32 %99, 1
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 %101
store i8 10, i8* %102
%103 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%104 = call i32 @strlen(i8* %103)
%105 = add nsw i32 %104, 2
%106 = sext i32 %105 to i64
%107 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 %106
store i8 0, i8* %107
%108 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%109 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %108)
%110 = load i32, i32* %7
%111 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%112 = call i64 @write(i32 %110, i8* %111, i32 2048)
%113 = icmp slt i64 %112, 0
br i1 %113, label %114, label %117
114: ; preds = %93
%115 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%116 = call i32 @exit(i32 1)
unreachable
117: ; preds = %93
%118 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%119 = call i32 @bzero(i8* %118, i32 2048)
%120 = call i32 @sleep(i32 2)
%121 = load i32, i32* %7
%122 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%123 = call i64 @read(i32 %121, i8* %122, i32 2048)
%124 = icmp slt i64 %123, 0
br i1 %124, label %125, label %128
125: ; preds = %117
%126 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%127 = call i32 @exit(i32 1)
unreachable
128: ; preds = %117
%129 = load i32, i32* %7
%130 = call i32 @close(i32 %129)
%131 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* %131)
%133 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [7 x i8] c"socket\00"
@.str.2 = [14 x i8] c"gethostbyname\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [16 x i8] c"File not found!\00"
@.str.5 = [8 x i8] c"connect\00"
@.str.6 = [41 x i8] c"Requested connection to host %s port %d\0A\00"
@.str.7 = [13 x i8] c"Sending:\0A%s\0A\00"
@.str.8 = [6 x i8] c"write\00"
@.str.9 = [5 x i8] c"read\00"
@.str.10 = [8 x i8] c"Got:\0A%s\00"
@str = [38 x i8] c"Please give host name and port number\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [2048 x i8], [2048 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 %11
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = load i32, i32* @PF_INET
%13 = load i32, i32* @SOCK_STREAM
%14 = tail call i32 @socket(i32 %12, i32 %13, i32 0)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%18 = tail call i32 @exit(i32 1)
unreachable
19: ; preds = %11
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call %struct.hostent* @gethostbyname(i8* %21)
%23 = icmp eq %struct.hostent* %22, null
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = tail call i32 @herror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%26 = tail call i32 @exit(i32 1)
unreachable
27: ; preds = %19
%28 = getelementptr inbounds i8*, i8** %1, i64 2
%29 = load i8*, i8** %28
%30 = tail call i32 @atoi(i8* %29)
%31 = load i32, i32* @PF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %31, i32* %32
%33 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i64 0, i32 1
%34 = load i64, i64* %33
%35 = inttoptr i64 %34 to i8*
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
%37 = bitcast i32* %36 to i8*
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i64 0, i32 0
%39 = load i32, i32* %38
%40 = tail call i32 @htons(i32 %30)
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %40, i32* %41
%42 = getelementptr inbounds i8*, i8** %1, i64 3
%43 = load i8*, i8** %42
%44 = tail call i32* @fopen(i8* %43, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%45 = icmp eq i32* %44, null
br i1 %45, label %46, label %48
46: ; preds = %27
%47 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
ret i32 1
48: ; preds = %27
%49 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%50 = call i64 @connect(i32 %14, %struct.sockaddr* %49, i32 12)
%51 = icmp slt i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0))
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %48
%56 = load i8*, i8** %20
%57 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str.6, i64 0, i64 0), i8* %56, i32 %30)
%58 = call i32 @bzero(i8* %5, i32 2048)
%59 = call i32 @feof(i32* %44)
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %55, %61
%62 = call i32 @strlen(i8* %5)
%63 = sext i32 %62 to i64
%64 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %63
%65 = call i32 @fgets(i8* %64, i32 2048, i32* %44)
%66 = call i32 @feof(i32* %44)
%67 = icmp eq i32 %66, 0
br i1 %67, label %61, label %68
68: ; preds = %61, %55
%69 = call i32 @strlen(i8* %5)
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %70
store i8 13, i8* %71
%72 = call i32 @strlen(i8* %5)
%73 = add nsw i32 %72, 1
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %74
store i8 10, i8* %75
%76 = call i32 @strlen(i8* %5)
%77 = add nsw i32 %76, 2
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 %78
store i8 0, i8* %79
%80 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0), i8* %5)
%81 = call i64 @write(i32 %14, i8* %5, i32 2048)
%82 = icmp slt i64 %81, 0
br i1 %82, label %83, label %86
83: ; preds = %68
%84 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%85 = call i32 @exit(i32 1)
unreachable
86: ; preds = %68
%87 = call i32 @bzero(i8* %5, i32 2048)
%88 = call i32 @sleep(i32 2)
%89 = call i64 @read(i32 %14, i8* %5, i32 2048)
%90 = icmp slt i64 %89, 0
br i1 %90, label %91, label %94
91: ; preds = %86
%92 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.9, i64 0, i64 0))
%93 = call i32 @exit(i32 1)
unreachable
94: ; preds = %86
%95 = call i32 @close(i32 %14)
%96 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.10, i64 0, i64 0), i8* %5)
%97 = call i32 @exit(i32 0)
unreachable
}