#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 {
  unsigned long st_size;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  scalar_t__ h_addr;
};
typedef unsigned char file_size;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ CLOSE(int);
scalar_t__ CONNECT(int, struct sockaddr *, int);
int SEND(int, unsigned char *, int, int /*<<< orphan*/);
int SOCKET(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bcopy(void *, void *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(unsigned char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(unsigned char *, int, int, int /*<<< orphan*/ *);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ init_tcpudp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, char *argv[]) {
  int sock;
  int r_val;
  int w_val;
  struct sockaddr_in sin_addr;
  char server_name[260];
  char file_name[260];
  char port[8] = "8000";
  unsigned char buf[1000];
  struct hostent *hp;
  FILE *send_file;
  if (argc == 4) {
    strcpy(server_name, argv[1]);
    strcpy(port, argv[2]);
    strcpy(file_name, argv[3]);
  } else {
    fprintf(stderr, "Incorrect command line format.\n");
    fprintf(stderr,
            "USAGE: ftpc remote_IP remote_port local_file_to_transfer\n");
    exit(1);
  }
  init_tcpudp("CLIENT");
  unsigned long file_size = -1, file_left = -1;
  struct stat file_stat;
  if (stat(file_name, &file_stat) >= 0)
    file_size = file_stat.st_size;
  fprintf(stdout, "Size of file is %lu\n", file_size);
  send_file = fopen(file_name, "rb");
  if ((sock = SOCKET(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("error openting datagram socket");
    exit(1);
  }
  hp = gethostbyname(server_name);
  if (hp == 0) {
    fprintf(stderr, "%s: unknown host\n", server_name);
    exit(2);
  }
  bcopy((void *)hp->h_addr, (void *)&sin_addr.sin_addr, hp->h_length);
  sin_addr.sin_family = AF_INET;
  sin_addr.sin_port = htons(atoi(port));
  if (CONNECT(sock, (struct sockaddr *)&sin_addr, sizeof(struct sockaddr_in)) <
      0) {
    CLOSE(sock);
    perror("error connecting stream socket");
    exit(1);
  }
  buf[0] = (file_size >> 24) & 0xff;
  buf[1] = (file_size >> 16) & 0xff;
  buf[2] = (file_size >> 8) & 0xff;
  buf[3] = (file_size)&0xff;
  w_val = SEND(sock, buf, 4, 0);
  if (w_val < 0) {
    perror("error writing on stream socket");
    exit(1);
  }
  bzero(buf, 1000);
  strcpy((char *)buf, file_name);
  w_val = SEND(sock, buf, 20, 0);
  if (w_val < 0) {
    perror("error writing on stream socket");
    exit(1);
  }
  file_left = file_size;
  while (file_left) {
    r_val = fread(buf, sizeof(unsigned char), 1000, send_file);
    if (r_val < 0) {
      perror("error reading file");
      exit(1);
    }
    if (r_val > file_left) {
      r_val = file_left;
    }
    w_val = SEND(sock, buf, 1000, 0);
    if (w_val < 0) {
      perror("error writing on stream socket");
      exit(1);
    }
    file_left = file_left - r_val;
  }
  printf("Client sends: %lu bytes\n", file_size);
  CLOSE(sock);
  fclose(send_file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x660,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xdb0(%rip),%rax
mov    %rax,-0x248(%rbp)
cmpl   $0x4,-0x8(%rbp)
jne    12a2 <main+0x72>
lea    -0x130(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x248(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1030 <strcpy@plt>
lea    -0x240(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
call   1030 <strcpy@plt>
jmp    12da <main+0xaa>
mov    0x2d2f(%rip),%rax
mov    (%rax),%edi
lea    0xd56(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    0x2d18(%rip),%rax
mov    (%rax),%edi
lea    0xd5f(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    0xd81(%rip),%rdi
call   1040 <init_tcpudp@plt>
movq   $0xffffffffffffffff,-0x648(%rbp)
ff ff ff ff
movq   $0xffffffffffffffff,-0x650(%rbp)
ff ff ff ff
lea    -0x240(%rbp),%rdi
lea    -0x658(%rbp),%rsi
call   10e0 <stat@plt>
cmp    $0x0,%rax
jl     1327 <main+0xf7>
mov    -0x658(%rbp),%rax
mov    %rax,-0x648(%rbp)
mov    0x2c9a(%rip),%rax
mov    (%rax),%edi
mov    -0x648(%rbp),%rdx
lea    0xd2b(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
lea    -0x240(%rbp),%rdi
lea    0xd2b(%rip),%rsi
call   1110 <fopen@plt>
mov    %rax,-0x640(%rbp)
mov    0x2c82(%rip),%rax
mov    (%rax),%edi
mov    0x2c61(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <SOCKET@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    139a <main+0x16a>
lea    0xcf6(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    -0x130(%rbp),%rdi
call   10c0 <gethostbyname@plt>
mov    %rax,-0x638(%rbp)
cmpq   $0x0,-0x638(%rbp)
jne    13e3 <main+0x1b3>
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rdx
lea    0xcce(%rip),%rsi
mov    $0x0,%al
call   10d0 <fprintf@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
mov    -0x638(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    -0x638(%rbp),%rax
mov    (%rax),%edx
call   1100 <bcopy@plt>
mov    0x2bdd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x248(%rbp),%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1090 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1050 <CONNECT@plt>
cmp    $0x0,%rax
jge    145f <main+0x22f>
mov    -0x14(%rbp),%edi
call   10b0 <CLOSE@plt>
lea    0xc62(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x648(%rbp),%rax
shr    $0x18,%rax
and    $0xff,%rax
mov    %al,-0x630(%rbp)
mov    -0x648(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    %al,-0x62f(%rbp)
mov    -0x648(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    %al,-0x62e(%rbp)
mov    -0x648(%rbp),%rax
and    $0xff,%rax
mov    %al,-0x62d(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x630(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   10f0 <SEND@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14f0 <main+0x2c0>
lea    0xbf0(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    -0x630(%rbp),%rdi
mov    $0x3e8,%esi
call   1130 <bzero@plt>
lea    -0x630(%rbp),%rdi
lea    -0x240(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x630(%rbp),%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
call   10f0 <SEND@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    154d <main+0x31d>
lea    0xb93(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x648(%rbp),%rax
mov    %rax,-0x650(%rbp)
cmpq   $0x0,-0x650(%rbp)
je     1617 <main+0x3e7>
lea    -0x630(%rbp),%rdi
mov    -0x640(%rbp),%rcx
mov    $0x1,%esi
mov    $0x3e8,%edx
call   1060 <fread@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    15a9 <main+0x379>
lea    0xb56(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movslq -0x18(%rbp),%rax
cmp    -0x650(%rbp),%rax
jbe    15c4 <main+0x394>
mov    -0x650(%rbp),%rax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x630(%rbp),%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   10f0 <SEND@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    15fd <main+0x3cd>
lea    0xae3(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x650(%rbp),%rax
movslq -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x650(%rbp)
jmp    155b <main+0x32b>
mov    -0x648(%rbp),%rsi
lea    0xade(%rip),%rdi
call   10a0 <printf@plt>
mov    -0x14(%rbp),%edi
call   10b0 <CLOSE@plt>
mov    -0x640(%rbp),%rdi
call   1080 <fclose@plt>
xor    %eax,%eax
add    $0x660,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x628,%rsp
movq   $0x30303038,(%rsp)
30
cmp    $0x4,%edi
jne    1464 <main+0x234>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0x20(%rsp),%rdi
call   1030 <strcpy@plt>
mov    0x10(%rbx),%rsi
mov    %rsp,%rdi
call   1030 <strcpy@plt>
mov    0x18(%rbx),%rsi
lea    0x130(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
lea    0xdd0(%rip),%rdi
call   1040 <init_tcpudp@plt>
lea    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   10e0 <stat@plt>
mov    $0xffffffffffffffff,%r14
test   %rax,%rax
js     12ad <main+0x7d>
mov    0x18(%rsp),%r14
mov    0x2d14(%rip),%rax
mov    (%rax),%edi
lea    0xda4(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
lea    0xda8(%rip),%rsi
mov    %rbx,%rdi
call   1110 <fopen@plt>
mov    %rax,%r15
mov    0x2d08(%rip),%rbx
mov    (%rbx),%edi
mov    0x2ce7(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1070 <SOCKET@plt>
test   %eax,%eax
js     1495 <main+0x265>
mov    %eax,%r12d
lea    0x20(%rsp),%rdi
call   10c0 <gethostbyname@plt>
test   %rax,%rax
je     149e <main+0x26e>
mov    0x8(%rax),%rsi
lea    0x10(%rsp),%rdi
mov    (%rax),%edx
call   1100 <memmove@plt>
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    %rsp,%rdi
call   1140 <atoi@plt>
mov    %eax,%edi
call   1090 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   1050 <CONNECT@plt>
test   %rax,%rax
js     14c4 <main+0x294>
mov    %r14d,%eax
bswap  %eax
mov    %eax,0x240(%rsp)
lea    0x240(%rsp),%rsi
mov    %r12d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   10f0 <SEND@plt>
test   %eax,%eax
js     1445 <main+0x215>
lea    0x240(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1130 <bzero@plt>
lea    0x130(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
xor    %ecx,%ecx
call   10f0 <SEND@plt>
test   %eax,%eax
js     1445 <main+0x215>
test   %r14,%r14
je     1412 <main+0x1e2>
lea    0x240(%rsp),%r13
mov    %r14,%rbx
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x3e8,%edx
mov    %r15,%rcx
call   1060 <fread@plt>
test   %eax,%eax
js     144e <main+0x21e>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   10f0 <SEND@plt>
test   %eax,%eax
js     1445 <main+0x215>
mov    %ebp,%eax
cmp    %rax,%rbx
mov    %ebx,%eax
cmovae %ebp,%eax
cltq
sub    %rax,%rbx
jne    13d0 <main+0x1a0>
lea    0xce2(%rip),%rdi
mov    %r14,%rsi
call   10a0 <printf@plt>
mov    %r12d,%edi
call   10b0 <CLOSE@plt>
mov    %r15,%rdi
call   1080 <fclose@plt>
xor    %eax,%eax
add    $0x628,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc7d(%rip),%rdi
jmp    1455 <main+0x225>
lea    0xc93(%rip),%rdi
call   1120 <perror@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    0x2b6d(%rip),%rbx
mov    (%rbx),%edi
lea    0xb8c(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xb9c(%rip),%rsi
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
lea    0xbdd(%rip),%rdi
jmp    1455 <main+0x225>
mov    0x2b33(%rip),%rax
mov    (%rax),%edi
lea    0xbea(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10d0 <fprintf@plt>
mov    $0x2,%edi
call   1150 <exit@plt>
mov    %r12d,%edi
call   10b0 <CLOSE@plt>
lea    0xbd7(%rip),%rdi
jmp    1455 <main+0x225>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.hostent = type { i32, i64 }
%struct.stat = type { i64 }
%struct.sockaddr = type { i32 }
@__const.main.port = [8 x i8] c"8000\00\00\00\00"
@stderr = global i32 0
@.str = [32 x i8] c"Incorrect command line format.\0A\00"
@.str.1 = [58 x i8] c"USAGE: ftpc remote_IP remote_port local_file_to_transfer\0A\00"
@.str.2 = [7 x i8] c"CLIENT\00"
@stdout = global i32 0
@.str.3 = [21 x i8] c"Size of file is %lu\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [31 x i8] c"error openting datagram socket\00"
@.str.6 = [18 x i8] c"%s: unknown host\0A\00"
@.str.7 = [31 x i8] c"error connecting stream socket\00"
@.str.8 = [31 x i8] c"error writing on stream socket\00"
@.str.9 = [19 x i8] c"error reading file\00"
@.str.10 = [25 x i8] c"Client sends: %lu bytes\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 [260 x i8]
%11 = alloca [260 x i8]
%12 = alloca [8 x i8]
%13 = alloca [1000 x i8]
%14 = alloca %struct.hostent*
%15 = alloca i32*
%16 = alloca i64
%17 = alloca i64
%18 = alloca %struct.stat
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = bitcast [8 x i8]* %12 to i8*
%20 = load i32, i32* %4
%21 = icmp eq i32 %20, 4
br i1 %21, label %22, label %38
22: ; preds = %2
%23 = getelementptr inbounds [260 x i8], [260 x i8]* %10, i64 0, i64 0
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 @strcpy(i8* %23, i8* %26)
%28 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @strcpy(i8* %28, i8* %31)
%33 = getelementptr inbounds [260 x i8], [260 x i8]* %11, i64 0, i64 0
%34 = load i8**, i8*** %5
%35 = getelementptr inbounds i8*, i8** %34, i64 3
%36 = load i8*, i8** %35
%37 = call i32 @strcpy(i8* %33, i8* %36)
br label %44
38: ; preds = %2
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %22
%45 = call i32 @init_tcpudp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
store i64 -1, i64* %16
store i64 -1, i64* %17
%46 = getelementptr inbounds [260 x i8], [260 x i8]* %11, i64 0, i64 0
%47 = call i64 @stat(i8* %46, %struct.stat* %18)
%48 = icmp sge i64 %47, 0
br i1 %48, label %49, label %52
49: ; preds = %44
%50 = getelementptr inbounds %struct.stat, %struct.stat* %18, i32 0, i32 0
%51 = load i64, i64* %50
store i64 %51, i64* %16
br label %52
52: ; preds = %49, %44
%53 = load i32, i32* @stdout
%54 = load i64, i64* %16
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %54)
%56 = getelementptr inbounds [260 x i8], [260 x i8]* %11, i64 0, i64 0
%57 = call i32* @fopen(i8* %56, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %57, i32** %15
%58 = load i32, i32* @AF_INET
%59 = load i32, i32* @SOCK_STREAM
%60 = call i32 @SOCKET(i32 %58, i32 %59, i32 0)
store i32 %60, i32* %6
%61 = icmp slt i32 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %52
%63 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%64 = call i32 @exit(i32 1)
unreachable
65: ; preds = %52
%66 = getelementptr inbounds [260 x i8], [260 x i8]* %10, i64 0, i64 0
%67 = call %struct.hostent* @gethostbyname(i8* %66)
store %struct.hostent* %67, %struct.hostent** %14
%68 = load %struct.hostent*, %struct.hostent** %14
%69 = icmp eq %struct.hostent* %68, null
br i1 %69, label %70, label %75
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = getelementptr inbounds [260 x i8], [260 x i8]* %10, i64 0, i64 0
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %72)
%74 = call i32 @exit(i32 2)
unreachable
75: ; preds = %65
%76 = load %struct.hostent*, %struct.hostent** %14
%77 = getelementptr inbounds %struct.hostent, %struct.hostent* %76, i32 0, i32 1
%78 = load i64, i64* %77
%79 = inttoptr i64 %78 to i8*
%80 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
%81 = bitcast i32* %80 to i8*
%82 = load %struct.hostent*, %struct.hostent** %14
%83 = getelementptr inbounds %struct.hostent, %struct.hostent* %82, i32 0, i32 0
%84 = load i32, i32* %83
%85 = call i32 @bcopy(i8* %79, i8* %81, i32 %84)
%86 = load i32, i32* @AF_INET
%87 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
store i32 %86, i32* %87
%88 = getelementptr inbounds [8 x i8], [8 x i8]* %12, i64 0, i64 0
%89 = call i32 @atoi(i8* %88)
%90 = call i32 @htons(i32 %89)
%91 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %90, i32* %91
%92 = load i32, i32* %6
%93 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%94 = call i64 @CONNECT(i32 %92, %struct.sockaddr* %93, i32 12)
%95 = icmp slt i64 %94, 0
br i1 %95, label %96, label %101
96: ; preds = %75
%97 = load i32, i32* %6
%98 = call i32 @CLOSE(i32 %97)
%99 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %75
%102 = load i64, i64* %16
%103 = lshr i64 %102, 24
%104 = and i64 %103, 255
%105 = trunc i64 %104 to i8
%106 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
store i8 %105, i8* %106
%107 = load i64, i64* %16
%108 = lshr i64 %107, 16
%109 = and i64 %108, 255
%110 = trunc i64 %109 to i8
%111 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 1
store i8 %110, i8* %111
%112 = load i64, i64* %16
%113 = lshr i64 %112, 8
%114 = and i64 %113, 255
%115 = trunc i64 %114 to i8
%116 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 2
store i8 %115, i8* %116
%117 = load i64, i64* %16
%118 = and i64 %117, 255
%119 = trunc i64 %118 to i8
%120 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 3
store i8 %119, i8* %120
%121 = load i32, i32* %6
%122 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%123 = call i32 @SEND(i32 %121, i8* %122, i32 4, i32 0)
store i32 %123, i32* %8
%124 = load i32, i32* %8
%125 = icmp slt i32 %124, 0
br i1 %125, label %126, label %129
126: ; preds = %101
%127 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%128 = call i32 @exit(i32 1)
unreachable
129: ; preds = %101
%130 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%131 = call i32 @bzero(i8* %130, i32 1000)
%132 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%133 = getelementptr inbounds [260 x i8], [260 x i8]* %11, i64 0, i64 0
%134 = call i32 @strcpy(i8* %132, i8* %133)
%135 = load i32, i32* %6
%136 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%137 = call i32 @SEND(i32 %135, i8* %136, i32 20, i32 0)
store i32 %137, i32* %8
%138 = load i32, i32* %8
%139 = icmp slt i32 %138, 0
br i1 %139, label %140, label %143
140: ; preds = %129
%141 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%142 = call i32 @exit(i32 1)
unreachable
143: ; preds = %129
%144 = load i64, i64* %16
store i64 %144, i64* %17
br label %145
145: ; preds = %174, %143
%146 = load i64, i64* %17
%147 = icmp ne i64 %146, 0
br i1 %147, label %148, label %179
148: ; preds = %145
%149 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%150 = load i32*, i32** %15
%151 = call i32 @fread(i8* %149, i32 1, i32 1000, i32* %150)
store i32 %151, i32* %7
%152 = load i32, i32* %7
%153 = icmp slt i32 %152, 0
br i1 %153, label %154, label %157
154: ; preds = %148
%155 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%156 = call i32 @exit(i32 1)
unreachable
157: ; preds = %148
%158 = load i32, i32* %7
%159 = sext i32 %158 to i64
%160 = load i64, i64* %17
%161 = icmp ugt i64 %159, %160
br i1 %161, label %162, label %165
162: ; preds = %157
%163 = load i64, i64* %17
%164 = trunc i64 %163 to i32
store i32 %164, i32* %7
br label %165
165: ; preds = %162, %157
%166 = load i32, i32* %6
%167 = getelementptr inbounds [1000 x i8], [1000 x i8]* %13, i64 0, i64 0
%168 = call i32 @SEND(i32 %166, i8* %167, i32 1000, i32 0)
store i32 %168, i32* %8
%169 = load i32, i32* %8
%170 = icmp slt i32 %169, 0
br i1 %170, label %171, label %174
171: ; preds = %165
%172 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%173 = call i32 @exit(i32 1)
unreachable
174: ; preds = %165
%175 = load i64, i64* %17
%176 = load i32, i32* %7
%177 = sext i32 %176 to i64
%178 = sub i64 %175, %177
store i64 %178, i64* %17
br label %145
179: ; preds = %145
%180 = load i64, i64* %16
%181 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i64 %180)
%182 = load i32, i32* %6
%183 = call i32 @CLOSE(i32 %182)
%184 = load i32*, i32** %15
%185 = call i32 @fclose(i32* %184)
ret i32 0
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, i32 }
%struct.stat = type { i64 }
%struct.hostent = type { i32, i64 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Incorrect command line format.\0A\00"
@.str.1 = [58 x i8] c"USAGE: ftpc remote_IP remote_port local_file_to_transfer\0A\00"
@.str.2 = [7 x i8] c"CLIENT\00"
@stdout = global i32 0
@.str.3 = [21 x i8] c"Size of file is %lu\0A\00"
@.str.4 = [3 x i8] c"rb\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.5 = [31 x i8] c"error openting datagram socket\00"
@.str.6 = [18 x i8] c"%s: unknown host\0A\00"
@.str.7 = [31 x i8] c"error connecting stream socket\00"
@.str.8 = [31 x i8] c"error writing on stream socket\00"
@.str.9 = [19 x i8] c"error reading file\00"
@.str.10 = [25 x i8] c"Client sends: %lu bytes\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca [260 x i8]
%5 = alloca [260 x i8]
%6 = alloca i64
%7 = alloca [1000 x i8]
%8 = alloca %struct.stat
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = getelementptr inbounds [260 x i8], [260 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [260 x i8], [260 x i8]* %5, i64 0, i64 0
%12 = bitcast i64* %6 to i8*
store i64 808464440, i64* %6
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%14 = icmp eq i32 %0, 4
br i1 %14, label %15, label %39
15: ; preds = %2
%16 = getelementptr inbounds i8*, i8** %1, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strcpy(i8* %10, i8* %17)
%19 = getelementptr inbounds i8*, i8** %1, i64 2
%20 = load i8*, i8** %19
%21 = call i32 @strcpy(i8* %12, i8* %20)
%22 = getelementptr inbounds i8*, i8** %1, i64 3
%23 = load i8*, i8** %22
%24 = call i32 @strcpy(i8* %11, i8* %23)
%25 = call i32 @init_tcpudp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%26 = bitcast %struct.stat* %8 to i8*
%27 = call i64 @stat(i8* %11, %struct.stat* %8)
%28 = icmp sgt i64 %27, -1
%29 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%30 = load i64, i64* %29
%31 = select i1 %28, i64 %30, i64 -1
%32 = load i32, i32* @stdout
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i64 %31)
%34 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%35 = load i32, i32* @AF_INET
%36 = load i32, i32* @SOCK_STREAM
%37 = call i32 @SOCKET(i32 %35, i32 %36, i32 0)
%38 = icmp slt i32 %37, 0
br i1 %38, label %45, label %48
39: ; preds = %2
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%42 = load i32, i32* @stderr
%43 = tail call i32 (i32, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.1, i64 0, i64 0))
%44 = tail call i32 @exit(i32 1)
unreachable
45: ; preds = %15
%46 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.5, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %15
%49 = call %struct.hostent* @gethostbyname(i8* %10)
%50 = icmp eq %struct.hostent* %49, null
br i1 %50, label %51, label %55
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%54 = call i32 @exit(i32 2)
unreachable
55: ; preds = %48
%56 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i64 0, i32 1
%57 = load i64, i64* %56
%58 = inttoptr i64 %57 to i8*
%59 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
%60 = bitcast i32* %59 to i8*
%61 = getelementptr inbounds %struct.hostent, %struct.hostent* %49, i64 0, i32 0
%62 = load i32, i32* %61
%63 = load i32, i32* @AF_INET
%64 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %63, i32* %64
%65 = call i32 @atoi(i8* %12)
%66 = call i32 @htons(i32 %65)
%67 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
store i32 %66, i32* %67
%68 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%69 = call i64 @CONNECT(i32 %37, %struct.sockaddr* %68, i32 12)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %75
71: ; preds = %55
%72 = call i32 @CLOSE(i32 %37)
%73 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%74 = call i32 @exit(i32 1)
unreachable
75: ; preds = %55
%76 = lshr i64 %31, 24
%77 = trunc i64 %76 to i8
store i8 %77, i8* %13
%78 = lshr i64 %31, 16
%79 = trunc i64 %78 to i8
%80 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 1
store i8 %79, i8* %80
%81 = lshr i64 %31, 8
%82 = trunc i64 %81 to i8
%83 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 2
store i8 %82, i8* %83
%84 = trunc i64 %31 to i8
%85 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 3
store i8 %84, i8* %85
%86 = call i32 @SEND(i32 %37, i8* %13, i32 4, i32 0)
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %75
%89 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %75
%92 = call i32 @bzero(i8* %13, i32 1000)
%93 = call i32 @strcpy(i8* %13, i8* %11)
%94 = call i32 @SEND(i32 %37, i8* %13, i32 20, i32 0)
%95 = icmp slt i32 %94, 0
br i1 %95, label %98, label %96
96: ; preds = %91
%97 = icmp eq i64 %31, 0
br i1 %97, label %122, label %101
98: ; preds = %91
%99 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%100 = call i32 @exit(i32 1)
unreachable
101: ; preds = %96, %114
%102 = phi i64 [ %120, %114 ], [ %31, %96 ]
%103 = call i32 @fread(i8* %13, i32 1, i32 1000, i32* %34)
%104 = icmp slt i32 %103, 0
br i1 %104, label %105, label %108
105: ; preds = %101
%106 = call i32 @perror(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i64 0, i64 0))
%107 = call i32 @exit(i32 1)
unreachable
108: ; preds = %101
%109 = call i32 @SEND(i32 %37, i8* %13, i32 1000, i32 0)
%110 = icmp slt i32 %109, 0
br i1 %110, label %111, label %114
111: ; preds = %108
%112 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.8, i64 0, i64 0))
%113 = call i32 @exit(i32 1)
unreachable
114: ; preds = %108
%115 = zext i32 %103 to i64
%116 = icmp ult i64 %102, %115
%117 = trunc i64 %102 to i32
%118 = select i1 %116, i32 %117, i32 %103
%119 = sext i32 %118 to i64
%120 = sub i64 %102, %119
%121 = icmp eq i64 %120, 0
br i1 %121, label %122, label %101
122: ; preds = %114, %96
%123 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.10, i64 0, i64 0), i64 %31)
%124 = call i32 @CLOSE(i32 %37)
%125 = call i32 @fclose(i32* %34)
ret i32 0
}