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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SHUT_WR;
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);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ shutdown(int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char *argv[]) {
  int sockfd, portno, n;
  FILE *fp;
  char buf[512];
  int byterec;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  if (argc < 4) {
    fprintf(stderr, "usage %s <hostname> <port> <filename>\n", argv[0]);
    exit(1);
  }
  portno = atoi(argv[2]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0) {
    error("ERROR opening socket\n");
  }
  server = gethostbyname(argv[1]);
  if (server == NULL) {
    close(sockfd);
    fprintf(stderr, "ERROR, no such host\n");
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_port = htons(portno);
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) {
    close(sockfd);
    error("ERROR connecting");
  }
  fp = fopen(argv[3], "r");
  if (fp == NULL) {
    printf("Open file failed\n");
    return -1;
  }
  while ((byterec = fread(buf, 1, 512, fp)) > 0) {
    n = write(sockfd, buf, byterec);
    if (n < 0) {
      close(sockfd);
      error("ERROR writing to socket");
    }
  }
  fclose(fp);
  shutdown(sockfd, SHUT_WR);
  bzero(buf, 512);
  n = read(sockfd, buf, 512);
  printf("%s", buf);
  if (n < 0) {
    close(sockfd);
    error("ERROR reading from socket");
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x250,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    126b <main+0x4b>
mov    0x2d86(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xda6(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1110 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
mov    0x2d3d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    12ad <main+0x8d>
lea    0xd7f(%rip),%rdi
call   10e0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <gethostbyname@plt>
mov    %rax,-0x248(%rbp)
cmpq   $0x0,-0x248(%rbp)
jne    12ee <main+0xce>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   10c0 <fprintf@plt>
lea    -0x240(%rbp),%rdi
mov    $0xc,%esi
call   1100 <bzero@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x238(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x23c(%rbp)
mov    -0x248(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x240(%rbp),%rsi
mov    -0x248(%rbp),%rax
mov    (%rax),%edx
call   10d0 <bcopy@plt>
mov    -0x14(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
jge    136e <main+0x14e>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    0xce9(%rip),%rdi
call   10e0 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xce6(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    13ab <main+0x18b>
lea    0xccd(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1498 <main+0x278>
jmp    13b0 <main+0x190>
lea    -0x230(%rbp),%rdi
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1030 <fread@plt>
mov    %eax,-0x234(%rbp)
cmp    $0x0,%eax
jle    1414 <main+0x1f4>
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    -0x234(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    140f <main+0x1ef>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    0xc6d(%rip),%rdi
call   10e0 <error@plt>
jmp    13b0 <main+0x190>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x14(%rbp),%edi
mov    0x2bb9(%rip),%rax
mov    (%rax),%esi
call   1060 <shutdown@plt>
lea    -0x230(%rbp),%rdi
mov    $0x200,%esi
call   1100 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x230(%rbp),%rsi
mov    $0x200,%edx
call   10a0 <read@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x230(%rbp),%rsi
lea    0xc2b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jge    1489 <main+0x269>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    0xc0e(%rip),%rdi
call   10e0 <error@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %rsi,%r14
cmp    $0x3,%edi
jle    1433 <main+0x203>
mov    0x10(%r14),%rdi
call   1120 <atoi@plt>
mov    %eax,%r12d
mov    0x2d88(%rip),%r13
mov    0x0(%r13),%edi
mov    0x2d5d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
jns    1287 <main+0x57>
lea    0xda5(%rip),%rdi
call   10f0 <error@plt>
mov    0x8(%r14),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    12b7 <main+0x87>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1110 <bzero@plt>
mov    0x0(%r13),%eax
mov    %eax,0x8(%rsp)
mov    %r12d,%edi
call   1080 <htons@plt>
mov    %eax,0x4(%rsp)
mov    0x8(%rbp),%rsi
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
call   10e0 <memmove@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1140 <connect@plt>
test   %rax,%rax
jns    1313 <main+0xe3>
mov    %r15d,%edi
call   10a0 <close@plt>
lea    0xd44(%rip),%rdi
call   10f0 <error@plt>
mov    0x18(%r14),%rdi
lea    0xd45(%rip),%rsi
call   1100 <fopen@plt>
test   %rax,%rax
je     140e <main+0x1de>
mov    %rax,%rbx
lea    0x10(%rsp),%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    139c <main+0x16c>
lea    0x10(%rsp),%rbp
lea    0xd0f(%rip),%r14
jmp    1379 <main+0x149>
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
test   %eax,%eax
jle    139c <main+0x16c>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %eax,%eax
jns    1360 <main+0x130>
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r14,%rdi
call   10f0 <error@plt>
jmp    1360 <main+0x130>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    0x2c35(%rip),%rax
mov    (%rax),%esi
mov    %r15d,%edi
call   1070 <shutdown@plt>
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x200,%esi
call   1110 <bzero@plt>
mov    %r15d,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   10b0 <read@plt>
mov    %eax,%ebp
lea    0xc9d(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
test   %ebp,%ebp
jns    1404 <main+0x1d4>
mov    %r15d,%edi
call   10a0 <close@plt>
lea    0xc81(%rip),%rdi
call   10f0 <error@plt>
mov    %r15d,%edi
call   10a0 <close@plt>
jmp    141f <main+0x1ef>
lea    0xc85(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b96(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%rdx
lea    0xbba(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"usage %s <hostname> <port> <filename>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"ERROR opening socket\0A\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [18 x i8] c"Open file failed\0A\00"
@.str.6 = [24 x i8] c"ERROR writing to socket\00"
@SHUT_WR = global i32 0
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [26 x i8] c"ERROR reading from socket\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 i32*
%10 = alloca [512 x i8]
%11 = alloca i32
%12 = alloca %struct.sockaddr_in
%13 = alloca %struct.hostent*
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, 4
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 ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
%28 = load i32, i32* @AF_INET
%29 = load i32, i32* @SOCK_STREAM
%30 = call i32 @socket(i32 %28, i32 %29, i32 0)
store i32 %30, i32* %6
%31 = load i32, i32* %6
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %23
%34 = call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %23
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = call %struct.hostent* @gethostbyname(i8* %38)
store %struct.hostent* %39, %struct.hostent** %13
%40 = load %struct.hostent*, %struct.hostent** %13
%41 = icmp eq %struct.hostent* %40, null
br i1 %41, label %42, label %47
42: ; preds = %35
%43 = load i32, i32* %6
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* @stderr
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %47
47: ; preds = %42, %35
%48 = bitcast %struct.sockaddr_in* %12 to i8*
%49 = call i32 @bzero(i8* %48, i32 12)
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i32, i32* %7
%53 = call i32 @htons(i32 %52)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 1
store i32 %53, i32* %54
%55 = load %struct.hostent*, %struct.hostent** %13
%56 = getelementptr inbounds %struct.hostent, %struct.hostent* %55, i32 0, i32 1
%57 = load i64, i64* %56
%58 = inttoptr i64 %57 to i8*
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %12, i32 0, i32 0
%60 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %59, i32 0, i32 0
%61 = bitcast i32* %60 to i8*
%62 = load %struct.hostent*, %struct.hostent** %13
%63 = getelementptr inbounds %struct.hostent, %struct.hostent* %62, i32 0, i32 0
%64 = load i32, i32* %63
%65 = call i32 @bcopy(i8* %58, i8* %61, i32 %64)
%66 = load i32, i32* %6
%67 = bitcast %struct.sockaddr_in* %12 to %struct.sockaddr*
%68 = call i64 @connect(i32 %66, %struct.sockaddr* %67, i32 12)
%69 = icmp slt i64 %68, 0
br i1 %69, label %70, label %74
70: ; preds = %47
%71 = load i32, i32* %6
%72 = call i32 @close(i32 %71)
%73 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %74
74: ; preds = %70, %47
%75 = load i8**, i8*** %5
%76 = getelementptr inbounds i8*, i8** %75, i64 3
%77 = load i8*, i8** %76
%78 = call i32* @fopen(i8* %77, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %78, i32** %9
%79 = load i32*, i32** %9
%80 = icmp eq i32* %79, null
br i1 %80, label %81, label %83
81: ; preds = %74
%82 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %123
83: ; preds = %74
br label %84
84: ; preds = %100, %83
%85 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%86 = load i32*, i32** %9
%87 = call i32 @fread(i8* %85, i32 1, i32 512, i32* %86)
store i32 %87, i32* %11
%88 = icmp sgt i32 %87, 0
br i1 %88, label %89, label %101
89: ; preds = %84
%90 = load i32, i32* %6
%91 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%92 = load i32, i32* %11
%93 = call i32 @write(i32 %90, i8* %91, i32 %92)
store i32 %93, i32* %8
%94 = load i32, i32* %8
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %100
96: ; preds = %89
%97 = load i32, i32* %6
%98 = call i32 @close(i32 %97)
%99 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %100
100: ; preds = %96, %89
br label %84
101: ; preds = %84
%102 = load i32*, i32** %9
%103 = call i32 @fclose(i32* %102)
%104 = load i32, i32* %6
%105 = load i32, i32* @SHUT_WR
%106 = call i32 @shutdown(i32 %104, i32 %105)
%107 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%108 = call i32 @bzero(i8* %107, i32 512)
%109 = load i32, i32* %6
%110 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%111 = call i32 @read(i32 %109, i8* %110, i32 512)
store i32 %111, i32* %8
%112 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%113 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %112)
%114 = load i32, i32* %8
%115 = icmp slt i32 %114, 0
br i1 %115, label %116, label %120
116: ; preds = %101
%117 = load i32, i32* %6
%118 = call i32 @close(i32 %117)
%119 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
br label %120
120: ; preds = %116, %101
%121 = load i32, i32* %6
%122 = call i32 @close(i32 %121)
store i32 0, i32* %3
br label %123
123: ; preds = %120, %81
%124 = load i32, i32* %3
ret i32 %124
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [39 x i8] c"usage %s <hostname> <port> <filename>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [22 x i8] c"ERROR opening socket\0A\00"
@.str.2 = [21 x i8] c"ERROR, no such host\0A\00"
@.str.3 = [17 x i8] c"ERROR connecting\00"
@.str.4 = [2 x i8] c"r\00"
@.str.6 = [24 x i8] c"ERROR writing to socket\00"
@SHUT_WR = global i32 0
@.str.7 = [3 x i8] c"%s\00"
@.str.8 = [26 x i8] c"ERROR reading from socket\00"
@str = [17 x i8] c"Open file failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [512 x i8]
%4 = alloca %struct.sockaddr_in
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.sockaddr_in* %4 to i8*
%7 = icmp slt i32 %0, 4
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = load i8*, i8** %1
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %9, i8* getelementptr inbounds ([39 x i8], [39 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 2
%15 = load i8*, i8** %14
%16 = tail call i32 @atoi(i8* %15)
%17 = load i32, i32* @AF_INET
%18 = load i32, i32* @SOCK_STREAM
%19 = tail call i32 @socket(i32 %17, i32 %18, i32 0)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %13
%22 = tail call i32 @error(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
br label %23
23: ; preds = %21, %13
%24 = getelementptr inbounds i8*, i8** %1, i64 1
%25 = load i8*, i8** %24
%26 = tail call %struct.hostent* @gethostbyname(i8* %25)
%27 = icmp eq %struct.hostent* %26, null
br i1 %27, label %28, label %32
28: ; preds = %23
%29 = tail call i32 @close(i32 %19)
%30 = load i32, i32* @stderr
%31 = tail call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
br label %32
32: ; preds = %28, %23
%33 = call i32 @bzero(i8* %6, i32 12)
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %34, i32* %35
%36 = tail call i32 @htons(i32 %16)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i64 0, i32 1
%39 = load i64, i64* %38
%40 = inttoptr i64 %39 to i8*
%41 = getelementptr inbounds %struct.hostent, %struct.hostent* %26, i64 0, i32 0
%42 = load i32, i32* %41
%43 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%44 = call i64 @connect(i32 %19, %struct.sockaddr* %43, i32 12)
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %32
%47 = call i32 @close(i32 %19)
%48 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %46, %32
%50 = getelementptr inbounds i8*, i8** %1, i64 3
%51 = load i8*, i8** %50
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i32* %52, null
br i1 %53, label %57, label %54
54: ; preds = %49
%55 = call i32 @fread(i8* %5, i32 1, i32 512, i32* %52)
%56 = icmp sgt i32 %55, 0
br i1 %56, label %59, label %69
57: ; preds = %49
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str, i64 0, i64 0))
br label %82
59: ; preds = %54, %66
%60 = phi i32 [ %67, %66 ], [ %55, %54 ]
%61 = call i32 @write(i32 %19, i8* %5, i32 %60)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %59
%64 = call i32 @close(i32 %19)
%65 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %63, %59
%67 = call i32 @fread(i8* %5, i32 1, i32 512, i32* %52)
%68 = icmp sgt i32 %67, 0
br i1 %68, label %59, label %69
69: ; preds = %66, %54
%70 = call i32 @fclose(i32* %52)
%71 = load i32, i32* @SHUT_WR
%72 = call i32 @shutdown(i32 %19, i32 %71)
%73 = call i32 @bzero(i8* %5, i32 512)
%74 = call i32 @read(i32 %19, i8* %5, i32 512)
%75 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* %5)
%76 = icmp slt i32 %74, 0
br i1 %76, label %77, label %80
77: ; preds = %69
%78 = call i32 @close(i32 %19)
%79 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.8, i64 0, i64 0))
br label %80
80: ; preds = %77, %69
%81 = call i32 @close(i32 %19)
br label %82
82: ; preds = %80, %57
%83 = phi i32 [ -1, %57 ], [ 0, %80 ]
ret i32 %83
}