#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 stat {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ 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*/ server;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
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 /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int fwrite(char *, int, int, int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(unsigned short);
char *inet_ntoa(int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(void *, void *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read_cli(int, char const **);
int recv(int, char *, int, int /*<<< orphan*/);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int main(int argc, char const *argv[]) {
  unsigned short port;
  int tport = read_cli(argc, argv);
  if (tport < 0) {
    fprintf(stderr, "Usage: file_name port_number(8000-9000)\n");
    exit(EXIT_FAILURE);
  }
  port = (unsigned short)tport;
  int sock = socket(PF_INET, SOCK_STREAM, 0);
  if (sock < 0) {
    perror("socket() failed");
    exit(EXIT_FAILURE);
  }
  struct hostent *hp = gethostbyname("localhost");
  if (hp == NULL) {
    perror("gethostbyname() failed");
    exit(EXIT_FAILURE);
  }
  struct sockaddr_in server;
  server.sin_family = PF_INET;
  memcpy((void *)&server.sin_addr, (void *)hp->h_addr, hp->h_length);
  server.sin_port = htons(port);
  printf("server address is %s\n", inet_ntoa(server.sin_addr));
  if (connect(sock, (struct sockaddr *)&server, sizeof(server)) < 0) {
    perror("connect() failed");
    exit(EXIT_FAILURE);
  }
  char *msg_LIST = "LIST\n\0";
  char *msg_ADD = "ADD maybe3.txt 27\nadsab cdefghijklmnopqrstuvwxyz";
  char *msg_ADD1 = "ADD test.txt "
                   "69\nabcdefghijklmnopqrstuvwxyzdksjahfklsdjhfasdjklhfsdklafh"
                   "asklfhasjklf\0";
  char *msg_APPEND = "APPEND maybe.txt 20\nAPPENDED: HELLO WORLD";
  char *msg_READ = "READ test.txt\n\0";
  char *msg_DELETE = "DELETE test.txt\n\0";
  char *msg_ADD_binary = "ADD banner1.png 59930\n";
  int n;
  struct stat buf;
  char sdbuf[5000000];
  bzero(sdbuf, 5000000);
  int fs_block_sz;
  FILE *fs = fopen("banner1.png", "r");
  while ((fs_block_sz = fread(sdbuf, sizeof(char), 5000000, fs)) > 0) {
    if (send(sock, sdbuf, fs_block_sz, 0) < 0) {
      break;
    }
    bzero(sdbuf, 5000000);
  }
  char revbuf[5000000];
  char *fr_name = "banner2.png";
  FILE *fr = fopen(fr_name, "w");
  if (fr == NULL)
    printf("File %s Cannot be opened.\n", fr_name);
  else {
    bzero(revbuf, 5000000);
    int fr_block_sz = 0;
    while ((fr_block_sz = recv(sock, revbuf, 5000000, 0)) > 0) {
      int write_sz = fwrite(revbuf, sizeof(char), fr_block_sz, fr);
      if (write_sz < fr_block_sz) {
        error("File write failed.\n");
      }
      bzero(revbuf, 5000000);
      if (fr_block_sz == 0 || fr_block_sz != 512) {
        break;
      }
    }
    if (fr_block_sz < 0)
      printf("recv() timed out.\n");
  }
  printf("Ok received from server!\n");
  fclose(fr);
  close(sock);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x989730,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   10b0 <read_cli@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1295 <main+0x55>
mov    0x2d67(%rip),%rax
mov    (%rax),%edi
lea    0xd7e(%rip),%rsi
call   10d0 <fprintf@plt>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
mov    -0x18(%rbp),%eax
mov    %ax,-0x12(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%edi
mov    0x2d2c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    12dc <main+0x9c>
lea    0xd60(%rip),%rdi
call   1110 <perror@plt>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
lea    0xd56(%rip),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1311 <main+0xd1>
lea    0xd45(%rip),%rdi
call   1110 <perror@plt>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
mov    0x2cb8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
lea    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x28(%rbp),%rax
mov    (%rax),%edx
call   10e0 <memcpy@plt>
movzwl -0x12(%rbp),%edi
call   1070 <htons@plt>
mov    %eax,-0x34(%rbp)
mov    -0x38(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
mov    $0xc,%edx
call   1140 <connect@plt>
cmp    $0x0,%rax
jge    138e <main+0x14e>
lea    0xcf5(%rip),%rdi
call   1110 <perror@plt>
mov    0x2c41(%rip),%rax
mov    (%rax),%edi
call   1130 <exit@plt>
lea    0xdd6(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xce1(%rip),%rax
mov    %rax,-0x48(%rbp)
lea    0xdc7(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xcfc(%rip),%rax
mov    %rax,-0x58(%rbp)
lea    0xe18(%rip),%rax
mov    %rax,-0x60(%rbp)
lea    0xdfb(%rip),%rax
mov    %rax,-0x68(%rbp)
lea    0xd05(%rip),%rax
mov    %rax,-0x70(%rbp)
lea    -0x4c4bc0(%rbp),%rdi
mov    $0x4c4b40,%esi
call   1120 <bzero@plt>
lea    0xd00(%rip),%rdi
lea    0xd05(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x4c4bd0(%rbp)
lea    -0x4c4bc0(%rbp),%rdi
mov    -0x4c4bd0(%rbp),%rcx
mov    $0x1,%esi
mov    $0x4c4b40,%edx
call   1040 <fread@plt>
mov    %eax,-0x4c4bc4(%rbp)
cmp    $0x0,%eax
jle    146e <main+0x22e>
mov    -0x1c(%rbp),%edi
lea    -0x4c4bc0(%rbp),%rsi
mov    -0x4c4bc4(%rbp),%edx
xor    %ecx,%ecx
call   1080 <send@plt>
cmp    $0x0,%rax
jge    1458 <main+0x218>
jmp    146e <main+0x22e>
lea    -0x4c4bc0(%rbp),%rdi
mov    $0x4c4b40,%esi
call   1120 <bzero@plt>
jmp    1406 <main+0x1c6>
lea    0xc8c(%rip),%rax
mov    %rax,-0x989718(%rbp)
mov    -0x989718(%rbp),%rdi
lea    0xc83(%rip),%rsi
call   1100 <fopen@plt>
mov    %rax,-0x989720(%rbp)
cmpq   $0x0,-0x989720(%rbp)
jne    14be <main+0x27e>
mov    -0x989718(%rbp),%rsi
lea    0xc5d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1598 <main+0x358>
lea    -0x989710(%rbp),%rdi
mov    $0x4c4b40,%esi
call   1120 <bzero@plt>
movl   $0x0,-0x989724(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x989710(%rbp),%rsi
mov    $0x4c4b40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %eax,-0x989724(%rbp)
cmp    $0x0,%eax
jle    1578 <main+0x338>
lea    -0x989710(%rbp),%rdi
mov    -0x989724(%rbp),%edx
mov    -0x989720(%rbp),%rcx
mov    $0x1,%esi
call   1150 <fwrite@plt>
mov    %eax,-0x989728(%rbp)
mov    -0x989728(%rbp),%eax
cmp    -0x989724(%rbp),%eax
jge    1540 <main+0x300>
lea    0xbef(%rip),%rdi
call   10f0 <error@plt>
lea    -0x989710(%rbp),%rdi
mov    $0x4c4b40,%esi
call   1120 <bzero@plt>
cmpl   $0x0,-0x989724(%rbp)
je     156e <main+0x32e>
cmpl   $0x200,-0x989724(%rbp)
je     1573 <main+0x333>
jmp    1578 <main+0x338>
jmp    14d9 <main+0x299>
cmpl   $0x0,-0x989724(%rbp)
jge    1593 <main+0x353>
lea    0xbb2(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1598 <main+0x358>
lea    0xbb2(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x989720(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x1c(%rbp),%edi
call   10a0 <close@plt>
mov    0x29ff(%rip),%rax
mov    (%rax),%eax
add    $0x989730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x989690,%rsp
call   10c0 <read_cli@plt>
test   %eax,%eax
js     1477 <main+0x227>
mov    %eax,%ebx
mov    0x2d5b(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d59(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1170 <socket@plt>
test   %eax,%eax
js     148e <main+0x23e>
mov    %eax,%r14d
lea    0xd9f(%rip),%rdi
call   10d0 <gethostbyname@plt>
test   %rax,%rax
je     1497 <main+0x247>
mov    0x0(%rbp),%ecx
mov    %ecx,0x8(%rsp)
mov    0x8(%rax),%rsi
mov    (%rax),%edx
mov    %rsp,%rbp
mov    %rbp,%rdi
call   10f0 <memcpy@plt>
movzwl %bx,%edi
call   1080 <htons@plt>
mov    %eax,0x4(%rsp)
mov    (%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xd7f(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0xc,%edx
call   1150 <connect@plt>
test   %rax,%rax
js     14a0 <main+0x250>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x4c4b40,%esi
call   1130 <bzero@plt>
lea    0xd6a(%rip),%rdi
lea    0xd6f(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x4c4b40,%edx
mov    %rax,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jle    138a <main+0x13a>
lea    0x10(%rsp),%rbp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14d,%edi
mov    %rbp,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
test   %rax,%rax
js     138a <main+0x13a>
mov    %rbp,%rdi
mov    $0x4c4b40,%esi
call   1130 <bzero@plt>
mov    %rbp,%rdi
mov    $0x1,%esi
mov    $0x4c4b40,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
test   %eax,%eax
jg     1350 <main+0x100>
lea    0xcfe(%rip),%rdi
lea    0xd03(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
je     141d <main+0x1cd>
lea    0x4c4b50(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x4c4b40,%esi
call   1130 <bzero@plt>
lea    0xcf7(%rip),%r15
jmp    13e5 <main+0x195>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbp,%rdi
mov    $0x4c4b40,%esi
call   1130 <bzero@plt>
cmp    $0x200,%ebx
jne    1442 <main+0x1f2>
mov    %r14d,%edi
mov    %rbp,%rsi
mov    $0x4c4b40,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
test   %eax,%eax
jle    1434 <main+0x1e4>
mov    %eax,%ebx
mov    %rbp,%rdi
mov    $0x1,%esi
mov    %eax,%edx
mov    %r12,%rcx
call   1160 <fwrite@plt>
cmp    %ebx,%eax
jge    13d0 <main+0x180>
mov    %r15,%rdi
call   1100 <error@plt>
jmp    13d0 <main+0x180>
lea    0xc79(%rip),%rdi
lea    0xc64(%rip),%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
jmp    1442 <main+0x1f2>
jns    1442 <main+0x1f2>
lea    0xca8(%rip),%rdi
call   1040 <puts@plt>
lea    0xc83(%rip),%rdi
call   1040 <puts@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
mov    %r14d,%edi
call   10b0 <close@plt>
mov    0x2b5b(%rip),%rax
mov    (%rax),%eax
add    $0x989690,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b62(%rip),%rax
mov    (%rax),%edi
lea    0xb79(%rip),%rsi
call   10e0 <fprintf@plt>
jmp    14ac <main+0x25c>
lea    0xb94(%rip),%rdi
jmp    14a7 <main+0x257>
lea    0xba5(%rip),%rdi
jmp    14a7 <main+0x257>
lea    0xbc9(%rip),%rdi
call   1120 <perror@plt>
mov    0x2b15(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>

LLVM IR (-O0):
%struct.hostent = type { i32, i64 }
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"Usage: file_name port_number(8000-9000)\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [23 x i8] c"gethostbyname() failed\00"
@.str.4 = [22 x i8] c"server address is %s\0A\00"
@.str.5 = [17 x i8] c"connect() failed\00"
@.str.6 = [7 x i8] c"LIST\0A\00\00"
@.str.7 = [49 x i8] c"ADD maybe3.txt 27\0Aadsab cdefghijklmnopqrstuvwxyz\00"
@.str.8 = [85 x i8] c"ADD test.txt 69\0Aabcdefghijklmnopqrstuvwxyzdksjahfklsdjhfasdjklhfsdklafhasklfhasjklf\00\00"
@.str.9 = [42 x i8] c"APPEND maybe.txt 20\0AAPPENDED: HELLO WORLD\00"
@.str.10 = [16 x i8] c"READ test.txt\0A\00\00"
@.str.11 = [18 x i8] c"DELETE test.txt\0A\00\00"
@.str.12 = [23 x i8] c"ADD banner1.png 59930\0A\00"
@.str.13 = [12 x i8] c"banner1.png\00"
@.str.14 = [2 x i8] c"r\00"
@.str.15 = [12 x i8] c"banner2.png\00"
@.str.16 = [2 x i8] c"w\00"
@.str.17 = [27 x i8] c"File %s Cannot be opened.\0A\00"
@.str.18 = [20 x i8] c"File write failed.\0A\00"
@.str.19 = [19 x i8] c"recv() timed out.\0A\00"
@.str.20 = [26 x i8] c"Ok received from server!\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i16
%7 = alloca i32
%8 = alloca i32
%9 = alloca %struct.hostent*
%10 = alloca %struct.sockaddr_in
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca i8*
%18 = alloca i32
%19 = alloca %struct.stat
%20 = alloca [5000000 x i8]
%21 = alloca i32
%22 = alloca i32*
%23 = alloca [5000000 x i8]
%24 = alloca i8*
%25 = alloca i32*
%26 = alloca i32
%27 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%28 = load i32, i32* %4
%29 = load i8**, i8*** %5
%30 = call i32 @read_cli(i32 %28, i8** %29)
store i32 %30, i32* %7
%31 = load i32, i32* %7
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %38
33: ; preds = %2
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %2
%39 = load i32, i32* %7
%40 = trunc i32 %39 to i16
store i16 %40, i16* %6
%41 = load i32, i32* @PF_INET
%42 = load i32, i32* @SOCK_STREAM
%43 = call i32 @socket(i32 %41, i32 %42, i32 0)
store i32 %43, i32* %8
%44 = load i32, i32* %8
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %38
%47 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%48 = load i32, i32* @EXIT_FAILURE
%49 = call i32 @exit(i32 %48)
unreachable
50: ; preds = %38
%51 = call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store %struct.hostent* %51, %struct.hostent** %9
%52 = load %struct.hostent*, %struct.hostent** %9
%53 = icmp eq %struct.hostent* %52, null
br i1 %53, label %54, label %58
54: ; preds = %50
%55 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %50
%59 = load i32, i32* @PF_INET
%60 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %59, i32* %60
%61 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%62 = bitcast i32* %61 to i8*
%63 = load %struct.hostent*, %struct.hostent** %9
%64 = getelementptr inbounds %struct.hostent, %struct.hostent* %63, i32 0, i32 1
%65 = load i64, i64* %64
%66 = inttoptr i64 %65 to i8*
%67 = load %struct.hostent*, %struct.hostent** %9
%68 = getelementptr inbounds %struct.hostent, %struct.hostent* %67, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i32 @memcpy(i8* %62, i8* %66, i32 %69)
%71 = load i16, i16* %6
%72 = call i32 @htons(i16 zeroext %71)
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
store i32 %72, i32* %73
%74 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i8* @inet_ntoa(i32 %75)
%77 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %76)
%78 = load i32, i32* %8
%79 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%80 = call i64 @connect(i32 %78, %struct.sockaddr* %79, i32 12)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %58
%83 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%84 = load i32, i32* @EXIT_FAILURE
%85 = call i32 @exit(i32 %84)
unreachable
86: ; preds = %58
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8** %11
store i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i8** %12
store i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str.8, i64 0, i64 0), i8** %13
store i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.9, i64 0, i64 0), i8** %14
store i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.10, i64 0, i64 0), i8** %15
store i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.11, i64 0, i64 0), i8** %16
store i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.12, i64 0, i64 0), i8** %17
%87 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %20, i64 0, i64 0
%88 = call i32 @bzero(i8* %87, i32 5000000)
%89 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
store i32* %89, i32** %22
br label %90
90: ; preds = %102, %86
%91 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %20, i64 0, i64 0
%92 = load i32*, i32** %22
%93 = call i32 @fread(i8* %91, i32 1, i32 5000000, i32* %92)
store i32 %93, i32* %21
%94 = icmp sgt i32 %93, 0
br i1 %94, label %95, label %105
95: ; preds = %90
%96 = load i32, i32* %8
%97 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %20, i64 0, i64 0
%98 = load i32, i32* %21
%99 = call i64 @send(i32 %96, i8* %97, i32 %98, i32 0)
%100 = icmp slt i64 %99, 0
br i1 %100, label %101, label %102
101: ; preds = %95
br label %105
102: ; preds = %95
%103 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %20, i64 0, i64 0
%104 = call i32 @bzero(i8* %103, i32 5000000)
br label %90
105: ; preds = %101, %90
store i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0), i8** %24
%106 = load i8*, i8** %24
%107 = call i32* @fopen(i8* %106, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
store i32* %107, i32** %25
%108 = load i32*, i32** %25
%109 = icmp eq i32* %108, null
br i1 %109, label %110, label %113
110: ; preds = %105
%111 = load i8*, i8** %24
%112 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.17, i64 0, i64 0), i8* %111)
br label %147
113: ; preds = %105
%114 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %23, i64 0, i64 0
%115 = call i32 @bzero(i8* %114, i32 5000000)
store i32 0, i32* %26
br label %116
116: ; preds = %140, %113
%117 = load i32, i32* %8
%118 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %23, i64 0, i64 0
%119 = call i32 @recv(i32 %117, i8* %118, i32 5000000, i32 0)
store i32 %119, i32* %26
%120 = icmp sgt i32 %119, 0
br i1 %120, label %121, label %141
121: ; preds = %116
%122 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %23, i64 0, i64 0
%123 = load i32, i32* %26
%124 = load i32*, i32** %25
%125 = call i32 @fwrite(i8* %122, i32 1, i32 %123, i32* %124)
store i32 %125, i32* %27
%126 = load i32, i32* %27
%127 = load i32, i32* %26
%128 = icmp slt i32 %126, %127
br i1 %128, label %129, label %131
129: ; preds = %121
%130 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0))
br label %131
131: ; preds = %129, %121
%132 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %23, i64 0, i64 0
%133 = call i32 @bzero(i8* %132, i32 5000000)
%134 = load i32, i32* %26
%135 = icmp eq i32 %134, 0
br i1 %135, label %139, label %136
136: ; preds = %131
%137 = load i32, i32* %26
%138 = icmp ne i32 %137, 512
br i1 %138, label %139, label %140
139: ; preds = %136, %131
br label %141
140: ; preds = %136
br label %116
141: ; preds = %139, %116
%142 = load i32, i32* %26
%143 = icmp slt i32 %142, 0
br i1 %143, label %144, label %146
144: ; preds = %141
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.19, i64 0, i64 0))
br label %146
146: ; preds = %144, %141
br label %147
147: ; preds = %146, %110
%148 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.20, i64 0, i64 0))
%149 = load i32*, i32** %25
%150 = call i32 @fclose(i32* %149)
%151 = load i32, i32* %8
%152 = call i32 @close(i32 %151)
%153 = load i32, i32* @EXIT_SUCCESS
ret i32 %153
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [41 x i8] c"Usage: file_name port_number(8000-9000)\0A\00"
@EXIT_FAILURE = global i32 0
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.1 = [16 x i8] c"socket() failed\00"
@.str.2 = [10 x i8] c"localhost\00"
@.str.3 = [23 x i8] c"gethostbyname() failed\00"
@.str.4 = [22 x i8] c"server address is %s\0A\00"
@.str.5 = [17 x i8] c"connect() failed\00"
@.str.13 = [12 x i8] c"banner1.png\00"
@.str.14 = [2 x i8] c"r\00"
@.str.15 = [12 x i8] c"banner2.png\00"
@.str.16 = [2 x i8] c"w\00"
@.str.17 = [27 x i8] c"File %s Cannot be opened.\0A\00"
@.str.18 = [20 x i8] c"File write failed.\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [25 x i8] c"Ok received from server!\00"
@str.21 = [18 x i8] c"recv() timed out.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [5000000 x i8]
%5 = alloca [5000000 x i8]
%6 = tail call i32 @read_cli(i32 %0, i8** %1)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %13
8: ; preds = %2
%9 = load i32, i32* @stderr
%10 = tail call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = trunc i32 %6 to i16
%15 = load i32, i32* @PF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %23
19: ; preds = %13
%20 = tail call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = tail call i32 @exit(i32 %21)
unreachable
23: ; preds = %13
%24 = tail call %struct.hostent* @gethostbyname(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
%25 = icmp eq %struct.hostent* %24, null
br i1 %25, label %26, label %30
26: ; preds = %23
%27 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %23
%31 = bitcast %struct.sockaddr_in* %3 to i8*
%32 = load i32, i32* @PF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%35 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i64 0, i32 1
%36 = load i64, i64* %35
%37 = inttoptr i64 %36 to i8*
%38 = getelementptr inbounds %struct.hostent, %struct.hostent* %24, i64 0, i32 0
%39 = load i32, i32* %38
%40 = call i32 @memcpy(i8* %31, i8* %37, i32 %39)
%41 = call i32 @htons(i16 zeroext %14)
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %41, i32* %42
%43 = load i32, i32* %34
%44 = call i8* @inet_ntoa(i32 %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.4, i64 0, i64 0), i8* %44)
%46 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%47 = call i64 @connect(i32 %17, %struct.sockaddr* %46, i32 12)
%48 = icmp slt i64 %47, 0
br i1 %48, label %49, label %53
49: ; preds = %30
%50 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32, i32* @EXIT_FAILURE
%52 = call i32 @exit(i32 %51)
unreachable
53: ; preds = %30
%54 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %4, i64 0, i64 0
%55 = call i32 @bzero(i8* %54, i32 5000000)
%56 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.13, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.14, i64 0, i64 0))
%57 = call i32 @fread(i8* %54, i32 1, i32 5000000, i32* %56)
%58 = icmp sgt i32 %57, 0
br i1 %58, label %59, label %67
59: ; preds = %53, %63
%60 = phi i32 [ %65, %63 ], [ %57, %53 ]
%61 = call i64 @send(i32 %17, i8* %54, i32 %60, i32 0)
%62 = icmp slt i64 %61, 0
br i1 %62, label %67, label %63
63: ; preds = %59
%64 = call i32 @bzero(i8* %54, i32 5000000)
%65 = call i32 @fread(i8* %54, i32 1, i32 5000000, i32* %56)
%66 = icmp sgt i32 %65, 0
br i1 %66, label %59, label %67
67: ; preds = %63, %59, %53
%68 = getelementptr inbounds [5000000 x i8], [5000000 x i8]* %5, i64 0, i64 0
%69 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.16, i64 0, i64 0))
%70 = icmp eq i32* %69, null
br i1 %70, label %71, label %73
71: ; preds = %67
%72 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.17, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.15, i64 0, i64 0))
br label %90
73: ; preds = %67
%74 = call i32 @bzero(i8* %68, i32 5000000)
br label %75
75: ; preds = %83, %73
%76 = call i32 @recv(i32 %17, i8* %68, i32 5000000, i32 0)
%77 = icmp sgt i32 %76, 0
br i1 %77, label %78, label %86
78: ; preds = %75
%79 = call i32 @fwrite(i8* %68, i32 1, i32 %76, i32* %69)
%80 = icmp slt i32 %79, %76
br i1 %80, label %81, label %83
81: ; preds = %78
%82 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.18, i64 0, i64 0))
br label %83
83: ; preds = %81, %78
%84 = call i32 @bzero(i8* %68, i32 5000000)
%85 = icmp eq i32 %76, 512
br i1 %85, label %75, label %90
86: ; preds = %75
%87 = icmp slt i32 %76, 0
br i1 %87, label %88, label %90
88: ; preds = %86
%89 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.21, i64 0, i64 0))
br label %90
90: ; preds = %83, %86, %88, %71
%91 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str, i64 0, i64 0))
%92 = call i32 @fclose(i32* %69)
%93 = call i32 @close(i32 %17)
%94 = load i32, i32* @EXIT_SUCCESS
ret i32 %94
}