#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ client_addr;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ MSG_WAITALL;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(unsigned char *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int recv(int, unsigned char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
int main(int argc, char *argv[]) {
  char port[8] = "1040";
  int sock;
  struct sockaddr_in sin_addr;
  if (argc > 2) {
    fprintf(stderr, "Incorrect command line format.\n");
    fprintf(stderr, "USAGE: ftps [local_port]\n");
    exit(1);
  }
  if (argc == 2) {
    strcpy(port, argv[1]);
  }
  printf("TCP server waiting for remote connection from clients ...\n");
  if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
    perror("error openting datagram socket");
    exit(1);
  }
  sin_addr.sin_family = AF_INET;
  sin_addr.sin_addr.s_addr = INADDR_ANY;
  sin_addr.sin_port = htons(atoi(port));
  if (bind(sock, (struct sockaddr *)&sin_addr, sizeof(struct sockaddr_in)) <
      0) {
    perror("error binding stream socket");
    exit(1);
  }
  listen(sock, 5);
  printf("Listen on port %s\n", port);
  while (1) {
    int sock_client;
    struct sockaddr_in client_addr;
    socklen_t client_addr_len;
    int r_val;
    int fw_val;
    unsigned int file_size, file_left;
    unsigned char buf_in[1024];
    char file_name[21];
    FILE *recv_file;
    client_addr_len = sizeof(client_addr);
    if ((sock_client = accept(sock, (struct sockaddr *)&client_addr,
                              &client_addr_len)) == -1) {
      perror("error connecting stream socket");
      exit(1);
    }
    bzero(buf_in, 1024);
    r_val = recv(sock_client, buf_in, 4, MSG_WAITALL);
    if (r_val < 0) {
      perror("error reading file size");
      exit(1);
    }
    file_size =
        (buf_in[0] << 24) | (buf_in[1] << 16) | (buf_in[2] << 8) | (buf_in[3]);
    printf("file size: %u bytes\n", file_size);
    r_val = recv(sock_client, buf_in, 20, MSG_WAITALL);
    if (r_val < 0) {
      perror("error reading file name");
      exit(1);
    }
    buf_in[r_val] = 0;
    strcpy(file_name, (const char *)buf_in);
    printf("file name: %s\n", file_name);
    recv_file = fopen(file_name, "wb");
    file_left = file_size;
    while (file_left) {
      r_val = read(sock_client, buf_in, 1024);
      if (r_val < 0) {
        perror("error reading on stream socket");
        break;
      }
      if (r_val > file_left) {
        r_val = file_left;
      }
      fw_val = fwrite(buf_in, sizeof(unsigned char), r_val, recv_file);
      if (fw_val < 0) {
        perror("error writing on local file");
        break;
      }
      file_left = file_left - r_val;
    }
    printf("Server receives: %u bytes\n", file_size);
    close(sock_client);
    fclose(recv_file);
  }
  close(sock);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x480,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xdc0(%rip),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    1282 <main+0x62>
mov    0x2d7b(%rip),%rax
mov    (%rax),%edi
lea    0xdaa(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2d66(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
cmpl   $0x2,-0x8(%rbp)
jne    129d <main+0x7d>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
lea    0xd9e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
mov    0x2d0d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    12e6 <main+0xc6>
lea    0xda6(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ce7(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10c0 <bind@plt>
cmp    $0x0,%rax
jge    1342 <main+0x122>
lea    0xd69(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   10b0 <listen@plt>
lea    -0x18(%rbp),%rsi
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1100 <accept@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    139a <main+0x17a>
lea    0xd40(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x450(%rbp),%rdi
mov    $0x400,%esi
call   10f0 <bzero@plt>
mov    -0x2c(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    0x2bfc(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1030 <recv@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    13eb <main+0x1cb>
lea    0xd0e(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movzbl -0x450(%rbp),%eax
shl    $0x18,%eax
movzbl -0x44f(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movzbl -0x44e(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x44d(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%esi
lea    0xcdf(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    0x2b7d(%rip),%rax
mov    (%rax),%ecx
mov    $0x14,%edx
call   1030 <recv@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    146a <main+0x24a>
lea    0xcbc(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movslq -0x40(%rbp),%rax
movb   $0x0,-0x450(%rbp,%rax,1)
lea    -0x470(%rbp),%rdi
lea    -0x450(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x470(%rbp),%rsi
lea    0xc98(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
lea    -0x470(%rbp),%rdi
lea    0xc92(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0x478(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1553 <main+0x333>
mov    -0x2c(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    14fa <main+0x2da>
lea    0xc51(%rip),%rdi
call   10e0 <perror@plt>
jmp    1553 <main+0x333>
mov    -0x40(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jbe    150c <main+0x2ec>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x450(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x478(%rbp),%rcx
mov    $0x1,%esi
call   1130 <fwrite@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1545 <main+0x325>
lea    0xc25(%rip),%rdi
call   10e0 <perror@plt>
jmp    1553 <main+0x333>
mov    -0x4c(%rbp),%eax
sub    -0x40(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    14be <main+0x29e>
mov    -0x48(%rbp),%esi
lea    0xc1f(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
mov    -0x478(%rbp),%rdi
call   1050 <fclose@plt>
jmp    1361 <main+0x141>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x468,%rsp
movq   $0x30343031,0x10(%rsp)
34 30
cmp    $0x3,%edi
jl     127c <main+0x4c>
mov    0x2d7a(%rip),%rbx
mov    (%rbx),%edi
lea    0xda1(%rip),%rsi
call   10b0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xdb3(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
cmp    $0x2,%edi
jne    128f <main+0x5f>
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%rdi
call   1040 <strcpy@plt>
lea    0xebe(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d46(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d1d(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1150 <socket@plt>
test   %eax,%eax
jns    12c4 <main+0x94>
lea    0xd7b(%rip),%rdi
jmp    14ce <main+0x29e>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x28(%rsp)
mov    0x2d0c(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
lea    0x10(%rsp),%rdi
call   1120 <atoi@plt>
mov    %eax,%edi
call   1070 <htons@plt>
mov    %eax,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10d0 <bind@plt>
test   %rax,%rax
jns    1312 <main+0xe2>
lea    0xd4c(%rip),%rdi
jmp    14ce <main+0x29e>
mov    %r14d,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
lea    0xd4f(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1080 <printf@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   1110 <accept@plt>
cmp    $0xffffffff,%eax
jne    135d <main+0x12d>
lea    0xd30(%rip),%rdi
jmp    14ce <main+0x29e>
mov    %eax,%ebp
lea    0x60(%rsp),%rbx
mov    0x2c4d(%rip),%r15
mov    %r14d,0x1c(%rsp)
jmp    13c9 <main+0x199>
lea    0xd85(%rip),%rdi
call   10f0 <perror@plt>
xchg   %ax,%ax
lea    0xdb2(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %ebp,%edi
call   1090 <close@plt>
mov    %r12,%rdi
call   1060 <fclose@plt>
movl   $0xc,0xc(%rsp)
mov    0x1c(%rsp),%edi
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1110 <accept@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
mov    0x2bf1(%rip),%r15
je     1351 <main+0x121>
mov    %rbx,%rdi
mov    $0x400,%esi
call   1100 <bzero@plt>
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1030 <recv@plt>
test   %eax,%eax
js     14be <main+0x28e>
mov    0x60(%rsp),%r13d
bswap  %r13d
lea    0xcc0(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1080 <printf@plt>
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1030 <recv@plt>
test   %eax,%eax
js     14c7 <main+0x297>
mov    %eax,%eax
movb   $0x0,0x60(%rsp,%rax,1)
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
lea    0xcab(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
lea    0xca6(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,%r12
mov    %r13d,%r14d
test   %r13d,%r13d
je     1380 <main+0x150>
nopl   0x0(%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
test   %eax,%eax
js     1372 <main+0x142>
mov    %eax,%r15d
cmp    %r14d,%eax
cmova  %r14d,%r15d
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %r12,%rcx
call   1140 <fwrite@plt>
test   %eax,%eax
js     14b2 <main+0x282>
sub    %r15d,%r14d
jne    1470 <main+0x240>
jmp    1380 <main+0x150>
lea    0xc64(%rip),%rdi
jmp    1379 <main+0x149>
lea    0xbe2(%rip),%rdi
jmp    14ce <main+0x29e>
lea    0xc06(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1130 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%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 = [26 x i8] c"USAGE: ftps [local_port]\0A\00"
@.str.2 = [59 x i8] c"TCP server waiting for remote connection from clients ...\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [31 x i8] c"error openting datagram socket\00"
@INADDR_ANY = global i32 0
@.str.4 = [28 x i8] c"error binding stream socket\00"
@.str.5 = [19 x i8] c"Listen on port %s\0A\00"
@.str.6 = [31 x i8] c"error connecting stream socket\00"
@MSG_WAITALL = global i32 0
@.str.7 = [24 x i8] c"error reading file size\00"
@.str.8 = [21 x i8] c"file size: %u bytes\0A\00"
@.str.9 = [24 x i8] c"error reading file name\00"
@.str.10 = [15 x i8] c"file name: %s\0A\00"
@.str.11 = [3 x i8] c"wb\00"
@.str.12 = [31 x i8] c"error reading on stream socket\00"
@.str.13 = [28 x i8] c"error writing on local file\00"
@.str.14 = [27 x i8] c"Server receives: %u bytes\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [8 x i8]
%7 = alloca i32
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca %struct.sockaddr_in
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca [1024 x i8]
%17 = alloca [21 x i8]
%18 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%19 = bitcast [8 x i8]* %6 to i8*
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 2
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = load i32, i32* @stderr
%24 = call i32 @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 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %2
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 2
br i1 %30, label %31, label %37
31: ; preds = %28
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @strcpy(i8* %32, i8* %35)
br label %37
37: ; preds = %31, %28
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%39 = load i32, i32* @AF_INET
%40 = load i32, i32* @SOCK_STREAM
%41 = call i32 @socket(i32 %39, i32 %40, i32 0)
store i32 %41, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %46
43: ; preds = %37
%44 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%45 = call i32 @exit(i32 1)
unreachable
46: ; preds = %37
%47 = load i32, i32* @AF_INET
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %47, i32* %48
%49 = load i32, i32* @INADDR_ANY
%50 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%51 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %50, i32 0, i32 0
store i32 %49, i32* %51
%52 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%53 = call i32 @atoi(i8* %52)
%54 = call i32 @htons(i32 %53)
%55 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %54, i32* %55
%56 = load i32, i32* %7
%57 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%58 = call i64 @bind(i32 %56, %struct.sockaddr* %57, i32 12)
%59 = icmp slt i64 %58, 0
br i1 %59, label %60, label %63
60: ; preds = %46
%61 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%62 = call i32 @exit(i32 1)
unreachable
63: ; preds = %46
%64 = load i32, i32* %7
%65 = call i32 @listen(i32 %64, i32 5)
%66 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %66)
br label %68
68: ; preds = %63, %160
store i32 12, i32* %11
%69 = load i32, i32* %7
%70 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%71 = call i32 @accept(i32 %69, %struct.sockaddr* %70, i32* %11)
store i32 %71, i32* %9
%72 = icmp eq i32 %71, -1
br i1 %72, label %73, label %76
73: ; preds = %68
%74 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%75 = call i32 @exit(i32 1)
unreachable
76: ; preds = %68
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%78 = call i32 @bzero(i8* %77, i32 1024)
%79 = load i32, i32* %9
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%81 = load i32, i32* @MSG_WAITALL
%82 = call i32 @recv(i32 %79, i8* %80, i32 4, i32 %81)
store i32 %82, i32* %12
%83 = load i32, i32* %12
%84 = icmp slt i32 %83, 0
br i1 %84, label %85, label %88
85: ; preds = %76
%86 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%87 = call i32 @exit(i32 1)
unreachable
88: ; preds = %76
%89 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%90 = load i8, i8* %89
%91 = zext i8 %90 to i32
%92 = shl i32 %91, 24
%93 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 1
%94 = load i8, i8* %93
%95 = zext i8 %94 to i32
%96 = shl i32 %95, 16
%97 = or i32 %92, %96
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 2
%99 = load i8, i8* %98
%100 = zext i8 %99 to i32
%101 = shl i32 %100, 8
%102 = or i32 %97, %101
%103 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 3
%104 = load i8, i8* %103
%105 = zext i8 %104 to i32
%106 = or i32 %102, %105
store i32 %106, i32* %14
%107 = load i32, i32* %14
%108 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %107)
%109 = load i32, i32* %9
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%111 = load i32, i32* @MSG_WAITALL
%112 = call i32 @recv(i32 %109, i8* %110, i32 20, i32 %111)
store i32 %112, i32* %12
%113 = load i32, i32* %12
%114 = icmp slt i32 %113, 0
br i1 %114, label %115, label %118
115: ; preds = %88
%116 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%117 = call i32 @exit(i32 1)
unreachable
118: ; preds = %88
%119 = load i32, i32* %12
%120 = sext i32 %119 to i64
%121 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 %120
store i8 0, i8* %121
%122 = getelementptr inbounds [21 x i8], [21 x i8]* %17, i64 0, i64 0
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%124 = call i32 @strcpy(i8* %122, i8* %123)
%125 = getelementptr inbounds [21 x i8], [21 x i8]* %17, i64 0, i64 0
%126 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* %125)
%127 = getelementptr inbounds [21 x i8], [21 x i8]* %17, i64 0, i64 0
%128 = call i32* @fopen(i8* %127, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
store i32* %128, i32** %18
%129 = load i32, i32* %14
store i32 %129, i32* %15
br label %130
130: ; preds = %156, %118
%131 = load i32, i32* %15
%132 = icmp ne i32 %131, 0
br i1 %132, label %133, label %160
133: ; preds = %130
%134 = load i32, i32* %9
%135 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%136 = call i32 @read(i32 %134, i8* %135, i32 1024)
store i32 %136, i32* %12
%137 = load i32, i32* %12
%138 = icmp slt i32 %137, 0
br i1 %138, label %139, label %141
139: ; preds = %133
%140 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0))
br label %160
141: ; preds = %133
%142 = load i32, i32* %12
%143 = load i32, i32* %15
%144 = icmp ugt i32 %142, %143
br i1 %144, label %145, label %147
145: ; preds = %141
%146 = load i32, i32* %15
store i32 %146, i32* %12
br label %147
147: ; preds = %145, %141
%148 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%149 = load i32, i32* %12
%150 = load i32*, i32** %18
%151 = call i32 @fwrite(i8* %148, i32 1, i32 %149, i32* %150)
store i32 %151, i32* %13
%152 = load i32, i32* %13
%153 = icmp slt i32 %152, 0
br i1 %153, label %154, label %156
154: ; preds = %147
%155 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0))
br label %160
156: ; preds = %147
%157 = load i32, i32* %15
%158 = load i32, i32* %12
%159 = sub i32 %157, %158
store i32 %159, i32* %15
br label %130
160: ; preds = %154, %139, %130
%161 = load i32, i32* %14
%162 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %161)
%163 = load i32, i32* %9
%164 = call i32 @close(i32 %163)
%165 = load i32*, i32** %18
%166 = call i32 @fclose(i32* %165)
br label %68
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Incorrect command line format.\0A\00"
@.str.1 = [26 x i8] c"USAGE: ftps [local_port]\0A\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.3 = [31 x i8] c"error openting datagram socket\00"
@INADDR_ANY = global i32 0
@.str.4 = [28 x i8] c"error binding stream socket\00"
@.str.5 = [19 x i8] c"Listen on port %s\0A\00"
@.str.6 = [31 x i8] c"error connecting stream socket\00"
@MSG_WAITALL = global i32 0
@.str.7 = [24 x i8] c"error reading file size\00"
@.str.8 = [21 x i8] c"file size: %u bytes\0A\00"
@.str.9 = [24 x i8] c"error reading file name\00"
@.str.10 = [15 x i8] c"file name: %s\0A\00"
@.str.11 = [3 x i8] c"wb\00"
@.str.12 = [31 x i8] c"error reading on stream socket\00"
@.str.13 = [28 x i8] c"error writing on local file\00"
@.str.14 = [27 x i8] c"Server receives: %u bytes\0A\00"
@str = [58 x i8] c"TCP server waiting for remote connection from clients ...\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i64
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca i32
%7 = alloca [1024 x i8]
%8 = alloca [21 x i8]
%9 = bitcast i64* %3 to i8*
store i64 808726577, i64* %3
%10 = bitcast %struct.sockaddr_in* %4 to i8*
%11 = icmp sgt i32 %0, 2
br i1 %11, label %12, label %18
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%17 = tail call i32 @exit(i32 1)
unreachable
18: ; preds = %2
%19 = icmp eq i32 %0, 2
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strcpy(i8* %9, i8* %22)
br label %24
24: ; preds = %20, %18
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%26 = load i32, i32* @AF_INET
%27 = load i32, i32* @SOCK_STREAM
%28 = call i32 @socket(i32 %26, i32 %27, i32 0)
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %24
%31 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %24
%34 = load i32, i32* @AF_INET
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %34, i32* %35
%36 = load i32, i32* @INADDR_ANY
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %36, i32* %37
%38 = call i32 @atoi(i8* %9)
%39 = call i32 @htons(i32 %38)
%40 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %39, i32* %40
%41 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%42 = call i64 @bind(i32 %28, %struct.sockaddr* %41, i32 12)
%43 = icmp slt i64 %42, 0
br i1 %43, label %44, label %47
44: ; preds = %33
%45 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %33
%48 = call i32 @listen(i32 %28, i32 5)
%49 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i64* %3)
%50 = bitcast %struct.sockaddr_in* %5 to i8*
%51 = bitcast i32* %6 to i8*
%52 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%53 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%54 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
store i32 12, i32* %6
%55 = call i32 @accept(i32 %28, %struct.sockaddr* %54, i32* %6)
%56 = icmp eq i32 %55, -1
br i1 %56, label %61, label %57
57: ; preds = %47
%58 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 1
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 2
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 3
br label %64
61: ; preds = %117, %47
%62 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0))
%63 = call i32 @exit(i32 1)
unreachable
64: ; preds = %57, %117
%65 = phi i32 [ %55, %57 ], [ %121, %117 ]
%66 = call i32 @bzero(i8* %52, i32 1024)
%67 = load i32, i32* @MSG_WAITALL
%68 = call i32 @recv(i32 %65, i8* %52, i32 4, i32 %67)
%69 = icmp slt i32 %68, 0
br i1 %69, label %70, label %73
70: ; preds = %64
%71 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.7, i64 0, i64 0))
%72 = call i32 @exit(i32 1)
unreachable
73: ; preds = %64
%74 = load i8, i8* %52
%75 = zext i8 %74 to i32
%76 = shl nuw i32 %75, 24
%77 = load i8, i8* %58
%78 = zext i8 %77 to i32
%79 = shl nuw nsw i32 %78, 16
%80 = or i32 %79, %76
%81 = load i8, i8* %59
%82 = zext i8 %81 to i32
%83 = shl nuw nsw i32 %82, 8
%84 = or i32 %80, %83
%85 = load i8, i8* %60
%86 = zext i8 %85 to i32
%87 = or i32 %84, %86
%88 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i32 %87)
%89 = load i32, i32* @MSG_WAITALL
%90 = call i32 @recv(i32 %65, i8* %52, i32 20, i32 %89)
%91 = icmp slt i32 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %73
%93 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.9, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %73
%96 = zext i32 %90 to i64
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %96
store i8 0, i8* %97
%98 = call i32 @strcpy(i8* %53, i8* %52)
%99 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* %53)
%100 = call i32* @fopen(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%101 = icmp eq i32 %87, 0
br i1 %101, label %117, label %104
102: ; preds = %108
%103 = icmp eq i32 %113, 0
br i1 %103, label %117, label %104
104: ; preds = %95, %102
%105 = phi i32 [ %113, %102 ], [ %87, %95 ]
%106 = call i32 @read(i32 %65, i8* %52, i32 1024)
%107 = icmp slt i32 %106, 0
br i1 %107, label %114, label %108
108: ; preds = %104
%109 = icmp ugt i32 %106, %105
%110 = select i1 %109, i32 %105, i32 %106
%111 = call i32 @fwrite(i8* %52, i32 1, i32 %110, i32* %100)
%112 = icmp slt i32 %111, 0
%113 = sub i32 %105, %110
br i1 %112, label %114, label %102
114: ; preds = %108, %104
%115 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.12, i64 0, i64 0), %104 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.13, i64 0, i64 0), %108 ]
%116 = call i32 @perror(i8* %115)
br label %117
117: ; preds = %102, %114, %95
%118 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i32 %87)
%119 = call i32 @close(i32 %65)
%120 = call i32 @fclose(i32* %100)
store i32 12, i32* %6
%121 = call i32 @accept(i32 %28, %struct.sockaddr* %54, i32* %6)
%122 = icmp eq i32 %121, -1
br i1 %122, label %61, label %64
}