#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 ACCEPT(int, struct sockaddr *, int *);
int /*<<< orphan*/ AF_INET;
scalar_t__ BIND(int, struct sockaddr *, int);
int /*<<< orphan*/ CLOSE(int);
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ LISTEN(int, int);
int /*<<< orphan*/ MSG_WAITALL;
int RECV(int, unsigned char *, int, int /*<<< orphan*/);
int SOCKET(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ atoi(char *);
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 fwrite(unsigned char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ init_tcpudp(char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char const *);
int main(int argc, char *argv[]) {
  char port[8] = "8000";
  int sock;
  struct sockaddr_in sin_addr;
  if (argc == 2) {
    strcpy(port, argv[1]);
  } else if (argc == 1) {
  } else {
    fprintf(stderr, "Incorrect command line format.\n");
    fprintf(stderr, "USAGE: ftps [local_port]\n");
    exit(1);
  }
  printf("TCP server waiting for remote connection from clients ...\n");
  init_tcpudp("SERVER");
  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[1000];
    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, 1000);
    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 = RECV(sock_client, buf_in, 1000, 0);
      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    $0x470,%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)
jne    1264 <main+0x44>
lea    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
jmp    12ac <main+0x8c>
cmpl   $0x1,-0x8(%rbp)
jne    1273 <main+0x53>
jmp    12a7 <main+0x87>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
call   10b0 <fprintf@plt>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
lea    0xd90(%rip),%rsi
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
jmp    12ac <main+0x8c>
lea    0xd8f(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    0xdbc(%rip),%rdi
call   1040 <init_tcpudp@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
mov    0x2cf2(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1050 <SOCKET@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jge    1301 <main+0xe1>
lea    0xd92(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2ccc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
lea    -0x18(%rbp),%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1080 <htons@plt>
mov    %eax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0xc,%edx
call   10d0 <BIND@plt>
cmp    $0x0,%rax
jge    135d <main+0x13d>
lea    0xd55(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
mov    -0x1c(%rbp),%edi
mov    $0x5,%esi
call   10c0 <LISTEN@plt>
lea    -0x18(%rbp),%rsi
lea    0xd4a(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
movl   $0xc,-0x3c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x3c(%rbp),%rdx
call   1070 <ACCEPT@plt>
mov    %eax,-0x2c(%rbp)
cmp    $0xffffffff,%eax
jne    13b5 <main+0x195>
lea    0xd2c(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
lea    -0x440(%rbp),%rdi
mov    $0x3e8,%esi
call   1100 <bzero@plt>
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    0x2be1(%rip),%rax
mov    (%rax),%ecx
mov    $0x4,%edx
call   1140 <RECV@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1406 <main+0x1e6>
lea    0xcfa(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movzbl -0x440(%rbp),%eax
shl    $0x18,%eax
movzbl -0x43f(%rbp),%ecx
shl    $0x10,%ecx
or     %ecx,%eax
movzbl -0x43e(%rbp),%ecx
shl    $0x8,%ecx
or     %ecx,%eax
movzbl -0x43d(%rbp),%ecx
or     %ecx,%eax
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%esi
lea    0xccb(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    0x2b62(%rip),%rax
mov    (%rax),%ecx
mov    $0x14,%edx
call   1140 <RECV@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1485 <main+0x265>
lea    0xca8(%rip),%rdi
call   10f0 <perror@plt>
mov    $0x1,%edi
call   1120 <exit@plt>
movslq -0x40(%rbp),%rax
movb   $0x0,-0x440(%rbp,%rax,1)
lea    -0x460(%rbp),%rdi
lea    -0x440(%rbp),%rsi
call   1030 <strcpy@plt>
lea    -0x460(%rbp),%rsi
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
lea    -0x460(%rbp),%rdi
lea    0xc7e(%rip),%rsi
call   10e0 <fopen@plt>
mov    %rax,-0x468(%rbp)
mov    -0x48(%rbp),%eax
mov    %eax,-0x4c(%rbp)
cmpl   $0x0,-0x4c(%rbp)
je     1570 <main+0x350>
mov    -0x2c(%rbp),%edi
lea    -0x440(%rbp),%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1140 <RECV@plt>
mov    %eax,-0x40(%rbp)
cmpl   $0x0,-0x40(%rbp)
jge    1517 <main+0x2f7>
lea    0xc3b(%rip),%rdi
call   10f0 <perror@plt>
jmp    1570 <main+0x350>
mov    -0x40(%rbp),%eax
cmp    -0x4c(%rbp),%eax
jbe    1529 <main+0x309>
mov    -0x4c(%rbp),%eax
mov    %eax,-0x40(%rbp)
lea    -0x440(%rbp),%rdi
mov    -0x40(%rbp),%edx
mov    -0x468(%rbp),%rcx
mov    $0x1,%esi
call   1130 <fwrite@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0x0,-0x44(%rbp)
jge    1562 <main+0x342>
lea    0xc0f(%rip),%rdi
call   10f0 <perror@plt>
jmp    1570 <main+0x350>
mov    -0x4c(%rbp),%eax
sub    -0x40(%rbp),%eax
mov    %eax,-0x4c(%rbp)
jmp    14d9 <main+0x2b9>
mov    -0x48(%rbp),%esi
lea    0xc09(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x2c(%rbp),%edi
call   10a0 <CLOSE@plt>
mov    -0x468(%rbp),%rdi
call   1060 <fclose@plt>
jmp    137c <main+0x15c>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x448,%rsp
movq   $0x30303038,0x10(%rsp)
30 30
cmp    $0x1,%edi
je     1262 <main+0x32>
cmp    $0x2,%edi
jne    12a3 <main+0x73>
mov    0x8(%rsi),%rsi
lea    0x10(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0xef2(%rip),%rdi
call   1050 <puts@plt>
lea    0xdc5(%rip),%rdi
call   1040 <init_tcpudp@plt>
mov    0x2d67(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d3e(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1060 <SOCKET@plt>
test   %eax,%eax
jns    12d0 <main+0xa0>
lea    0xda3(%rip),%rdi
jmp    14e0 <main+0x2b0>
mov    0x2d26(%rip),%rbx
mov    (%rbx),%edi
lea    0xd4d(%rip),%rsi
call   10c0 <fprintf@plt>
mov    (%rbx),%edi
lea    0xd5f(%rip),%rsi
call   10c0 <fprintf@plt>
mov    $0x1,%edi
call   1130 <exit@plt>
mov    %eax,%r14d
mov    (%rbx),%eax
mov    %eax,0x28(%rsp)
mov    0x2d00(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
lea    0x10(%rsp),%rdi
call   1120 <atoi@plt>
mov    %eax,%edi
call   1090 <htons@plt>
mov    %eax,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %r14d,%edi
mov    $0xc,%edx
call   10e0 <BIND@plt>
test   %rax,%rax
jns    131e <main+0xee>
lea    0xd47(%rip),%rdi
jmp    14e0 <main+0x2b0>
mov    %r14d,%edi
mov    $0x5,%esi
call   10d0 <LISTEN@plt>
lea    0xd4a(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
movl   $0xc,0xc(%rsp)
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %r14d,%edi
call   1080 <ACCEPT@plt>
cmp    $0xffffffff,%eax
jne    1369 <main+0x139>
lea    0xd2b(%rip),%rdi
jmp    14e0 <main+0x2b0>
mov    %eax,%ebp
lea    0x60(%rsp),%rbx
mov    0x2c41(%rip),%r15
mov    %r14d,0x1c(%rsp)
jmp    13dd <main+0x1ad>
lea    0xd80(%rip),%rdi
call   1100 <perror@plt>
nopw   0x0(%rax,%rax,1)
lea    0xda9(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %ebp,%edi
call   10b0 <CLOSE@plt>
mov    %r12,%rdi
call   1070 <fclose@plt>
movl   $0xc,0xc(%rsp)
mov    0x1c(%rsp),%edi
lea    0x30(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1080 <ACCEPT@plt>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
mov    0x2be1(%rip),%r15
je     135d <main+0x12d>
mov    %rbx,%rdi
mov    $0x3e8,%esi
call   1110 <bzero@plt>
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1150 <RECV@plt>
test   %eax,%eax
js     14d0 <main+0x2a0>
mov    0x60(%rsp),%r13d
bswap  %r13d
lea    0xcb3(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%r15),%ecx
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x14,%edx
call   1150 <RECV@plt>
test   %eax,%eax
js     14d9 <main+0x2a9>
mov    %eax,%eax
movb   $0x0,0x60(%rsp,%rax,1)
lea    0x40(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
lea    0xc9e(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %r14,%rdi
lea    0xc99(%rip),%rsi
call   10f0 <fopen@plt>
mov    %rax,%r12
mov    %r13d,%r14d
test   %r13d,%r13d
je     1390 <main+0x160>
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3e8,%edx
xor    %ecx,%ecx
call   1150 <RECV@plt>
test   %eax,%eax
js     137e <main+0x14e>
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     14c4 <main+0x294>
sub    %r15d,%r14d
jne    1480 <main+0x250>
jmp    1390 <main+0x160>
lea    0xc59(%rip),%rdi
jmp    1385 <main+0x155>
lea    0xbd7(%rip),%rdi
jmp    14e0 <main+0x2b0>
lea    0xbfb(%rip),%rdi
call   1100 <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"8000\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"
@.str.3 = [7 x i8] c"SERVER\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [31 x i8] c"error openting datagram socket\00"
@INADDR_ANY = global i32 0
@.str.5 = [28 x i8] c"error binding stream socket\00"
@.str.6 = [19 x i8] c"Listen on port %s\0A\00"
@.str.7 = [31 x i8] c"error connecting stream socket\00"
@MSG_WAITALL = global i32 0
@.str.8 = [24 x i8] c"error reading file size\00"
@.str.9 = [21 x i8] c"file size: %u bytes\0A\00"
@.str.10 = [24 x i8] c"error reading file name\00"
@.str.11 = [15 x i8] c"file name: %s\0A\00"
@.str.12 = [3 x i8] c"wb\00"
@.str.13 = [31 x i8] c"error reading on stream socket\00"
@.str.14 = [28 x i8] c"error writing on local file\00"
@.str.15 = [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 [1000 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 eq i32 %20, 2
br i1 %21, label %22, label %28
22: ; preds = %2
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %6, 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)
br label %39
28: ; preds = %2
%29 = load i32, i32* %4
%30 = icmp eq i32 %29, 1
br i1 %30, label %31, label %32
31: ; preds = %28
br label %38
32: ; preds = %28
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0))
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %31
br label %39
39: ; preds = %38, %22
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([59 x i8], [59 x i8]* @.str.2, i64 0, i64 0))
%41 = call i32 @init_tcpudp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%42 = load i32, i32* @AF_INET
%43 = load i32, i32* @SOCK_STREAM
%44 = call i32 @SOCKET(i32 %42, i32 %43, i32 0)
store i32 %44, i32* %7
%45 = icmp slt i32 %44, 0
br i1 %45, label %46, label %49
46: ; preds = %39
%47 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%48 = call i32 @exit(i32 1)
unreachable
49: ; preds = %39
%50 = load i32, i32* @AF_INET
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %50, i32* %51
%52 = load i32, i32* @INADDR_ANY
%53 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
%54 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %53, i32 0, i32 0
store i32 %52, i32* %54
%55 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%56 = call i32 @atoi(i8* %55)
%57 = call i32 @htons(i32 %56)
%58 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
store i32 %57, i32* %58
%59 = load i32, i32* %7
%60 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%61 = call i64 @BIND(i32 %59, %struct.sockaddr* %60, i32 12)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %49
%64 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %49
%67 = load i32, i32* %7
%68 = call i32 @LISTEN(i32 %67, i32 5)
%69 = getelementptr inbounds [8 x i8], [8 x i8]* %6, i64 0, i64 0
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i8* %69)
br label %71
71: ; preds = %66, %163
store i32 12, i32* %11
%72 = load i32, i32* %7
%73 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%74 = call i32 @ACCEPT(i32 %72, %struct.sockaddr* %73, i32* %11)
store i32 %74, i32* %9
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %71
%77 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%78 = call i32 @exit(i32 1)
unreachable
79: ; preds = %71
%80 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%81 = call i32 @bzero(i8* %80, i32 1000)
%82 = load i32, i32* %9
%83 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%84 = load i32, i32* @MSG_WAITALL
%85 = call i32 @RECV(i32 %82, i8* %83, i32 4, i32 %84)
store i32 %85, i32* %12
%86 = load i32, i32* %12
%87 = icmp slt i32 %86, 0
br i1 %87, label %88, label %91
88: ; preds = %79
%89 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%90 = call i32 @exit(i32 1)
unreachable
91: ; preds = %79
%92 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%93 = load i8, i8* %92
%94 = zext i8 %93 to i32
%95 = shl i32 %94, 24
%96 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 1
%97 = load i8, i8* %96
%98 = zext i8 %97 to i32
%99 = shl i32 %98, 16
%100 = or i32 %95, %99
%101 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 2
%102 = load i8, i8* %101
%103 = zext i8 %102 to i32
%104 = shl i32 %103, 8
%105 = or i32 %100, %104
%106 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 3
%107 = load i8, i8* %106
%108 = zext i8 %107 to i32
%109 = or i32 %105, %108
store i32 %109, i32* %14
%110 = load i32, i32* %14
%111 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 %110)
%112 = load i32, i32* %9
%113 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%114 = load i32, i32* @MSG_WAITALL
%115 = call i32 @RECV(i32 %112, i8* %113, i32 20, i32 %114)
store i32 %115, i32* %12
%116 = load i32, i32* %12
%117 = icmp slt i32 %116, 0
br i1 %117, label %118, label %121
118: ; preds = %91
%119 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%120 = call i32 @exit(i32 1)
unreachable
121: ; preds = %91
%122 = load i32, i32* %12
%123 = sext i32 %122 to i64
%124 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 %123
store i8 0, i8* %124
%125 = getelementptr inbounds [21 x i8], [21 x i8]* %17, i64 0, i64 0
%126 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%127 = call i32 @strcpy(i8* %125, i8* %126)
%128 = getelementptr inbounds [21 x i8], [21 x i8]* %17, i64 0, i64 0
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %128)
%130 = getelementptr inbounds [21 x i8], [21 x i8]* %17, i64 0, i64 0
%131 = call i32* @fopen(i8* %130, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
store i32* %131, i32** %18
%132 = load i32, i32* %14
store i32 %132, i32* %15
br label %133
133: ; preds = %159, %121
%134 = load i32, i32* %15
%135 = icmp ne i32 %134, 0
br i1 %135, label %136, label %163
136: ; preds = %133
%137 = load i32, i32* %9
%138 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%139 = call i32 @RECV(i32 %137, i8* %138, i32 1000, i32 0)
store i32 %139, i32* %12
%140 = load i32, i32* %12
%141 = icmp slt i32 %140, 0
br i1 %141, label %142, label %144
142: ; preds = %136
%143 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
br label %163
144: ; preds = %136
%145 = load i32, i32* %12
%146 = load i32, i32* %15
%147 = icmp ugt i32 %145, %146
br i1 %147, label %148, label %150
148: ; preds = %144
%149 = load i32, i32* %15
store i32 %149, i32* %12
br label %150
150: ; preds = %148, %144
%151 = getelementptr inbounds [1000 x i8], [1000 x i8]* %16, i64 0, i64 0
%152 = load i32, i32* %12
%153 = load i32*, i32** %18
%154 = call i32 @fwrite(i8* %151, i32 1, i32 %152, i32* %153)
store i32 %154, i32* %13
%155 = load i32, i32* %13
%156 = icmp slt i32 %155, 0
br i1 %156, label %157, label %159
157: ; preds = %150
%158 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0))
br label %163
159: ; preds = %150
%160 = load i32, i32* %15
%161 = load i32, i32* %12
%162 = sub i32 %160, %161
store i32 %162, i32* %15
br label %133
163: ; preds = %157, %142, %133
%164 = load i32, i32* %14
%165 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.15, i64 0, i64 0), i32 %164)
%166 = load i32, i32* %9
%167 = call i32 @CLOSE(i32 %166)
%168 = load i32*, i32** %18
%169 = call i32 @fclose(i32* %168)
br label %71
}

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"
@.str.3 = [7 x i8] c"SERVER\00"
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str.4 = [31 x i8] c"error openting datagram socket\00"
@INADDR_ANY = global i32 0
@.str.5 = [28 x i8] c"error binding stream socket\00"
@.str.6 = [19 x i8] c"Listen on port %s\0A\00"
@.str.7 = [31 x i8] c"error connecting stream socket\00"
@MSG_WAITALL = global i32 0
@.str.8 = [24 x i8] c"error reading file size\00"
@.str.9 = [21 x i8] c"file size: %u bytes\0A\00"
@.str.10 = [24 x i8] c"error reading file name\00"
@.str.11 = [15 x i8] c"file name: %s\0A\00"
@.str.12 = [3 x i8] c"wb\00"
@.str.13 = [31 x i8] c"error reading on stream socket\00"
@.str.14 = [28 x i8] c"error writing on local file\00"
@.str.15 = [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 [1000 x i8]
%8 = alloca [21 x i8]
%9 = bitcast i64* %3 to i8*
store i64 808464440, i64* %3
%10 = bitcast %struct.sockaddr_in* %4 to i8*
switch i32 %0, label %15 [
i32 2, label %11
i32 1, label %21
]
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 1
%13 = load i8*, i8** %12
%14 = call i32 @strcpy(i8* %9, i8* %13)
br label %21
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = tail call i32 @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 @fprintf(i32 %18, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %2, %11
%22 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([58 x i8], [58 x i8]* @str, i64 0, i64 0))
%23 = call i32 @init_tcpudp(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @SOCKET(i32 %24, i32 %25, i32 0)
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %21
%29 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %21
%32 = load i32, i32* @AF_INET
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %32, i32* %33
%34 = load i32, i32* @INADDR_ANY
%35 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %34, i32* %35
%36 = call i32 @atoi(i8* %9)
%37 = call i32 @htons(i32 %36)
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %37, i32* %38
%39 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%40 = call i64 @BIND(i32 %26, %struct.sockaddr* %39, i32 12)
%41 = icmp slt i64 %40, 0
br i1 %41, label %42, label %45
42: ; preds = %31
%43 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.5, i64 0, i64 0))
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %31
%46 = call i32 @LISTEN(i32 %26, i32 5)
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0), i64* %3)
%48 = bitcast %struct.sockaddr_in* %5 to i8*
%49 = bitcast i32* %6 to i8*
%50 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 0
%51 = getelementptr inbounds [21 x i8], [21 x i8]* %8, i64 0, i64 0
%52 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
store i32 12, i32* %6
%53 = call i32 @ACCEPT(i32 %26, %struct.sockaddr* %52, i32* %6)
%54 = icmp eq i32 %53, -1
br i1 %54, label %59, label %55
55: ; preds = %45
%56 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 1
%57 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 2
%58 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 3
br label %62
59: ; preds = %115, %45
%60 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i64 0, i64 0))
%61 = call i32 @exit(i32 1)
unreachable
62: ; preds = %55, %115
%63 = phi i32 [ %53, %55 ], [ %119, %115 ]
%64 = call i32 @bzero(i8* %50, i32 1000)
%65 = load i32, i32* @MSG_WAITALL
%66 = call i32 @RECV(i32 %63, i8* %50, i32 4, i32 %65)
%67 = icmp slt i32 %66, 0
br i1 %67, label %68, label %71
68: ; preds = %62
%69 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%70 = call i32 @exit(i32 1)
unreachable
71: ; preds = %62
%72 = load i8, i8* %50
%73 = zext i8 %72 to i32
%74 = shl nuw i32 %73, 24
%75 = load i8, i8* %56
%76 = zext i8 %75 to i32
%77 = shl nuw nsw i32 %76, 16
%78 = or i32 %77, %74
%79 = load i8, i8* %57
%80 = zext i8 %79 to i32
%81 = shl nuw nsw i32 %80, 8
%82 = or i32 %78, %81
%83 = load i8, i8* %58
%84 = zext i8 %83 to i32
%85 = or i32 %82, %84
%86 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i32 %85)
%87 = load i32, i32* @MSG_WAITALL
%88 = call i32 @RECV(i32 %63, i8* %50, i32 20, i32 %87)
%89 = icmp slt i32 %88, 0
br i1 %89, label %90, label %93
90: ; preds = %71
%91 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
%92 = call i32 @exit(i32 1)
unreachable
93: ; preds = %71
%94 = zext i32 %88 to i64
%95 = getelementptr inbounds [1000 x i8], [1000 x i8]* %7, i64 0, i64 %94
store i8 0, i8* %95
%96 = call i32 @strcpy(i8* %51, i8* %50)
%97 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.11, i64 0, i64 0), i8* %51)
%98 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.12, i64 0, i64 0))
%99 = icmp eq i32 %85, 0
br i1 %99, label %115, label %102
100: ; preds = %106
%101 = icmp eq i32 %111, 0
br i1 %101, label %115, label %102
102: ; preds = %93, %100
%103 = phi i32 [ %111, %100 ], [ %85, %93 ]
%104 = call i32 @RECV(i32 %63, i8* %50, i32 1000, i32 0)
%105 = icmp slt i32 %104, 0
br i1 %105, label %112, label %106
106: ; preds = %102
%107 = icmp ugt i32 %104, %103
%108 = select i1 %107, i32 %103, i32 %104
%109 = call i32 @fwrite(i8* %50, i32 1, i32 %108, i32* %98)
%110 = icmp slt i32 %109, 0
%111 = sub i32 %103, %108
br i1 %110, label %112, label %100
112: ; preds = %106, %102
%113 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0), %102 ], [ getelementptr inbounds ([28 x i8], [28 x i8]* @.str.14, i64 0, i64 0), %106 ]
%114 = call i32 @perror(i8* %113)
br label %115
115: ; preds = %100, %112, %93
%116 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([27 x i8], [27 x i8]* @.str.15, i64 0, i64 0), i32 %85)
%117 = call i32 @CLOSE(i32 %63)
%118 = call i32 @fclose(i32* %98)
store i32 12, i32* %6
%119 = call i32 @ACCEPT(i32 %26, %struct.sockaddr* %52, i32* %6)
%120 = icmp eq i32 %119, -1
br i1 %120, label %59, label %62
}