#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*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bcopy(void *, void *, int /*<<< orphan*/);
int /*<<< orphan*/ bzero(unsigned char *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, 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*/ perror(char *);
int /*<<< orphan*/ printf(char *, unsigned long);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ stat(char *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strcpy(char *, char *);
int write(int, unsigned char *, int);
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] = "1040";
  unsigned char buf[1024];
  struct hostent *hp;
  FILE *send_file;
  if (argc != 4) {
    fprintf(stderr, "Incorrect command line format.\n");
    fprintf(stderr,
            "USAGE: ftpc remote_IP remote_port local_file_to_transfer\n");
    exit(1);
  }
  strcpy(server_name, argv[1]);
  strcpy(port, argv[2]);
  strcpy(file_name, argv[3]);
  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 = write(sock, buf, 4);
  if (w_val < 0) {
    perror("error writing on stream socket");
    exit(1);
  }
  bzero(buf, 1024);
  strcpy((char *)buf, file_name);
  w_val = write(sock, buf, 20);
  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), 1024, send_file);
    if (r_val < 0) {
      perror("error reading file");
      exit(1);
    }
    if (r_val > file_left) {
      r_val = file_left;
    }
    w_val = write(sock, buf, 1024);
    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    $0x680,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xdc0(%rip),%rax
mov    %rax,-0x248(%rbp)
cmpl   $0x4,-0x8(%rbp)
je     1289 <main+0x69>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xdb0(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
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>
movq   $0xffffffffffffffff,-0x668(%rbp)
ff ff ff ff
movq   $0xffffffffffffffff,-0x670(%rbp)
ff ff ff ff
lea    -0x240(%rbp),%rdi
lea    -0x678(%rbp),%rsi
call   10c0 <stat@plt>
cmp    $0x0,%rax
jl     1306 <main+0xe6>
mov    -0x678(%rbp),%rax
mov    %rax,-0x668(%rbp)
mov    0x2cbb(%rip),%rax
mov    (%rax),%edi
mov    -0x668(%rbp),%rdx
lea    0xd45(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
lea    -0x240(%rbp),%rdi
lea    0xd45(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x660(%rbp)
mov    0x2ca3(%rip),%rax
mov    (%rax),%edi
mov    0x2c82(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1379 <main+0x159>
lea    0xd10(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x130(%rbp),%rdi
call   10a0 <gethostbyname@plt>
mov    %rax,-0x658(%rbp)
cmpq   $0x0,-0x658(%rbp)
jne    13c2 <main+0x1a2>
mov    0x2c37(%rip),%rax
mov    (%rax),%edi
lea    -0x130(%rbp),%rdx
lea    0xce8(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
mov    -0x658(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x28(%rbp),%rsi
add    $0x8,%rsi
mov    -0x658(%rbp),%rax
mov    (%rax),%edx
call   10d0 <bcopy@plt>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x248(%rbp),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
cmp    $0x0,%rax
jge    143e <main+0x21e>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
lea    0xc7c(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x668(%rbp),%rax
shr    $0x18,%rax
and    $0xff,%rax
mov    %al,-0x650(%rbp)
mov    -0x668(%rbp),%rax
shr    $0x10,%rax
and    $0xff,%rax
mov    %al,-0x64f(%rbp)
mov    -0x668(%rbp),%rax
shr    $0x8,%rax
and    $0xff,%rax
mov    %al,-0x64e(%rbp)
mov    -0x668(%rbp),%rax
and    $0xff,%rax
mov    %al,-0x64d(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x650(%rbp),%rsi
mov    $0x4,%edx
call   1050 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    14cd <main+0x2ad>
lea    0xc0c(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x650(%rbp),%rdi
mov    $0x400,%esi
call   1100 <bzero@plt>
lea    -0x650(%rbp),%rdi
lea    -0x240(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x14(%rbp),%edi
lea    -0x650(%rbp),%rsi
mov    $0x14,%edx
call   1050 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1528 <main+0x308>
lea    0xbb1(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x668(%rbp),%rax
mov    %rax,-0x670(%rbp)
cmpq   $0x0,-0x670(%rbp)
je     15f0 <main+0x3d0>
lea    -0x650(%rbp),%rdi
mov    -0x660(%rbp),%rcx
mov    $0x1,%esi
mov    $0x400,%edx
call   1040 <fread@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    1584 <main+0x364>
lea    0xb74(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movslq -0x18(%rbp),%rax
cmp    -0x670(%rbp),%rax
jbe    159f <main+0x37f>
mov    -0x670(%rbp),%rax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x650(%rbp),%rsi
mov    $0x400,%edx
call   1050 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    15d6 <main+0x3b6>
lea    0xb03(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x670(%rbp),%rax
movslq -0x18(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x670(%rbp)
jmp    1536 <main+0x316>
mov    -0x668(%rbp),%rsi
lea    0xafe(%rip),%rdi
call   1080 <printf@plt>
mov    -0x14(%rbp),%edi
call   1090 <close@plt>
mov    -0x660(%rbp),%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x680,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x648,%rsp
movq   $0x30343031,(%rsp)
30
cmp    $0x4,%edi
jne    1442 <main+0x222>
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    0x18(%rsp),%rsi
mov    %rbx,%rdi
call   10c0 <stat@plt>
mov    $0xffffffffffffffff,%r14
test   %rax,%rax
js     1291 <main+0x71>
mov    0x18(%rsp),%r14
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
lea    0xdb9(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
lea    0xdbd(%rip),%rsi
mov    %rbx,%rdi
call   10e0 <fopen@plt>
mov    %rax,%r15
mov    0x2d24(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
test   %eax,%eax
js     1473 <main+0x253>
mov    %eax,%r12d
lea    0x20(%rsp),%rdi
call   10a0 <gethostbyname@plt>
test   %rax,%rax
je     147c <main+0x25c>
mov    0x8(%rax),%rsi
lea    0x10(%rsp),%rdi
mov    (%rax),%edx
call   10d0 <memmove@plt>
mov    (%rbx),%eax
mov    %eax,0xc(%rsp)
mov    %rsp,%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %r12d,%edi
mov    $0xc,%edx
call   1130 <connect@plt>
test   %rax,%rax
js     14a2 <main+0x282>
mov    %r14d,%eax
bswap  %eax
mov    %eax,0x240(%rsp)
lea    0x240(%rsp),%rsi
mov    %r12d,%edi
mov    $0x4,%edx
call   1050 <write@plt>
test   %eax,%eax
js     1423 <main+0x203>
lea    0x240(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x400,%esi
call   1100 <bzero@plt>
lea    0x130(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %r12d,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1050 <write@plt>
test   %eax,%eax
js     1423 <main+0x203>
test   %r14,%r14
je     13f0 <main+0x1d0>
lea    0x240(%rsp),%r13
mov    %r14,%rbx
xchg   %ax,%ax
mov    %r13,%rdi
mov    $0x1,%esi
mov    $0x400,%edx
mov    %r15,%rcx
call   1040 <fread@plt>
test   %eax,%eax
js     142c <main+0x20c>
mov    %eax,%ebp
mov    %r12d,%edi
mov    %r13,%rsi
mov    $0x400,%edx
call   1050 <write@plt>
test   %eax,%eax
js     1423 <main+0x203>
mov    %ebp,%eax
cmp    %rax,%rbx
mov    %ebx,%eax
cmovae %ebp,%eax
cltq
sub    %rax,%rbx
jne    13b0 <main+0x190>
lea    0xcfd(%rip),%rdi
mov    %r14,%rsi
call   1080 <printf@plt>
mov    %r12d,%edi
call   1090 <close@plt>
mov    %r15,%rdi
call   1060 <fclose@plt>
xor    %eax,%eax
add    $0x648,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xc98(%rip),%rdi
jmp    1433 <main+0x213>
lea    0xcae(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2b8f(%rip),%rbx
mov    (%rbx),%edi
lea    0xbae(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xbbe(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    0xbf8(%rip),%rdi
jmp    1433 <main+0x213>
mov    0x2b55(%rip),%rax
mov    (%rax),%edi
lea    0xc05(%rip),%rsi
lea    0x20(%rsp),%rdx
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x2,%edi
call   1120 <exit@plt>
mov    %r12d,%edi
call   1090 <close@plt>
lea    0xbf2(%rip),%rdi
jmp    1433 <main+0x213>

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