#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 stat {
  int st_size;
};
struct TYPE_2__ {
  scalar_t__ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ server;
typedef int /*<<< orphan*/ client;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int O_CREAT;
int O_EXCL;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int listen(int, int);
char *malloc(int);
int open(char *, int, ...);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ recv(int, ...);
int /*<<< orphan*/ send(int, int *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sendfile(int, int, int /*<<< orphan*/ *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ sscanf(char *, char *, char *, ...);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int write(int, char *, int);
int main(int argc, char *argv[]) {
  struct sockaddr_in server, client;
  struct stat obj;
  int sock1, sock2;
  char buf[100], command[5], filename[20];
  char del_cmd[50];
  int k, i, size, len, c;
  int filehandle;
  sock1 = socket(AF_INET, SOCK_STREAM, 0);
  if (sock1 == -1) {
    printf("Socket creation failed");
    exit(1);
  }
  server.sin_port = atoi(argv[1]);
  server.sin_addr.s_addr = 0;
  k = bind(sock1, (struct sockaddr *)&server, sizeof(server));
  if (k == -1) {
    printf("Binding error");
    exit(1);
  }
  k = listen(sock1, 1);
  if (k == -1) {
    printf("Listen failed");
    exit(1);
  }
  len = sizeof(client);
  sock2 = accept(sock1, (struct sockaddr *)&client, &len);
  i = 1;
  while (1) {
    recv(sock2, buf, 100, 0);
    sscanf(buf, "%s", command);
    if (!strcmp(command, "ls")) {
      system("ls > temps.txt");
      i = 0;
      stat("temps.txt", &obj);
      size = obj.st_size;
      send(sock2, &size, sizeof(int), 0);
      filehandle = open("temps.txt", O_RDONLY);
      sendfile(sock2, filehandle, NULL, size);
    } else if (!strcmp(command, "get")) {
      sscanf(buf, "%s%s", filename, filename);
      stat(filename, &obj);
      filehandle = open(filename, O_RDONLY);
      size = obj.st_size;
      if (filehandle == -1)
        size = 0;
      send(sock2, &size, sizeof(int), 0);
      if (size)
        sendfile(sock2, filehandle, NULL, size);
    } else if (!strcmp(command, "put")) {
      int c = 0, len;
      char *f;
      sscanf(buf + strlen(command), "%s", filename);
      recv(sock2, &size, sizeof(int), 0);
      i = 1;
      while (1) {
        filehandle = open(filename, O_CREAT | O_EXCL | O_WRONLY, 0666);
        if (filehandle == -1)
          sprintf(filename + strlen(filename), "%d", i);
        else
          break;
      }
      f = malloc(size);
      recv(sock2, f, size, 0);
      c = write(filehandle, f, size);
      close(filehandle);
      send(sock2, &c, sizeof(int), 0);
    } else if (!strcmp(command, "bye") || !strcmp(command, "quit")) {
      printf("FTP server quitting..\n");
      i = 1;
      send(sock2, &i, sizeof(int), 0);
      exit(0);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
mov    0x2d57(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
mov    %eax,-0x3c(%rbp)
cmpl   $0xffffffff,-0x3c(%rbp)
jne    1295 <main+0x55>
lea    0xd7a(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x10,%edx
call   1100 <bind@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    12e7 <main+0xa7>
lea    0xd3f(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
mov    -0x3c(%rbp),%edi
mov    $0x1,%esi
call   10d0 <listen@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0xffffffff,-0x114(%rbp)
jne    131d <main+0xdd>
lea    0xd17(%rip),%rdi
call   1080 <printf@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movl   $0x10,-0x120(%rbp)
mov    -0x3c(%rbp),%edi
lea    -0x30(%rbp),%rsi
lea    -0x120(%rbp),%rdx
call   1120 <accept@plt>
mov    %eax,-0x40(%rbp)
movl   $0x1,-0x118(%rbp)
mov    -0x40(%rbp),%edi
lea    -0xb0(%rbp),%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1030 <recv@plt>
lea    -0xb0(%rbp),%rdi
lea    -0xb5(%rbp),%rdx
lea    0xcd7(%rip),%rsi
mov    $0x0,%al
call   10e0 <sscanf@plt>
lea    -0xb5(%rbp),%rdi
lea    0xcaa(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1416 <main+0x1d6>
lea    0xc98(%rip),%rdi
call   1060 <system@plt>
movl   $0x0,-0x118(%rbp)
lea    0xc87(%rip),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <stat@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x11c(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x11c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    0x2bf5(%rip),%rax
mov    (%rax),%esi
lea    0xc4f(%rip),%rdi
mov    $0x0,%al
call   1110 <open@plt>
mov    %eax,-0x128(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x128(%rbp),%esi
mov    -0x11c(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edx
call   10f0 <sendfile@plt>
jmp    16d6 <main+0x496>
lea    -0xb5(%rbp),%rdi
lea    0xc21(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    14e2 <main+0x2a2>
lea    -0xb0(%rbp),%rdi
lea    -0xd0(%rbp),%rdx
lea    -0xd0(%rbp),%rcx
lea    0xbfb(%rip),%rsi
mov    $0x0,%al
call   10e0 <sscanf@plt>
lea    -0xd0(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   10b0 <stat@plt>
lea    -0xd0(%rbp),%rdi
mov    0x2b65(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1110 <open@plt>
mov    %eax,-0x128(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x11c(%rbp)
cmpl   $0xffffffff,-0x128(%rbp)
jne    14a2 <main+0x262>
movl   $0x0,-0x11c(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x11c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
cmpl   $0x0,-0x11c(%rbp)
je     14dd <main+0x29d>
mov    -0x40(%rbp),%edi
mov    -0x128(%rbp),%esi
mov    -0x11c(%rbp),%ecx
xor    %eax,%eax
mov    %eax,%edx
call   10f0 <sendfile@plt>
jmp    16d1 <main+0x491>
lea    -0xb5(%rbp),%rdi
lea    0xb5e(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    165c <main+0x41c>
movl   $0x0,-0x12c(%rbp)
lea    -0xb0(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0xb5(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x140(%rbp),%rdi
cltq
add    %rax,%rdi
lea    -0xd0(%rbp),%rdx
lea    0xb0f(%rip),%rsi
mov    $0x0,%al
call   10e0 <sscanf@plt>
mov    -0x40(%rbp),%edi
lea    -0x11c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1030 <recv@plt>
movl   $0x1,-0x118(%rbp)
lea    -0xd0(%rbp),%rdi
mov    0x2a85(%rip),%rax
mov    (%rax),%esi
mov    0x2a4c(%rip),%rax
or     (%rax),%esi
mov    0x2a2b(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1110 <open@plt>
mov    %eax,-0x128(%rbp)
cmpl   $0xffffffff,-0x128(%rbp)
jne    15e3 <main+0x3a3>
lea    -0xd0(%rbp),%rax
mov    %rax,-0x148(%rbp)
lea    -0xd0(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x148(%rbp),%rdi
cltq
add    %rax,%rdi
mov    -0x118(%rbp),%edx
lea    0xa79(%rip),%rsi
call   1140 <sprintf@plt>
jmp    15e8 <main+0x3a8>
jmp    15ed <main+0x3ad>
jmp    1565 <main+0x325>
mov    -0x11c(%rbp),%edi
call   10c0 <malloc@plt>
mov    %rax,-0x138(%rbp)
mov    -0x40(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    -0x11c(%rbp),%edx
xor    %ecx,%ecx
mov    $0x0,%al
call   1030 <recv@plt>
mov    -0x128(%rbp),%edi
mov    -0x138(%rbp),%rsi
mov    -0x11c(%rbp),%edx
call   1040 <write@plt>
mov    %eax,-0x12c(%rbp)
mov    -0x128(%rbp),%edi
call   1090 <close@plt>
mov    -0x40(%rbp),%edi
lea    -0x12c(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
jmp    16cc <main+0x48c>
lea    -0xb5(%rbp),%rdi
lea    0x9eb(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
je     1694 <main+0x454>
lea    -0xb5(%rbp),%rdi
lea    0x9d3(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    16c7 <main+0x487>
lea    0x9c3(%rip),%rdi
call   1080 <printf@plt>
movl   $0x1,-0x118(%rbp)
mov    -0x40(%rbp),%edi
lea    -0x118(%rbp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
xor    %edi,%edi
call   1150 <exit@plt>
jmp    16cc <main+0x48c>
jmp    16d1 <main+0x491>
jmp    16d6 <main+0x496>
jmp    1347 <main+0x107>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
mov    %rsi,%rbp
mov    0x2d85(%rip),%rax
mov    (%rax),%edi
mov    0x2d5c(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1160 <socket@plt>
cmp    $0xffffffff,%eax
jne    127b <main+0x3b>
lea    0xd87(%rip),%rdi
jmp    12ca <main+0x8a>
mov    %eax,%ebx
mov    0x8(%rbp),%rdi
call   1130 <atoi@plt>
mov    %eax,0x38(%rsp)
movq   $0x0,0x30(%rsp)
lea    0x30(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   1100 <bind@plt>
cmp    $0xffffffff,%eax
jne    12b2 <main+0x72>
lea    0xd67(%rip),%rdi
jmp    12ca <main+0x8a>
mov    %ebx,%edi
mov    $0x1,%esi
call   10d0 <listen@plt>
cmp    $0xffffffff,%eax
jne    12d9 <main+0x99>
lea    0xd5b(%rip),%rdi
call   1090 <printf@plt>
mov    $0x1,%edi
call   1150 <exit@plt>
movl   $0x10,0x2c(%rsp)
lea    0x60(%rsp),%rsi
lea    0x2c(%rsp),%rdx
mov    %ebx,%edi
call   1120 <accept@plt>
mov    %eax,%r12d
lea    0x70(%rsp),%rbp
lea    0x13(%rsp),%r15
lea    0x40(%rsp),%r14
mov    %eax,0x28(%rsp)
jmp    1377 <main+0x137>
nopw   0x0(%rax,%rax,1)
lea    0xd1f(%rip),%rdi
call   1070 <system@plt>
movl   $0x0,0x20(%rsp)
lea    0xd10(%rip),%rbx
mov    %rbx,%rdi
lea    0x18(%rsp),%rsi
call   10b0 <stat@plt>
mov    0x18(%rsp),%eax
mov    %eax,0xc(%rsp)
mov    %r12d,%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    0x2c7d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1110 <open@plt>
mov    0xc(%rsp),%ecx
mov    %r12d,%edi
mov    %eax,%esi
xor    %edx,%edx
call   10f0 <sendfile@plt>
mov    %r12d,%edi
mov    %rbp,%rsi
mov    $0x64,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <recv@plt>
mov    %rbp,%rdi
lea    0xcb6(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   10e0 <sscanf@plt>
movzwl 0x13(%rsp),%eax
xor    $0x736c,%eax
movzbl 0x15(%rsp),%ecx
or     %ax,%cx
je     1310 <main+0xd0>
cmpl   $0x746567,0x13(%rsp)
je     1400 <main+0x1c0>
cmpl   $0x747570,0x13(%rsp)
je     147a <main+0x23a>
cmpl   $0x657962,0x13(%rsp)
je     15b1 <main+0x371>
mov    0x13(%rsp),%eax
mov    $0x74697571,%ecx
xor    %ecx,%eax
movzbl 0x17(%rsp),%ecx
or     %eax,%ecx
jne    1377 <main+0x137>
jmp    15b1 <main+0x371>
cs nopw 0x0(%rax,%rax,1)
xor    %r15d,%r15d
mov    %rbp,%rdi
lea    0xc3c(%rip),%rsi
mov    %r14,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   10e0 <sscanf@plt>
mov    %r14,%rdi
lea    0x18(%rsp),%rsi
call   10b0 <stat@plt>
mov    0x2baa(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1446 <main+0x206>
mov    0x18(%rsp),%r15d
mov    %r15d,0xc(%rsp)
mov    %r12d,%edi
lea    0xc(%rsp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
lea    0x13(%rsp),%r15
je     1377 <main+0x137>
mov    %r12d,%edi
mov    %ebx,%esi
jmp    1370 <main+0x130>
movl   $0x0,0x24(%rsp)
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x70,%rdi
lea    0xbb0(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10e0 <sscanf@plt>
mov    $0x4,%edx
mov    %r12d,%edi
lea    0xc(%rsp),%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <recv@plt>
movl   $0x1,0x20(%rsp)
mov    0x2afe(%rip),%rbp
mov    0x0(%rbp),%esi
mov    0x2b24(%rip),%rbx
or     (%rbx),%esi
mov    0x2ad3(%rip),%rax
or     (%rax),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,%r15d
cmp    $0xffffffff,%eax
jne    1554 <main+0x314>
mov    0x2ab3(%rip),%r13
lea    0xb4e(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %r14,%rdi
call   1060 <strlen@plt>
cltq
lea    (%rsp,%rax,1),%rdi
add    $0x40,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1140 <sprintf@plt>
mov    0x0(%rbp),%esi
or     (%rbx),%esi
or     0x0(%r13),%esi
mov    %r14,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1110 <open@plt>
cmp    $0xffffffff,%eax
je     1510 <main+0x2d0>
mov    %eax,%r15d
mov    0x28(%rsp),%r12d
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
call   10c0 <malloc@plt>
mov    %rax,%r13
mov    %r12d,%edi
mov    %rax,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
xor    %eax,%eax
call   1030 <recv@plt>
mov    0xc(%rsp),%edx
mov    %r15d,%edi
mov    %r13,%rsi
call   1050 <write@plt>
mov    %eax,0x24(%rsp)
mov    %r15d,%edi
call   10a0 <close@plt>
mov    %r12d,%edi
lea    0x24(%rsp),%rsi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
lea    0x70(%rsp),%rbp
lea    0x13(%rsp),%r15
jmp    1377 <main+0x137>
lea    0xaa6(%rip),%rdi
call   1040 <puts@plt>
movl   $0x1,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %r12d,%edi
mov    $0x4,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
xor    %edi,%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"Socket creation failed\00"
@.str.1 = [14 x i8] c"Binding error\00"
@.str.2 = [14 x i8] c"Listen failed\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [15 x i8] c"ls > temps.txt\00"
@.str.6 = [10 x i8] c"temps.txt\00"
@O_RDONLY = global i32 0
@.str.7 = [4 x i8] c"get\00"
@.str.8 = [5 x i8] c"%s%s\00"
@.str.9 = [4 x i8] c"put\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [4 x i8] c"bye\00"
@.str.12 = [5 x i8] c"quit\00"
@.str.13 = [23 x i8] c"FTP server quitting..\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca %struct.stat
%9 = alloca i32
%10 = alloca i32
%11 = alloca [100 x i8]
%12 = alloca [5 x i8]
%13 = alloca [20 x i8]
%14 = alloca [50 x i8]
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32
%21 = alloca i32
%22 = alloca i32
%23 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = load i32, i32* @AF_INET
%25 = load i32, i32* @SOCK_STREAM
%26 = call i32 @socket(i32 %24, i32 %25, i32 0)
store i32 %26, i32* %9
%27 = load i32, i32* %9
%28 = icmp eq i32 %27, -1
br i1 %28, label %29, label %32
29: ; preds = %2
%30 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%31 = call i32 @exit(i32 1)
unreachable
32: ; preds = %2
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 1
%35 = load i8*, i8** %34
%36 = call i32 @atoi(i8* %35)
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 1
store i32 %36, i32* %37
%38 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i32 0, i32 0
%39 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %38, i32 0, i32 0
store i64 0, i64* %39
%40 = load i32, i32* %9
%41 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%42 = call i32 @bind(i32 %40, %struct.sockaddr* %41, i32 16)
store i32 %42, i32* %15
%43 = load i32, i32* %15
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %48
45: ; preds = %32
%46 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %32
%49 = load i32, i32* %9
%50 = call i32 @listen(i32 %49, i32 1)
store i32 %50, i32* %15
%51 = load i32, i32* %15
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %48
%54 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%55 = call i32 @exit(i32 1)
unreachable
56: ; preds = %48
store i32 16, i32* %18
%57 = load i32, i32* %9
%58 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%59 = call i32 @accept(i32 %57, %struct.sockaddr* %58, i32* %18)
store i32 %59, i32* %10
store i32 1, i32* %16
br label %60
60: ; preds = %56, %178
%61 = load i32, i32* %10
%62 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%63 = call i32 (i32, ...) @recv(i32 %61, i8* %62, i32 100, i32 0)
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%65 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%66 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %64, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %65)
%67 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%68 = call i32 @strcmp(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%69 = icmp ne i32 %68, 0
br i1 %69, label %83, label %70
70: ; preds = %60
%71 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %16
%72 = call i32 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), %struct.stat* %8)
%73 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%74 = load i32, i32* %73
store i32 %74, i32* %17
%75 = load i32, i32* %10
%76 = call i32 @send(i32 %75, i32* %17, i32 4, i32 0)
%77 = load i32, i32* @O_RDONLY
%78 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %77)
store i32 %78, i32* %20
%79 = load i32, i32* %10
%80 = load i32, i32* %20
%81 = load i32, i32* %17
%82 = call i32 @sendfile(i32 %79, i32 %80, i32* null, i32 %81)
br label %178
83: ; preds = %60
%84 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%85 = call i32 @strcmp(i8* %84, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0))
%86 = icmp ne i32 %85, 0
br i1 %86, label %113, label %87
87: ; preds = %83
%88 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%89 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%90 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%91 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %88, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %89, i8* %90)
%92 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%93 = call i32 @stat(i8* %92, %struct.stat* %8)
%94 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%95 = load i32, i32* @O_RDONLY
%96 = call i32 (i8*, i32, ...) @open(i8* %94, i32 %95)
store i32 %96, i32* %20
%97 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%98 = load i32, i32* %97
store i32 %98, i32* %17
%99 = load i32, i32* %20
%100 = icmp eq i32 %99, -1
br i1 %100, label %101, label %102
101: ; preds = %87
store i32 0, i32* %17
br label %102
102: ; preds = %101, %87
%103 = load i32, i32* %10
%104 = call i32 @send(i32 %103, i32* %17, i32 4, i32 0)
%105 = load i32, i32* %17
%106 = icmp ne i32 %105, 0
br i1 %106, label %107, label %112
107: ; preds = %102
%108 = load i32, i32* %10
%109 = load i32, i32* %20
%110 = load i32, i32* %17
%111 = call i32 @sendfile(i32 %108, i32 %109, i32* null, i32 %110)
br label %112
112: ; preds = %107, %102
br label %177
113: ; preds = %83
%114 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%115 = call i32 @strcmp(i8* %114, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0))
%116 = icmp ne i32 %115, 0
br i1 %116, label %162, label %117
117: ; preds = %113
store i32 0, i32* %21
%118 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%119 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%120 = call i32 @strlen(i8* %119)
%121 = sext i32 %120 to i64
%122 = getelementptr inbounds i8, i8* %118, i64 %121
%123 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%124 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %122, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %123)
%125 = load i32, i32* %10
%126 = call i32 (i32, ...) @recv(i32 %125, i32* %17, i64 4, i32 0)
store i32 1, i32* %16
br label %127
127: ; preds = %117, %146
%128 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%129 = load i32, i32* @O_CREAT
%130 = load i32, i32* @O_EXCL
%131 = or i32 %129, %130
%132 = load i32, i32* @O_WRONLY
%133 = or i32 %131, %132
%134 = call i32 (i8*, i32, ...) @open(i8* %128, i32 %133, i32 438)
store i32 %134, i32* %20
%135 = load i32, i32* %20
%136 = icmp eq i32 %135, -1
br i1 %136, label %137, label %145
137: ; preds = %127
%138 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%139 = getelementptr inbounds [20 x i8], [20 x i8]* %13, i64 0, i64 0
%140 = call i32 @strlen(i8* %139)
%141 = sext i32 %140 to i64
%142 = getelementptr inbounds i8, i8* %138, i64 %141
%143 = load i32, i32* %16
%144 = call i32 @sprintf(i8* %142, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 %143)
br label %146
145: ; preds = %127
br label %147
146: ; preds = %137
br label %127
147: ; preds = %145
%148 = load i32, i32* %17
%149 = call i8* @malloc(i32 %148)
store i8* %149, i8** %23
%150 = load i32, i32* %10
%151 = load i8*, i8** %23
%152 = load i32, i32* %17
%153 = call i32 (i32, ...) @recv(i32 %150, i8* %151, i32 %152, i32 0)
%154 = load i32, i32* %20
%155 = load i8*, i8** %23
%156 = load i32, i32* %17
%157 = call i32 @write(i32 %154, i8* %155, i32 %156)
store i32 %157, i32* %21
%158 = load i32, i32* %20
%159 = call i32 @close(i32 %158)
%160 = load i32, i32* %10
%161 = call i32 @send(i32 %160, i32* %21, i32 4, i32 0)
br label %176
162: ; preds = %113
%163 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%164 = call i32 @strcmp(i8* %163, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0))
%165 = icmp ne i32 %164, 0
br i1 %165, label %166, label %170
166: ; preds = %162
%167 = getelementptr inbounds [5 x i8], [5 x i8]* %12, i64 0, i64 0
%168 = call i32 @strcmp(i8* %167, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0))
%169 = icmp ne i32 %168, 0
br i1 %169, label %175, label %170
170: ; preds = %166, %162
%171 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.13, i64 0, i64 0))
store i32 1, i32* %16
%172 = load i32, i32* %10
%173 = call i32 @send(i32 %172, i32* %16, i32 4, i32 0)
%174 = call i32 @exit(i32 0)
unreachable
175: ; preds = %166
br label %176
176: ; preds = %175, %147
br label %177
177: ; preds = %176, %112
br label %178
178: ; preds = %177, %70
br label %60
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.stat = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [23 x i8] c"Socket creation failed\00"
@.str.1 = [14 x i8] c"Binding error\00"
@.str.2 = [14 x i8] c"Listen failed\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [3 x i8] c"ls\00"
@.str.5 = [15 x i8] c"ls > temps.txt\00"
@.str.6 = [10 x i8] c"temps.txt\00"
@O_RDONLY = global i32 0
@.str.7 = [4 x i8] c"get\00"
@.str.8 = [5 x i8] c"%s%s\00"
@.str.9 = [4 x i8] c"put\00"
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@O_WRONLY = global i32 0
@.str.10 = [3 x i8] c"%d\00"
@.str.11 = [4 x i8] c"bye\00"
@.str.12 = [5 x i8] c"quit\00"
@str = [22 x i8] c"FTP server quitting..\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.stat
%6 = alloca [100 x i8]
%7 = alloca [5 x i8]
%8 = alloca [20 x i8]
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = bitcast %struct.sockaddr_in* %3 to i8*
%14 = bitcast %struct.sockaddr_in* %4 to i8*
%15 = bitcast %struct.stat* %5 to i8*
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %7, i64 0, i64 0
%18 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 0
%19 = bitcast i32* %9 to i8*
%20 = bitcast i32* %10 to i8*
%21 = bitcast i32* %11 to i8*
%22 = load i32, i32* @AF_INET
%23 = load i32, i32* @SOCK_STREAM
%24 = tail call i32 @socket(i32 %22, i32 %23, i32 0)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %2
%27 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%28 = tail call i32 @exit(i32 1)
unreachable
29: ; preds = %2
%30 = getelementptr inbounds i8*, i8** %1, i64 1
%31 = load i8*, i8** %30
%32 = tail call i32 @atoi(i8* %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %32, i32* %33
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i64 0, i64* %34
%35 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%36 = call i32 @bind(i32 %24, %struct.sockaddr* %35, i32 16)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %41
38: ; preds = %29
%39 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %29
%42 = call i32 @listen(i32 %24, i32 1)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %47
44: ; preds = %41
%45 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%46 = call i32 @exit(i32 1)
unreachable
47: ; preds = %41
store i32 16, i32* %11
%48 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%49 = call i32 @accept(i32 %24, %struct.sockaddr* %48, i32* %11)
%50 = bitcast i32* %12 to i8*
%51 = getelementptr inbounds %struct.stat, %struct.stat* %5, i64 0, i32 0
br label %52
52: ; preds = %82, %47
%53 = call i32 (i32, ...) @recv(i32 %49, i8* %16, i32 100, i32 0)
%54 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%55 = call i32 @bcmp(i8* dereferenceable(3) %17, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i64 3)
%56 = icmp eq i32 %55, 0
br i1 %56, label %57, label %66
57: ; preds = %52
%58 = call i32 @system(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %9
%59 = call i32 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), %struct.stat* %5)
%60 = load i32, i32* %51
store i32 %60, i32* %10
%61 = call i32 @send(i32 %49, i32* %10, i32 4, i32 0)
%62 = load i32, i32* @O_RDONLY
%63 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %62)
%64 = load i32, i32* %10
%65 = call i32 @sendfile(i32 %49, i32 %63, i32* null, i32 %64)
br label %82
66: ; preds = %52
%67 = call i32 @bcmp(i8* dereferenceable(4) %17, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i64 4)
%68 = icmp eq i32 %67, 0
br i1 %68, label %69, label %83
69: ; preds = %66
%70 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0), i8* %18, i8* %18)
%71 = call i32 @stat(i8* %18, %struct.stat* %5)
%72 = load i32, i32* @O_RDONLY
%73 = call i32 (i8*, i32, ...) @open(i8* %18, i32 %72)
%74 = load i32, i32* %51
%75 = icmp eq i32 %73, -1
%76 = select i1 %75, i32 0, i32 %74
store i32 %76, i32* %10
%77 = call i32 @send(i32 %49, i32* %10, i32 4, i32 0)
%78 = load i32, i32* %10
%79 = icmp eq i32 %78, 0
br i1 %79, label %82, label %80
80: ; preds = %69
%81 = call i32 @sendfile(i32 %49, i32 %73, i32* null, i32 %78)
br label %82
82: ; preds = %80, %69, %123, %111, %57
br label %52
83: ; preds = %66
%84 = call i32 @bcmp(i8* dereferenceable(4) %17, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.9, i64 0, i64 0), i64 4)
%85 = icmp eq i32 %84, 0
br i1 %85, label %86, label %120
86: ; preds = %83
store i32 0, i32* %12
%87 = call i32 @strlen(i8* %17)
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %88
%90 = call i32 (i8*, i8*, i8*, ...) @sscanf(i8* %89, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%91 = call i32 (i32, ...) @recv(i32 %49, i32* %10, i64 4, i32 0)
store i32 1, i32* %9
%92 = load i32, i32* @O_CREAT
%93 = load i32, i32* @O_EXCL
%94 = or i32 %93, %92
%95 = load i32, i32* @O_WRONLY
%96 = or i32 %94, %95
%97 = call i32 (i8*, i32, ...) @open(i8* %18, i32 %96, i32 438)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %111
99: ; preds = %86, %99
%100 = call i32 @strlen(i8* %18)
%101 = sext i32 %100 to i64
%102 = getelementptr inbounds [20 x i8], [20 x i8]* %8, i64 0, i64 %101
%103 = call i32 @sprintf(i8* %102, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.10, i64 0, i64 0), i32 1)
%104 = load i32, i32* @O_CREAT
%105 = load i32, i32* @O_EXCL
%106 = or i32 %105, %104
%107 = load i32, i32* @O_WRONLY
%108 = or i32 %106, %107
%109 = call i32 (i8*, i32, ...) @open(i8* %18, i32 %108, i32 438)
%110 = icmp eq i32 %109, -1
br i1 %110, label %99, label %111
111: ; preds = %99, %86
%112 = phi i32 [ %97, %86 ], [ %109, %99 ]
%113 = load i32, i32* %10
%114 = call i8* @malloc(i32 %113)
%115 = call i32 (i32, ...) @recv(i32 %49, i8* %114, i32 %113, i32 0)
%116 = load i32, i32* %10
%117 = call i32 @write(i32 %112, i8* %114, i32 %116)
store i32 %117, i32* %12
%118 = call i32 @close(i32 %112)
%119 = call i32 @send(i32 %49, i32* %12, i32 4, i32 0)
br label %82
120: ; preds = %83
%121 = call i32 @bcmp(i8* dereferenceable(4) %17, i8* dereferenceable(4) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.11, i64 0, i64 0), i64 4)
%122 = icmp eq i32 %121, 0
br i1 %122, label %126, label %123
123: ; preds = %120
%124 = call i32 @bcmp(i8* dereferenceable(5) %17, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i64 5)
%125 = icmp eq i32 %124, 0
br i1 %125, label %126, label %82
126: ; preds = %123, %120
%127 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
store i32 1, i32* %9
%128 = call i32 @send(i32 %49, i32* %9, i32 4, i32 0)
%129 = call i32 @exit(i32 0)
unreachable
}