#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 {
  char sin_zero;
  int /*<<< orphan*/ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int atoi(char *);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int connect(int, struct sockaddr *, int);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_pton(int /*<<< orphan*/, char *, int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int main(int argc, char *argv[]) {
  int sockfd;
  char *tmp;
  struct sockaddr_in remote_addr;
  if (argc != 4) {
    printf("Usage ./client <IP> <Port> <Filename>\n");
    exit(-1);
  }
  if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
    fprintf(stderr, "ERROR: Failed to obtain Socket Descriptor! (errno = %d)\n",
            errno);
    exit(1);
  }
  remote_addr.sin_family = AF_INET;
  remote_addr.sin_port = htons(atoi(argv[2]));
  inet_pton(AF_INET, argv[1], &remote_addr.sin_addr);
  bzero(&(remote_addr.sin_zero), 8);
  if (connect(sockfd, (struct sockaddr *)&remote_addr,
              sizeof(struct sockaddr)) == -1) {
    fprintf(stderr, "ERROR: Failed to connect to the host! (errno = %d)\n",
            errno);
    exit(1);
  } else
    printf("[TCP Client] Connected to server at port %d...ok!\n",
           atoi(argv[2]));
  char *fs_name = argv[3];
  char sdbuf[512];
  printf("[TCP Client] Sending %s to the Server... ", fs_name);
  FILE *fs = fopen(fs_name, "r");
  if (fs == NULL) {
    printf("ERROR: File %s not found.\n", fs_name);
    exit(1);
  }
  tmp = (char *)malloc(sizeof(char) * (strlen(fs_name) + 1));
  strcpy(tmp, fs_name);
  memset(sdbuf, '\0', 512);
  strcpy(sdbuf, tmp);
  if (send(sockfd, sdbuf, 512, 0) < 0) {
    fprintf(stderr, "ERROR: Failed to send fileName %s. (errno = %d)\n",
            fs_name, errno);
    exit(-1);
  }
  bzero(sdbuf, 512);
  int fs_block_sz;
  while ((fs_block_sz = fread(sdbuf, sizeof(char), 512, fs)) > 0) {
    if (send(sockfd, sdbuf, fs_block_sz, 0) < 0) {
      fprintf(stderr, "ERROR: Failed to send file %s. (errno = %d)\n", fs_name,
              errno);
      break;
    }
    bzero(sdbuf, 512);
  }
  printf("Ok File %s from Client was Sent! Size: %d\n", fs_name, fs_block_sz);
  close(sockfd);
  printf("[TCP Client] Closing connection!\n");
  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)
je     124b <main+0x3b>
lea    0xdc6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
mov    0x2d75(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    129a <main+0x8a>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
mov    0x2d48(%rip),%rax
mov    (%rax),%edx
lea    0xd9e(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d24(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    -0x30(%rbp),%rdx
add    $0x4,%rdx
call   10c0 <inet_pton@plt>
lea    -0x30(%rbp),%rdi
mov    $0x8,%esi
call   10f0 <bzero@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x4,%edx
call   1120 <connect@plt>
cmp    $0xffffffff,%eax
jne    132d <main+0x11d>
mov    0x2cce(%rip),%rax
mov    (%rax),%edi
mov    0x2cb5(%rip),%rax
mov    (%rax),%edx
lea    0xd44(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1100 <atoi@plt>
mov    %eax,%esi
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rsi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x38(%rbp),%rdi
lea    0xd7e(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x248(%rbp)
cmpq   $0x0,-0x248(%rbp)
jne    13a9 <main+0x199>
mov    -0x38(%rbp),%rsi
lea    0xd5b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x1,%edi
call   1110 <exit@plt>
mov    -0x38(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10d0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x240(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1090 <memset@plt>
lea    -0x240(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    1444 <main+0x234>
mov    0x2bbb(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    0x2b9e(%rip),%rax
mov    (%rax),%ecx
lea    0xcdb(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1110 <exit@plt>
lea    -0x240(%rbp),%rdi
mov    $0x200,%esi
call   10f0 <bzero@plt>
lea    -0x240(%rbp),%rdi
mov    -0x248(%rbp),%rcx
mov    $0x1,%esi
mov    $0x200,%edx
call   1040 <fread@plt>
mov    %eax,-0x24c(%rbp)
cmp    $0x0,%eax
jle    14e1 <main+0x2d1>
mov    -0x14(%rbp),%edi
lea    -0x240(%rbp),%rsi
mov    -0x24c(%rbp),%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmp    $0x0,%rax
jge    14cb <main+0x2bb>
mov    0x2b2f(%rip),%rax
mov    (%rax),%edi
mov    -0x38(%rbp),%rdx
mov    0x2b12(%rip),%rax
mov    (%rax),%ecx
lea    0xc80(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
jmp    14e1 <main+0x2d1>
lea    -0x240(%rbp),%rdi
mov    $0x200,%esi
call   10f0 <bzero@plt>
jmp    1455 <main+0x245>
mov    -0x38(%rbp),%rsi
mov    -0x24c(%rbp),%edx
lea    0xc7a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   10a0 <close@plt>
lea    0xc8f(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x250,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
cmp    $0x4,%edi
jne    142a <main+0x20a>
mov    %rsi,%rbx
mov    0x2da6(%rip),%rbp
mov    0x0(%rbp),%edi
mov    0x2d84(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
cmp    $0xffffffff,%eax
je     1440 <main+0x220>
mov    %eax,%r15d
mov    0x0(%rbp),%eax
mov    %eax,0xc(%rsp)
mov    0x10(%rbx),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
mov    0x0(%rbp),%edi
mov    0x8(%rbx),%rsi
lea    0x4(%rsp),%rdx
call   10d0 <inet_pton@plt>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x8,%esi
call   1100 <bzero@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1130 <connect@plt>
cmp    $0xffffffff,%eax
je     145b <main+0x23b>
mov    0x10(%rbx),%rdi
call   1110 <atoi@plt>
lea    0xda7(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    0x18(%rbx),%r14
lea    0xdc6(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
lea    0xddf(%rip),%rsi
mov    %r14,%rdi
call   10f0 <fopen@plt>
test   %rax,%rax
je     1485 <main+0x265>
mov    %rax,%r12
mov    %r14,%rdi
call   1060 <strlen@plt>
lea    0x1(%rax),%edi
call   10e0 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   10a0 <memset@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    %r15d,%edi
mov    %rbp,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
test   %rax,%rax
js     14a0 <main+0x280>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x200,%esi
call   1100 <bzero@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    13f1 <main+0x1d1>
lea    0x10(%rsp),%rbx
nopl   0x0(%rax)
mov    %r15d,%edi
mov    %rbx,%rsi
mov    %ebp,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
test   %rax,%rax
js     13ce <main+0x1ae>
mov    %rbx,%rdi
mov    $0x200,%esi
call   1100 <bzero@plt>
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x200,%edx
mov    %r12,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
test   %eax,%eax
jg     1390 <main+0x170>
jmp    13f1 <main+0x1d1>
mov    0x2c03(%rip),%rax
mov    (%rax),%edi
mov    0x2bea(%rip),%rax
mov    (%rax),%ecx
lea    0xd31(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
lea    0xd4d(%rip),%rdi
mov    %r14,%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1090 <printf@plt>
mov    %r15d,%edi
call   10b0 <close@plt>
lea    0xd5d(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd60(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>
mov    0x2b91(%rip),%rax
mov    (%rax),%edi
mov    0x2b78(%rip),%rax
mov    (%rax),%edx
lea    0xba7(%rip),%rsi
jmp    1474 <main+0x254>
mov    0x2b76(%rip),%rax
mov    (%rax),%edi
mov    0x2b5d(%rip),%rax
mov    (%rax),%edx
lea    0xbc5(%rip),%rsi
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xc40(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2b31(%rip),%rax
mov    (%rax),%edi
mov    0x2b18(%rip),%rax
mov    (%rax),%ecx
lea    0xc2e(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10c0 <fprintf@plt>
mov    $0xffffffff,%edi
call   1120 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i8, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@.str = [39 x i8] c"Usage ./client <IP> <Port> <Filename>\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [57 x i8] c"ERROR: Failed to obtain Socket Descriptor! (errno = %d)\0A\00"
@errno = global i32 0
@.str.2 = [52 x i8] c"ERROR: Failed to connect to the host! (errno = %d)\0A\00"
@.str.3 = [51 x i8] c"[TCP Client] Connected to server at port %d...ok!\0A\00"
@.str.4 = [42 x i8] c"[TCP Client] Sending %s to the Server... \00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [27 x i8] c"ERROR: File %s not found.\0A\00"
@.str.7 = [49 x i8] c"ERROR: Failed to send fileName %s. (errno = %d)\0A\00"
@.str.8 = [45 x i8] c"ERROR: Failed to send file %s. (errno = %d)\0A\00"
@.str.9 = [43 x i8] c"Ok File %s from Client was Sent! Size: %d\0A\00"
@.str.10 = [34 x i8] c"[TCP Client] Closing connection!\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.sockaddr_in
%9 = alloca i8*
%10 = alloca [512 x i8]
%11 = alloca i32*
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 4
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %2
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %28
23: ; preds = %18
%24 = load i32, i32* @stderr
%25 = load i32, i32* @errno
%26 = call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %18
%29 = load i32, i32* @AF_INET
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 3
store i32 %29, i32* %30
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 2
%33 = load i8*, i8** %32
%34 = call i32 @atoi(i8* %33)
%35 = call i32 @htons(i32 %34)
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %35, i32* %36
%37 = load i32, i32* @AF_INET
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%42 = call i32 @inet_pton(i32 %37, i8* %40, i32* %41)
%43 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%44 = call i32 @bzero(i8* %43, i32 8)
%45 = load i32, i32* %6
%46 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%47 = call i32 @connect(i32 %45, %struct.sockaddr* %46, i32 4)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %54
49: ; preds = %28
%50 = load i32, i32* @stderr
%51 = load i32, i32* @errno
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = call i32 @exit(i32 1)
unreachable
54: ; preds = %28
%55 = load i8**, i8*** %5
%56 = getelementptr inbounds i8*, i8** %55, i64 2
%57 = load i8*, i8** %56
%58 = call i32 @atoi(i8* %57)
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %58)
br label %60
60: ; preds = %54
%61 = load i8**, i8*** %5
%62 = getelementptr inbounds i8*, i8** %61, i64 3
%63 = load i8*, i8** %62
store i8* %63, i8** %9
%64 = load i8*, i8** %9
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %64)
%66 = load i8*, i8** %9
%67 = call i32* @fopen(i8* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %67, i32** %11
%68 = load i32*, i32** %11
%69 = icmp eq i32* %68, null
br i1 %69, label %70, label %74
70: ; preds = %60
%71 = load i8*, i8** %9
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %71)
%73 = call i32 @exit(i32 1)
unreachable
74: ; preds = %60
%75 = load i8*, i8** %9
%76 = call i32 @strlen(i8* %75)
%77 = add nsw i32 %76, 1
%78 = sext i32 %77 to i64
%79 = mul i64 1, %78
%80 = trunc i64 %79 to i32
%81 = call i64 @malloc(i32 %80)
%82 = inttoptr i64 %81 to i8*
store i8* %82, i8** %7
%83 = load i8*, i8** %7
%84 = load i8*, i8** %9
%85 = call i32 @strcpy(i8* %83, i8* %84)
%86 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%87 = call i32 @memset(i8* %86, i8 signext 0, i32 512)
%88 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%89 = load i8*, i8** %7
%90 = call i32 @strcpy(i8* %88, i8* %89)
%91 = load i32, i32* %6
%92 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%93 = call i64 @send(i32 %91, i8* %92, i32 512, i32 0)
%94 = icmp slt i64 %93, 0
br i1 %94, label %95, label %101
95: ; preds = %74
%96 = load i32, i32* @stderr
%97 = load i8*, i8** %9
%98 = load i32, i32* @errno
%99 = call i32 (i32, i8*, ...) @fprintf(i32 %96, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i8* %97, i32 %98)
%100 = call i32 @exit(i32 -1)
unreachable
101: ; preds = %74
%102 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%103 = call i32 @bzero(i8* %102, i32 512)
br label %104
104: ; preds = %120, %101
%105 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%106 = load i32*, i32** %11
%107 = call i32 @fread(i8* %105, i32 1, i32 512, i32* %106)
store i32 %107, i32* %12
%108 = icmp sgt i32 %107, 0
br i1 %108, label %109, label %123
109: ; preds = %104
%110 = load i32, i32* %6
%111 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%112 = load i32, i32* %12
%113 = call i64 @send(i32 %110, i8* %111, i32 %112, i32 0)
%114 = icmp slt i64 %113, 0
br i1 %114, label %115, label %120
115: ; preds = %109
%116 = load i32, i32* @stderr
%117 = load i8*, i8** %9
%118 = load i32, i32* @errno
%119 = call i32 (i32, i8*, ...) @fprintf(i32 %116, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i8* %117, i32 %118)
br label %123
120: ; preds = %109
%121 = getelementptr inbounds [512 x i8], [512 x i8]* %10, i64 0, i64 0
%122 = call i32 @bzero(i8* %121, i32 512)
br label %104
123: ; preds = %115, %104
%124 = load i8*, i8** %9
%125 = load i32, i32* %12
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i8* %124, i32 %125)
%127 = load i32, i32* %6
%128 = call i32 @close(i32 %127)
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i8, i32, i32, i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str.1 = [57 x i8] c"ERROR: Failed to obtain Socket Descriptor! (errno = %d)\0A\00"
@errno = global i32 0
@.str.2 = [52 x i8] c"ERROR: Failed to connect to the host! (errno = %d)\0A\00"
@.str.3 = [51 x i8] c"[TCP Client] Connected to server at port %d...ok!\0A\00"
@.str.4 = [42 x i8] c"[TCP Client] Sending %s to the Server... \00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [27 x i8] c"ERROR: File %s not found.\0A\00"
@.str.7 = [49 x i8] c"ERROR: Failed to send fileName %s. (errno = %d)\0A\00"
@.str.8 = [45 x i8] c"ERROR: Failed to send file %s. (errno = %d)\0A\00"
@.str.9 = [43 x i8] c"Ok File %s from Client was Sent! Size: %d\0A\00"
@str = [33 x i8] c"[TCP Client] Closing connection!\00"
@str.11 = [38 x i8] c"Usage ./client <IP> <Port> <Filename>\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [512 x i8]
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%6 = icmp eq i32 %0, 4
br i1 %6, label %10, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.11, i64 0, i64 0))
%9 = tail call i32 @exit(i32 -1)
unreachable
10: ; preds = %2
%11 = load i32, i32* @AF_INET
%12 = load i32, i32* @SOCK_STREAM
%13 = tail call i32 @socket(i32 %11, i32 %12, i32 0)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = load i32, i32* @errno
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %10
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 3
store i32 %21, i32* %22
%23 = getelementptr inbounds i8*, i8** %1, i64 2
%24 = load i8*, i8** %23
%25 = tail call i32 @atoi(i8* %24)
%26 = tail call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %26, i32* %27
%28 = load i32, i32* @AF_INET
%29 = getelementptr inbounds i8*, i8** %1, i64 1
%30 = load i8*, i8** %29
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
%32 = call i32 @inet_pton(i32 %28, i8* %30, i32* %31)
%33 = call i32 @bzero(i8* %5, i32 8)
%34 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%35 = call i32 @connect(i32 %13, %struct.sockaddr* %34, i32 4)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %42
37: ; preds = %20
%38 = load i32, i32* @stderr
%39 = load i32, i32* @errno
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.2, i64 0, i64 0), i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %20
%43 = load i8*, i8** %23
%44 = call i32 @atoi(i8* %43)
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds i8*, i8** %1, i64 3
%47 = load i8*, i8** %46
%48 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* %47)
%50 = call i32* @fopen(i8* %47, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%51 = icmp eq i32* %50, null
br i1 %51, label %52, label %55
52: ; preds = %42
%53 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.6, i64 0, i64 0), i8* %47)
%54 = call i32 @exit(i32 1)
unreachable
55: ; preds = %42
%56 = call i32 @strlen(i8* %47)
%57 = add nsw i32 %56, 1
%58 = call i64 @malloc(i32 %57)
%59 = inttoptr i64 %58 to i8*
%60 = call i32 @strcpy(i8* %59, i8* %47)
%61 = call i32 @memset(i8* %48, i8 signext 0, i32 512)
%62 = call i32 @strcpy(i8* %48, i8* %59)
%63 = call i64 @send(i32 %13, i8* %48, i32 512, i32 0)
%64 = icmp slt i64 %63, 0
br i1 %64, label %65, label %70
65: ; preds = %55
%66 = load i32, i32* @stderr
%67 = load i32, i32* @errno
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %66, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0), i8* %47, i32 %67)
%69 = call i32 @exit(i32 -1)
unreachable
70: ; preds = %55
%71 = call i32 @bzero(i8* %48, i32 512)
%72 = call i32 @fread(i8* %48, i32 1, i32 512, i32* %50)
%73 = icmp sgt i32 %72, 0
br i1 %73, label %74, label %86
74: ; preds = %70, %82
%75 = phi i32 [ %84, %82 ], [ %72, %70 ]
%76 = call i64 @send(i32 %13, i8* %48, i32 %75, i32 0)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %82
78: ; preds = %74
%79 = load i32, i32* @stderr
%80 = load i32, i32* @errno
%81 = call i32 (i32, i8*, ...) @fprintf(i32 %79, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.8, i64 0, i64 0), i8* %47, i32 %80)
br label %86
82: ; preds = %74
%83 = call i32 @bzero(i8* %48, i32 512)
%84 = call i32 @fread(i8* %48, i32 1, i32 512, i32* %50)
%85 = icmp sgt i32 %84, 0
br i1 %85, label %74, label %86
86: ; preds = %82, %70, %78
%87 = phi i32 [ %75, %78 ], [ %72, %70 ], [ %84, %82 ]
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.9, i64 0, i64 0), i8* %47, i32 %87)
%89 = call i32 @close(i32 %13)
%90 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @str, i64 0, i64 0))
ret i32 0
}