#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*/ serv_addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EOF;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ SOL_SOCKET;
int /*<<< orphan*/ SO_REUSEADDR;
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*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ setsockopt(int, int /*<<< orphan*/, int /*<<< orphan*/,
                              char const *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strtok(char *, char *);
int write(int, char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int sockfd, portno, n;
  struct sockaddr_in serv_addr;
  struct hostent *server;
  int opt = 1;
  char buffer[256];
  char buffer2[256];
  bzero(buffer, 256);
  bzero(buffer2, 256);
  if (argc < 2) {
    fprintf(stderr, "usage %s port [hostname]\n", argv[0]);
    exit(0);
  }
  portno = atoi(argv[1]);
  sockfd = socket(AF_INET, SOCK_STREAM, 0);
  if (sockfd < 0)
    error("ERROR opening socket");
  if (argc == 2) {
    server = gethostbyname("localhost");
  } else {
    server = gethostbyname(argv[2]);
  }
  if (server == NULL) {
    fprintf(stderr, "ERROR, no such host\n");
    exit(0);
  }
  bzero((char *)&serv_addr, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr,
        server->h_length);
  serv_addr.sin_port = htons(portno);
  setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&opt, sizeof(int));
  if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0)
    error("ERROR connecting");
  printf("Please enter the file location: ");
  fgets(buffer2, 255, stdin);
  strtok(buffer2, "\n");
  FILE *fp;
  fp = fopen(buffer2, "r");
  if (fp == 0) {
    printf("ERROR could not open file\n");
    close(sockfd);
    exit(0);
  }
  int x;
  int i = 0;
  while ((x = fgetc(fp)) != EOF && i < 255) {
    buffer[i] = x;
    i++;
  }
  buffer[i] = '\0';
  fclose(fp);
  n = write(sockfd, buffer, strlen(buffer));
  if (n < 0)
    error("ERROR writing to socket");
  bzero(buffer, 256);
  n = read(sockfd, buffer, 255);
  if (n < 0)
    error("ERROR reading from socket");
  printf("%s\n", buffer);
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x34(%rbp)
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1130 <bzero@plt>
lea    -0x240(%rbp),%rdi
mov    $0x100,%esi
call   1130 <bzero@plt>
cmpl   $0x2,-0x8(%rbp)
jge    12c1 <main+0x71>
mov    0x2d1d(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xd4d(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1140 <atoi@plt>
mov    %eax,-0x18(%rbp)
mov    0x2d08(%rip),%rax
mov    (%rax),%edi
mov    0x2cd7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1303 <main+0xb3>
lea    0xd1c(%rip),%rdi
call   1100 <error@plt>
cmpl   $0x2,-0x8(%rbp)
jne    1322 <main+0xd2>
lea    0xd1b(%rip),%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
jmp    1333 <main+0xe3>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   10d0 <gethostbyname@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    135c <main+0x10c>
mov    0x2c7b(%rip),%rax
mov    (%rax),%edi
lea    0xceb(%rip),%rsi
mov    $0x0,%al
call   10e0 <fprintf@plt>
xor    %edi,%edi
call   1150 <exit@plt>
lea    -0x28(%rbp),%rdi
mov    $0xc,%esi
call   1130 <bzero@plt>
mov    0x2c6f(%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   1070 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2c42(%rip),%rax
mov    (%rax),%esi
mov    0x2c01(%rip),%rax
mov    (%rax),%edx
lea    -0x34(%rbp),%rcx
mov    $0x4,%r8d
call   1030 <setsockopt@plt>
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1160 <connect@plt>
cmp    $0x0,%rax
jge    13e7 <main+0x197>
lea    0xc6c(%rip),%rdi
call   1100 <error@plt>
lea    0xc71(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x240(%rbp),%rdi
mov    0x2bd5(%rip),%rax
mov    (%rax),%edx
mov    $0xff,%esi
call   10c0 <fgets@plt>
lea    -0x240(%rbp),%rdi
lea    0xbfb(%rip),%rsi
call   1120 <strtok@plt>
lea    -0x240(%rbp),%rdi
lea    0xc50(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x248(%rbp)
cmpq   $0x0,-0x248(%rbp)
jne    1467 <main+0x217>
lea    0xc31(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %edi,%edi
call   1150 <exit@plt>
movl   $0x0,-0x250(%rbp)
mov    -0x248(%rbp),%rdi
call   1090 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x24c(%rbp)
xor    %eax,%eax
mov    0x2b42(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x251(%rbp)
je     14af <main+0x25f>
cmpl   $0xff,-0x250(%rbp)
setl   %al
mov    %al,-0x251(%rbp)
mov    -0x251(%rbp),%al
test   $0x1,%al
jne    14c2 <main+0x272>
jmp    14ec <main+0x29c>
mov    -0x24c(%rbp),%eax
mov    %al,%cl
movslq -0x250(%rbp),%rax
mov    %cl,-0x140(%rbp,%rax,1)
mov    -0x250(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x250(%rbp)
jmp    1471 <main+0x221>
movslq -0x250(%rbp),%rax
movb   $0x0,-0x140(%rbp,%rax,1)
mov    -0x248(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x264(%rbp)
lea    -0x140(%rbp),%rax
mov    %rax,-0x260(%rbp)
lea    -0x140(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x264(%rbp),%edi
mov    -0x260(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1557 <main+0x307>
lea    0xb4b(%rip),%rdi
call   1100 <error@plt>
lea    -0x140(%rbp),%rdi
mov    $0x100,%esi
call   1130 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x140(%rbp),%rsi
mov    $0xff,%edx
call   10b0 <read@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1595 <main+0x345>
lea    0xb25(%rip),%rdi
call   1100 <error@plt>
lea    -0x140(%rbp),%rsi
lea    0xb2c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
xor    %eax,%eax
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x220,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
movl   $0x1,0xc(%rsp)
lea    0x20(%rsp),%rdi
mov    $0x100,%esi
call   1140 <bzero@plt>
lea    0x120(%rsp),%rdi
mov    $0x100,%esi
call   1140 <bzero@plt>
cmp    $0x1,%ebx
jle    14ae <main+0x24e>
mov    0x8(%rbp),%rdi
call   1150 <atoi@plt>
mov    %eax,%r14d
mov    0x2d27(%rip),%r12
mov    (%r12),%edi
mov    0x2cf4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1180 <socket@plt>
mov    %eax,%r15d
test   %eax,%eax
js     12e2 <main+0x82>
cmp    $0x2,%ebx
jne    12f3 <main+0x93>
lea    0xd4f(%rip),%rdi
jmp    12f7 <main+0x97>
lea    0xd31(%rip),%rdi
call   1110 <error@plt>
cmp    $0x2,%ebx
je     12d9 <main+0x79>
mov    0x10(%rbp),%rdi
call   10e0 <gethostbyname@plt>
test   %rax,%rax
je     14d0 <main+0x270>
mov    %rax,%rbp
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xc,%esi
call   1140 <bzero@plt>
mov    (%r12),%eax
mov    %eax,0x18(%rsp)
mov    0x8(%rbp),%rsi
lea    0x14(%rsp),%rdi
mov    0x0(%rbp),%edx
call   1100 <memmove@plt>
mov    %r14d,%edi
call   1080 <htons@plt>
mov    %eax,0x10(%rsp)
mov    0x2ca2(%rip),%rax
mov    (%rax),%esi
mov    0x2c61(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rcx
mov    %r15d,%edi
mov    $0x4,%r8d
call   1040 <setsockopt@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xc,%edx
call   1170 <connect@plt>
test   %rax,%rax
jns    1385 <main+0x125>
lea    0xcce(%rip),%rdi
call   1110 <error@plt>
lea    0xcd3(%rip),%rdi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x2c3e(%rip),%rax
mov    (%rax),%edx
lea    0x120(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xff,%esi
call   10d0 <fgets@plt>
lea    0xc60(%rip),%rsi
mov    %rbx,%rdi
call   1130 <strtok@plt>
lea    0xcb9(%rip),%rsi
mov    %rbx,%rdi
call   1120 <fopen@plt>
test   %rax,%rax
je     14ee <main+0x28e>
mov    %rax,%r12
mov    %rax,%rdi
call   10a0 <fgetc@plt>
mov    0x2be6(%rip),%r14
cmp    (%r14),%eax
jne    13f3 <main+0x193>
xor    %ebp,%ebp
jmp    1421 <main+0x1c1>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    %al,0x20(%rsp,%rbx,1)
lea    0x1(%rbx),%rbp
mov    %r12,%rdi
call   10a0 <fgetc@plt>
cmp    (%r14),%eax
je     1421 <main+0x1c1>
cmp    $0xfe,%rbx
mov    %rbp,%rbx
jb     1400 <main+0x1a0>
movb   $0x0,0x20(%rsp,%rbp,1)
mov    %r12,%rdi
call   1060 <fclose@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <write@plt>
test   %eax,%eax
jns    1458 <main+0x1f8>
lea    0xc2f(%rip),%rdi
call   1110 <error@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1140 <bzero@plt>
mov    %r15d,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
call   10c0 <read@plt>
test   %eax,%eax
jns    148a <main+0x22a>
lea    0xc15(%rip),%rdi
call   1110 <error@plt>
lea    0x20(%rsp),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b0b(%rip),%rax
mov    (%rax),%edi
mov    0x0(%rbp),%rdx
lea    0xb3e(%rip),%rsi
xor    %eax,%eax
call   10f0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
mov    0x2ae9(%rip),%rax
mov    (%rax),%edi
lea    0xb59(%rip),%rsi
xor    %eax,%eax
call   10f0 <fprintf@plt>
xor    %edi,%edi
call   1160 <exit@plt>
lea    0xbbf(%rip),%rdi
call   1030 <puts@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
xor    %edi,%edi
call   1160 <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 }
@stderr = global i32 0
@.str = [26 x i8] c"usage %s port [hostname]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [33 x i8] c"Please enter the file location: \00"
@stdin = global i32 0
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [2 x i8] c"r\00"
@.str.8 = [27 x i8] c"ERROR could not open file\0A\00"
@EOF = global i32 0
@.str.9 = [24 x i8] c"ERROR writing to socket\00"
@.str.10 = [26 x i8] c"ERROR reading from socket\00"
@.str.11 = [4 x i8] c"%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 i32
%12 = alloca [256 x i8]
%13 = alloca [256 x i8]
%14 = alloca i32*
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%18 = call i32 @bzero(i8* %17, i32 256)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%20 = call i32 @bzero(i8* %19, i32 256)
%21 = load i32, i32* %4
%22 = icmp slt i32 %21, 2
br i1 %22, label %23, label %30
23: ; preds = %2
%24 = load i32, i32* @stderr
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 0
%27 = load i8*, i8** %26
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %27)
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %2
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 1
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %7
%35 = load i32, i32* @AF_INET
%36 = load i32, i32* @SOCK_STREAM
%37 = call i32 @socket(i32 %35, i32 %36, i32 0)
store i32 %37, i32* %6
%38 = load i32, i32* %6
%39 = icmp slt i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %30
%41 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %42
42: ; preds = %40, %30
%43 = load i32, i32* %4
%44 = icmp eq i32 %43, 2
br i1 %44, label %45, label %47
45: ; preds = %42
%46 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store %struct.hostent* %46, %struct.hostent** %10
br label %52
47: ; preds = %42
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call %struct.hostent* @gethostbyname(i8* %50)
store %struct.hostent* %51, %struct.hostent** %10
br label %52
52: ; preds = %47, %45
%53 = load %struct.hostent*, %struct.hostent** %10
%54 = icmp eq %struct.hostent* %53, null
br i1 %54, label %55, label %59
55: ; preds = %52
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 0)
unreachable
59: ; preds = %52
%60 = bitcast %struct.sockaddr_in* %9 to i8*
%61 = call i32 @bzero(i8* %60, i32 12)
%62 = load i32, i32* @AF_INET
%63 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %62, i32* %63
%64 = load %struct.hostent*, %struct.hostent** %10
%65 = getelementptr inbounds %struct.hostent, %struct.hostent* %64, i32 0, i32 1
%66 = load i64, i64* %65
%67 = inttoptr i64 %66 to i8*
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%69 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %68, i32 0, i32 0
%70 = bitcast i32* %69 to i8*
%71 = load %struct.hostent*, %struct.hostent** %10
%72 = getelementptr inbounds %struct.hostent, %struct.hostent* %71, i32 0, i32 0
%73 = load i32, i32* %72
%74 = call i32 @bcopy(i8* %67, i8* %70, i32 %73)
%75 = load i32, i32* %7
%76 = call i32 @htons(i32 %75)
%77 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %76, i32* %77
%78 = load i32, i32* %6
%79 = load i32, i32* @SOL_SOCKET
%80 = load i32, i32* @SO_REUSEADDR
%81 = bitcast i32* %11 to i8*
%82 = call i32 @setsockopt(i32 %78, i32 %79, i32 %80, i8* %81, i32 4)
%83 = load i32, i32* %6
%84 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%85 = call i64 @connect(i32 %83, %struct.sockaddr* %84, i32 12)
%86 = icmp slt i64 %85, 0
br i1 %86, label %87, label %89
87: ; preds = %59
%88 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %89
89: ; preds = %87, %59
%90 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%91 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%92 = load i32, i32* @stdin
%93 = call i32 @fgets(i8* %91, i32 255, i32 %92)
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%95 = call i32 @strtok(i8* %94, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%96 = getelementptr inbounds [256 x i8], [256 x i8]* %13, i64 0, i64 0
%97 = call i32* @fopen(i8* %96, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %97, i32** %14
%98 = load i32*, i32** %14
%99 = icmp eq i32* %98, null
br i1 %99, label %100, label %105
100: ; preds = %89
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.8, i64 0, i64 0))
%102 = load i32, i32* %6
%103 = call i32 @close(i32 %102)
%104 = call i32 @exit(i32 0)
unreachable
105: ; preds = %89
store i32 0, i32* %16
br label %106
106: ; preds = %116, %105
%107 = load i32*, i32** %14
%108 = call i32 @fgetc(i32* %107)
store i32 %108, i32* %15
%109 = load i32, i32* @EOF
%110 = icmp ne i32 %108, %109
br i1 %110, label %111, label %114
111: ; preds = %106
%112 = load i32, i32* %16
%113 = icmp slt i32 %112, 255
br label %114
114: ; preds = %111, %106
%115 = phi i1 [ false, %106 ], [ %113, %111 ]
br i1 %115, label %116, label %124
116: ; preds = %114
%117 = load i32, i32* %15
%118 = trunc i32 %117 to i8
%119 = load i32, i32* %16
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %120
store i8 %118, i8* %121
%122 = load i32, i32* %16
%123 = add nsw i32 %122, 1
store i32 %123, i32* %16
br label %106
124: ; preds = %114
%125 = load i32, i32* %16
%126 = sext i32 %125 to i64
%127 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 %126
store i8 0, i8* %127
%128 = load i32*, i32** %14
%129 = call i32 @fclose(i32* %128)
%130 = load i32, i32* %6
%131 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%132 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%133 = call i32 @strlen(i8* %132)
%134 = call i32 @write(i32 %130, i8* %131, i32 %133)
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 = %124
%138 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %139
139: ; preds = %137, %124
%140 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%141 = call i32 @bzero(i8* %140, i32 256)
%142 = load i32, i32* %6
%143 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%144 = call i32 @read(i32 %142, i8* %143, i32 255)
store i32 %144, i32* %8
%145 = load i32, i32* %8
%146 = icmp slt i32 %145, 0
br i1 %146, label %147, label %149
147: ; preds = %139
%148 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %149
149: ; preds = %147, %139
%150 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%151 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i8* %150)
%152 = load i32, i32* %6
%153 = call i32 @close(i32 %152)
ret i32 0
}

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 }
@stderr = global i32 0
@.str = [26 x i8] c"usage %s port [hostname]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [21 x i8] c"ERROR opening socket\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [21 x i8] c"ERROR, no such host\0A\00"
@SOL_SOCKET = global i32 0
@SO_REUSEADDR = global i32 0
@.str.4 = [17 x i8] c"ERROR connecting\00"
@.str.5 = [33 x i8] c"Please enter the file location: \00"
@stdin = global i32 0
@.str.6 = [2 x i8] c"\0A\00"
@.str.7 = [2 x i8] c"r\00"
@EOF = global i32 0
@.str.9 = [24 x i8] c"ERROR writing to socket\00"
@.str.10 = [26 x i8] c"ERROR reading from socket\00"
@str = [26 x i8] c"ERROR could not open file\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i32
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = bitcast %struct.sockaddr_in* %3 to i8*
%8 = bitcast i32* %4 to i8*
store i32 1, i32* %4
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%11 = call i32 @bzero(i8* %9, i32 256)
%12 = call i32 @bzero(i8* %10, i32 256)
%13 = icmp slt i32 %0, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %1
%17 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %2
%20 = getelementptr inbounds i8*, i8** %1, i64 1
%21 = load i8*, i8** %20
%22 = tail call i32 @atoi(i8* %21)
%23 = load i32, i32* @AF_INET
%24 = load i32, i32* @SOCK_STREAM
%25 = tail call i32 @socket(i32 %23, i32 %24, i32 0)
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %29
27: ; preds = %19
%28 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %27, %19
%30 = icmp eq i32 %0, 2
br i1 %30, label %34, label %31
31: ; preds = %29
%32 = getelementptr inbounds i8*, i8** %1, i64 2
%33 = load i8*, i8** %32
br label %34
34: ; preds = %29, %31
%35 = phi i8* [ %33, %31 ], [ getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), %29 ]
%36 = tail call %struct.hostent* @gethostbyname(i8* %35)
%37 = icmp eq %struct.hostent* %36, null
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* @stderr
%40 = tail call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0))
%41 = tail call i32 @exit(i32 0)
unreachable
42: ; preds = %34
%43 = call i32 @bzero(i8* %7, i32 12)
%44 = load i32, i32* @AF_INET
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %44, i32* %45
%46 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i64 0, i32 1
%47 = load i64, i64* %46
%48 = inttoptr i64 %47 to i8*
%49 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1, i32 0
%50 = bitcast i32* %49 to i8*
%51 = getelementptr inbounds %struct.hostent, %struct.hostent* %36, i64 0, i32 0
%52 = load i32, i32* %51
%53 = tail call i32 @htons(i32 %22)
%54 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %53, i32* %54
%55 = load i32, i32* @SOL_SOCKET
%56 = load i32, i32* @SO_REUSEADDR
%57 = call i32 @setsockopt(i32 %25, i32 %55, i32 %56, i8* %8, i32 4)
%58 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%59 = call i64 @connect(i32 %25, %struct.sockaddr* %58, i32 12)
%60 = icmp slt i64 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %42
%62 = call i32 @error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %63
63: ; preds = %61, %42
%64 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0))
%65 = load i32, i32* @stdin
%66 = call i32 @fgets(i8* %10, i32 255, i32 %65)
%67 = call i32 @strtok(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%68 = call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%69 = icmp eq i32* %68, null
br i1 %69, label %74, label %70
70: ; preds = %63
%71 = call i32 @fgetc(i32* %68)
%72 = load i32, i32* @EOF
%73 = icmp eq i32 %71, %72
br i1 %73, label %89, label %78
74: ; preds = %63
%75 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%76 = call i32 @close(i32 %25)
%77 = call i32 @exit(i32 0)
unreachable
78: ; preds = %70, %78
%79 = phi i64 [ %83, %78 ], [ 0, %70 ]
%80 = phi i32 [ %84, %78 ], [ %71, %70 ]
%81 = trunc i32 %80 to i8
%82 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %79
store i8 %81, i8* %82
%83 = add nuw nsw i64 %79, 1
%84 = call i32 @fgetc(i32* %68)
%85 = load i32, i32* @EOF
%86 = icmp ne i32 %84, %85
%87 = icmp ult i64 %79, 254
%88 = select i1 %86, i1 %87, i1 false
br i1 %88, label %78, label %89
89: ; preds = %78, %70
%90 = phi i64 [ 0, %70 ], [ %83, %78 ]
%91 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 %90
store i8 0, i8* %91
%92 = call i32 @fclose(i32* %68)
%93 = call i32 @strlen(i8* %9)
%94 = call i32 @write(i32 %25, i8* %9, i32 %93)
%95 = icmp slt i32 %94, 0
br i1 %95, label %96, label %98
96: ; preds = %89
%97 = call i32 @error(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
br label %98
98: ; preds = %96, %89
%99 = call i32 @bzero(i8* %9, i32 256)
%100 = call i32 @read(i32 %25, i8* %9, i32 255)
%101 = icmp slt i32 %100, 0
br i1 %101, label %102, label %104
102: ; preds = %98
%103 = call i32 @error(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.10, i64 0, i64 0))
br label %104
104: ; preds = %102, %98
%105 = call i32 @puts(i8* %9)
%106 = call i32 @close(i32 %25)
ret i32 0
}