#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 sockaddr_in {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
void *atoi(char *);
int /*<<< orphan*/ bind_listen_socket(int, struct sockaddr_in *);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ get_client_control_sfd_and_info(int, int *,
                                                   struct sockaddr_in *);
int get_client_data_sfd_and_info(int, struct sockaddr_in *,
                                 struct sockaddr_in *);
int get_listen_sfd();
int /*<<< orphan*/ listen(int, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ send_file_if_available(char *, int, int);
int /*<<< orphan*/ send_file_listing(int, int);
int /*<<< orphan*/ send_unknown_command_received(int);
int /*<<< orphan*/ setup_server_address_struct(struct sockaddr_in *,
                                               unsigned long);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char **argv) {
  int listen_sfd = -1;
  int control_sfd = -1;
  int data_sfd = -1;
  unsigned long int listen_port_number = 0;
  struct sockaddr_in server_address;
  struct sockaddr_in client_address_control;
  struct sockaddr_in client_address_data;
  if (argc != 2) {
    printf("Incorrect number of arguments. Exiting...\n");
    printf("usage: ftserver [port_number]\n");
    return 0;
  }
  listen_port_number = atoi(argv[1]);
  if ((listen_port_number > 65535) || (listen_port_number < 1024)) {
    fprintf(stderr, "Port out of range! Please choose a different port! "
                    "Exiting...\n");
    exit(EXIT_FAILURE);
  }
  printf("########################################\n");
  printf("     Transfer Server - Version 1.0      \n");
  printf("       Written by Corwin Perren         \n");
  printf("########################################\n");
  listen_sfd = get_listen_sfd();
  setup_server_address_struct(&server_address, listen_port_number);
  bind_listen_socket(listen_sfd, &server_address);
  while (1) {
    int data_port;
    char control_read_buffer[1024];
    char command[3];
    char filename[1024];
    listen(listen_sfd, 1);
    get_client_control_sfd_and_info(listen_sfd, &control_sfd,
                                    &client_address_control);
    if (control_sfd < 0) {
      fprintf(stderr, "Client accept failed. Trying next "
                      "connection...\n");
    } else {
      printf("Client connected!\n");
      memset(control_read_buffer, '\0', 1024);
      read(control_sfd, control_read_buffer, 1024);
      data_port = atoi(control_read_buffer);
      printf("PORT: %d\n", data_port);
      write(control_sfd, "OK", 3);
      memset(control_read_buffer, '\0', 1024);
      memset(command, '\0', 3);
      read(control_sfd, control_read_buffer, 1024);
      strncpy(command, control_read_buffer, 2);
      printf("Command: %s\n", command);
      write(control_sfd, "OK", 3);
      if (strcmp(control_read_buffer, "-g") == 0) {
        memset(control_read_buffer, '\0', 1024);
        memset(filename, '\0', 1024);
        read(control_sfd, control_read_buffer, 1024);
        strncpy(filename, control_read_buffer, 1023);
        printf("Filename: %s\n\n", filename);
        write(control_sfd, "OK", 3);
      }
      data_sfd = get_client_data_sfd_and_info(
          data_port, &client_address_control, &client_address_data);
      if (strcmp(command, "-l") == 0) {
        send_file_listing(control_sfd, data_sfd);
      } else if (strcmp(command, "-g") == 0) {
        send_file_if_available(filename, control_sfd, data_sfd);
      } else {
        send_unknown_command_received(control_sfd);
      }
      printf("Client disconnected.\n");
      close(control_sfd);
      close(data_sfd);
    }
  }
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x860,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movl   $0xffffffff,-0x18(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1297 <main+0x67>
lea    0xd89(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xda6(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
xor    %eax,%eax
add    $0x860,%rsp
pop    %rbp
ret
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1130 <atoi@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffff,-0x28(%rbp)
ja     12c4 <main+0x94>
cmpq   $0x400,-0x28(%rbp)
jae    12e7 <main+0xb7>
mov    0x2d15(%rip),%rax
mov    (%rax),%edi
lea    0xd76(%rip),%rsi
call   10e0 <fprintf@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%edi
call   1140 <exit@plt>
lea    0xd9b(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdb7(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    0xd71(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    $0x0,%al
call   1100 <get_listen_sfd@plt>
mov    %eax,-0x14(%rbp)
mov    -0x28(%rbp),%rsi
lea    -0x30(%rbp),%rdi
call   1030 <setup_server_address_struct@plt>
mov    -0x14(%rbp),%edi
lea    -0x30(%rbp),%rsi
call   1040 <bind_listen_socket@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1110 <listen@plt>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1090 <get_client_control_sfd_and_info@plt>
cmpl   $0x0,-0x18(%rbp)
jge    1383 <main+0x153>
mov    0x2c70(%rip),%rax
mov    (%rax),%edi
lea    0xd8e(%rip),%rsi
call   10e0 <fprintf@plt>
jmp    159e <main+0x36e>
lea    0xdae(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10a0 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <read@plt>
lea    -0x450(%rbp),%rdi
call   1130 <atoi@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xd7a(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xd73(%rip),%rsi
mov    $0x3,%edx
call   1060 <write@plt>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10a0 <memset@plt>
lea    -0x453(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   10a0 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <read@plt>
lea    -0x453(%rbp),%rdi
lea    -0x450(%rbp),%rsi
mov    $0x2,%edx
call   1050 <strncpy@plt>
lea    -0x453(%rbp),%rsi
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xcf8(%rip),%rsi
mov    $0x3,%edx
call   1060 <write@plt>
lea    -0x450(%rbp),%rdi
lea    0xcf0(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    14ff <main+0x2cf>
lea    -0x450(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10a0 <memset@plt>
lea    -0x860(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10a0 <memset@plt>
mov    -0x18(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    $0x400,%edx
call   10c0 <read@plt>
lea    -0x860(%rbp),%rdi
lea    -0x450(%rbp),%rsi
mov    $0x3ff,%edx
call   1050 <strncpy@plt>
lea    -0x860(%rbp),%rsi
lea    0xc84(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
lea    0xc60(%rip),%rsi
mov    $0x3,%edx
call   1060 <write@plt>
mov    -0x44(%rbp),%edi
lea    -0x38(%rbp),%rsi
lea    -0x40(%rbp),%rdx
call   1120 <get_client_data_sfd_and_info@plt>
mov    %eax,-0x1c(%rbp)
lea    -0x453(%rbp),%rdi
lea    0xc57(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    153f <main+0x30f>
mov    -0x18(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   10f0 <send_file_listing@plt>
jmp    1580 <main+0x350>
lea    -0x453(%rbp),%rdi
lea    0xc18(%rip),%rsi
call   10d0 <strcmp@plt>
cmp    $0x0,%rax
jne    1573 <main+0x343>
lea    -0x860(%rbp),%rdi
mov    -0x18(%rbp),%esi
mov    -0x1c(%rbp),%edx
call   1070 <send_file_if_available@plt>
jmp    157b <main+0x34b>
mov    -0x18(%rbp),%edi
call   1150 <send_unknown_command_received@plt>
jmp    1580 <main+0x350>
lea    0xbf3(%rip),%rdi
mov    $0x0,%al
call   1080 <printf@plt>
mov    -0x18(%rbp),%edi
call   10b0 <close@plt>
mov    -0x1c(%rbp),%edi
call   10b0 <close@plt>
jmp    1342 <main+0x112>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x828,%rsp
movl   $0xffffffff,(%rsp)
cmp    $0x2,%edi
jne    14eb <main+0x2ab>
mov    0x8(%rsi),%rdi
call   1140 <atoi@plt>
cmp    $0xffff,%rax
ja     1517 <main+0x2d7>
mov    %rax,%rbx
cmp    $0x3ff,%rax
jbe    1517 <main+0x2d7>
lea    0xe65(%rip),%rbp
mov    %rbp,%rdi
call   1060 <puts@plt>
lea    0xe04(%rip),%rdi
call   1060 <puts@plt>
lea    0xe21(%rip),%rdi
call   1060 <puts@plt>
mov    %rbp,%rdi
call   1060 <puts@plt>
xor    %eax,%eax
call   1110 <get_listen_sfd@plt>
mov    %eax,%r13d
lea    0x18(%rsp),%rbp
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1030 <setup_server_address_struct@plt>
mov    %r13d,%edi
mov    %rbp,%rsi
call   1040 <bind_listen_socket@plt>
lea    0x10(%rsp),%r15
lea    0x420(%rsp),%rbp
lea    0x5(%rsp),%r12
jmp    1315 <main+0xd5>
nopl   (%rax)
mov    (%rsp),%edi
mov    %ebx,%esi
call   1100 <send_file_listing@plt>
lea    0xe2b(%rip),%rdi
call   1060 <puts@plt>
mov    (%rsp),%edi
call   10c0 <close@plt>
mov    %ebx,%edi
call   10c0 <close@plt>
mov    %r13d,%edi
mov    $0x1,%esi
call   1120 <listen@plt>
mov    %r13d,%edi
mov    %rsp,%rsi
mov    %r15,%rdx
call   10a0 <get_client_control_sfd_and_info@plt>
cmpl   $0x0,(%rsp)
js     14c0 <main+0x280>
lea    0xdd9(%rip),%rdi
call   1060 <puts@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
mov    (%rsp),%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   10d0 <read@plt>
mov    %rbp,%rdi
call   1140 <atoi@plt>
mov    %rax,%r14
lea    0xcf9(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1090 <printf@plt>
mov    (%rsp),%edi
lea    0xcef(%rip),%rbx
mov    %rbx,%rsi
mov    $0x3,%edx
call   1070 <write@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   10b0 <memset@plt>
mov    (%rsp),%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   10d0 <read@plt>
mov    %r12,%rdi
mov    %rbp,%rsi
mov    $0x2,%edx
call   1050 <strncpy@plt>
lea    0xca0(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    (%rsp),%edi
mov    %rbx,%rsi
mov    $0x3,%edx
call   1070 <write@plt>
mov    %rbp,%rdi
lea    0xc89(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
jne    1473 <main+0x233>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   10b0 <memset@plt>
mov    (%rsp),%edi
mov    %rbp,%rsi
mov    $0x400,%edx
call   10d0 <read@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    $0x3ff,%edx
call   1050 <strncpy@plt>
lea    0xc38(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1090 <printf@plt>
mov    (%rsp),%edi
lea    0xc11(%rip),%rsi
mov    $0x3,%edx
call   1070 <write@plt>
mov    %r14d,%edi
mov    %r15,%rsi
lea    0x8(%rsp),%rdx
call   1130 <get_client_data_sfd_and_info@plt>
mov    %eax,%ebx
mov    %r12,%rdi
lea    0xc0d(%rip),%rsi
call   10e0 <strcmp@plt>
test   %rax,%rax
je     12f0 <main+0xb0>
mov    %r12,%rdi
lea    0xbe3(%rip),%rsi
call   10e0 <strcmp@plt>
mov    (%rsp),%esi
test   %rax,%rax
je     14da <main+0x29a>
mov    %esi,%edi
call   1160 <send_unknown_command_received@plt>
jmp    12fa <main+0xba>
mov    0x2b19(%rip),%rax
mov    (%rax),%edi
lea    0xb6f(%rip),%rsi
call   10f0 <fprintf@plt>
jmp    1315 <main+0xd5>
lea    0x20(%rsp),%rdi
mov    %ebx,%edx
call   1080 <send_file_if_available@plt>
jmp    12fa <main+0xba>
lea    0xc4f(%rip),%rdi
call   1060 <puts@plt>
lea    0xc6d(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
add    $0x828,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ac2(%rip),%rax
mov    (%rax),%edi
lea    0xad9(%rip),%rsi
call   10f0 <fprintf@plt>
mov    0x2aa5(%rip),%rax
mov    (%rax),%edi
call   1150 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
@.str = [43 x i8] c"Incorrect number of arguments. Exiting...\0A\00"
@.str.1 = [31 x i8] c"usage: ftserver [port_number]\0A\00"
@stderr = global i32 0
@.str.2 = [63 x i8] c"Port out of range! Please choose a different port! Exiting...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [42 x i8] c"########################################\0A\00"
@.str.4 = [42 x i8] c" Transfer Server - Version 1.0 \0A\00"
@.str.5 = [42 x i8] c" Written by Corwin Perren \0A\00"
@.str.6 = [49 x i8] c"Client accept failed. Trying next connection...\0A\00"
@.str.7 = [19 x i8] c"Client connected!\0A\00"
@.str.8 = [10 x i8] c"PORT: %d\0A\00"
@.str.9 = [3 x i8] c"OK\00"
@.str.10 = [13 x i8] c"Command: %s\0A\00"
@.str.11 = [3 x i8] c"-g\00"
@.str.12 = [15 x i8] c"Filename: %s\0A\0A\00"
@.str.13 = [3 x i8] c"-l\00"
@.str.14 = [22 x i8] c"Client disconnected.\0A\00"
@EXIT_SUCCESS = global i32 0
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 i64
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_in
%12 = alloca %struct.sockaddr_in
%13 = alloca i32
%14 = alloca [1024 x i8]
%15 = alloca [3 x i8]
%16 = alloca [1024 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
store i32 -1, i32* %7
store i32 -1, i32* %8
store i64 0, i64* %9
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %22
19: ; preds = %2
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0))
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
ret i32 0
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i8* @atoi(i8* %25)
%27 = ptrtoint i8* %26 to i64
store i64 %27, i64* %9
%28 = load i64, i64* %9
%29 = icmp ugt i64 %28, 65535
br i1 %29, label %33, label %30
30: ; preds = %22
%31 = load i64, i64* %9
%32 = icmp ult i64 %31, 1024
br i1 %32, label %33, label %38
33: ; preds = %30, %22
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; preds = %30
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0))
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
%43 = call i32 (...) @get_listen_sfd()
store i32 %43, i32* %6
%44 = load i64, i64* %9
%45 = call i32 @setup_server_address_struct(%struct.sockaddr_in* %10, i64 %44)
%46 = load i32, i32* %6
%47 = call i32 @bind_listen_socket(i32 %46, %struct.sockaddr_in* %10)
br label %48
48: ; preds = %38, %133
%49 = load i32, i32* %6
%50 = call i32 @listen(i32 %49, i32 1)
%51 = load i32, i32* %6
%52 = call i32 @get_client_control_sfd_and_info(i32 %51, i32* %7, %struct.sockaddr_in* %11)
%53 = load i32, i32* %7
%54 = icmp slt i32 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %48
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
br label %133
58: ; preds = %48
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.7, i64 0, i64 0))
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%61 = call i32 @memset(i8* %60, i8 signext 0, i32 1024)
%62 = load i32, i32* %7
%63 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%64 = call i32 @read(i32 %62, i8* %63, i32 1024)
%65 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%66 = call i8* @atoi(i8* %65)
%67 = ptrtoint i8* %66 to i32
store i32 %67, i32* %13
%68 = load i32, i32* %13
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %68)
%70 = load i32, i32* %7
%71 = call i32 @write(i32 %70, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 3)
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%73 = call i32 @memset(i8* %72, i8 signext 0, i32 1024)
%74 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%75 = call i32 @memset(i8* %74, i8 signext 0, i32 3)
%76 = load i32, i32* %7
%77 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%78 = call i32 @read(i32 %76, i8* %77, i32 1024)
%79 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%80 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%81 = call i32 @strncpy(i8* %79, i8* %80, i32 2)
%82 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%83 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %82)
%84 = load i32, i32* %7
%85 = call i32 @write(i32 %84, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 3)
%86 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%87 = call i64 @strcmp(i8* %86, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%88 = icmp eq i64 %87, 0
br i1 %88, label %89, label %104
89: ; preds = %58
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%91 = call i32 @memset(i8* %90, i8 signext 0, i32 1024)
%92 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%93 = call i32 @memset(i8* %92, i8 signext 0, i32 1024)
%94 = load i32, i32* %7
%95 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%96 = call i32 @read(i32 %94, i8* %95, i32 1024)
%97 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %14, i64 0, i64 0
%99 = call i32 @strncpy(i8* %97, i8* %98, i32 1023)
%100 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %100)
%102 = load i32, i32* %7
%103 = call i32 @write(i32 %102, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 3)
br label %104
104: ; preds = %89, %58
%105 = load i32, i32* %13
%106 = call i32 @get_client_data_sfd_and_info(i32 %105, %struct.sockaddr_in* %11, %struct.sockaddr_in* %12)
store i32 %106, i32* %8
%107 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%108 = call i64 @strcmp(i8* %107, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%109 = icmp eq i64 %108, 0
br i1 %109, label %110, label %114
110: ; preds = %104
%111 = load i32, i32* %7
%112 = load i32, i32* %8
%113 = call i32 @send_file_listing(i32 %111, i32 %112)
br label %127
114: ; preds = %104
%115 = getelementptr inbounds [3 x i8], [3 x i8]* %15, i64 0, i64 0
%116 = call i64 @strcmp(i8* %115, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%117 = icmp eq i64 %116, 0
br i1 %117, label %118, label %123
118: ; preds = %114
%119 = getelementptr inbounds [1024 x i8], [1024 x i8]* %16, i64 0, i64 0
%120 = load i32, i32* %7
%121 = load i32, i32* %8
%122 = call i32 @send_file_if_available(i8* %119, i32 %120, i32 %121)
br label %126
123: ; preds = %114
%124 = load i32, i32* %7
%125 = call i32 @send_unknown_command_received(i32 %124)
br label %126
126: ; preds = %123, %118
br label %127
127: ; preds = %126, %110
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.14, i64 0, i64 0))
%129 = load i32, i32* %7
%130 = call i32 @close(i32 %129)
%131 = load i32, i32* %8
%132 = call i32 @close(i32 %131)
br label %133
133: ; preds = %127, %55
br label %48
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
@stderr = global i32 0
@.str.2 = [63 x i8] c"Port out of range! Please choose a different port! Exiting...\0A\00"
@EXIT_FAILURE = global i32 0
@.str.6 = [49 x i8] c"Client accept failed. Trying next connection...\0A\00"
@.str.8 = [10 x i8] c"PORT: %d\0A\00"
@.str.9 = [3 x i8] c"OK\00"
@.str.10 = [13 x i8] c"Command: %s\0A\00"
@.str.11 = [3 x i8] c"-g\00"
@.str.12 = [15 x i8] c"Filename: %s\0A\0A\00"
@.str.13 = [3 x i8] c"-l\00"
@EXIT_SUCCESS = global i32 0
@str.15 = [41 x i8] c" Transfer Server - Version 1.0 \00"
@str.16 = [41 x i8] c" Written by Corwin Perren \00"
@str.17 = [41 x i8] c"########################################\00"
@str.18 = [18 x i8] c"Client connected!\00"
@str.19 = [21 x i8] c"Client disconnected.\00"
@str.20 = [42 x i8] c"Incorrect number of arguments. Exiting...\00"
@str.21 = [30 x i8] c"usage: ftserver [port_number]\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_in
%7 = alloca [1024 x i8]
%8 = alloca [3 x i8]
%9 = alloca [1024 x i8]
%10 = bitcast i32* %3 to i8*
store i32 -1, i32* %3
%11 = bitcast %struct.sockaddr_in* %4 to i8*
%12 = bitcast %struct.sockaddr_in* %5 to i8*
%13 = bitcast %struct.sockaddr_in* %6 to i8*
%14 = icmp eq i32 %0, 2
br i1 %14, label %18, label %15
15: ; preds = %2
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.20, i64 0, i64 0))
%17 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.21, i64 0, i64 0))
ret i32 0
18: ; preds = %2
%19 = getelementptr inbounds i8*, i8** %1, i64 1
%20 = load i8*, i8** %19
%21 = tail call i8* @atoi(i8* %20)
%22 = icmp ugt i8* %21, inttoptr (i64 65535 to i8*)
%23 = icmp ult i8* %21, inttoptr (i64 1024 to i8*)
%24 = or i1 %22, %23
br i1 %24, label %25, label %30
25: ; preds = %18
%26 = load i32, i32* @stderr
%27 = tail call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
%29 = tail call i32 @exit(i32 %28)
unreachable
30: ; preds = %18
%31 = ptrtoint i8* %21 to i64
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.17, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.15, i64 0, i64 0))
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.16, i64 0, i64 0))
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.17, i64 0, i64 0))
%36 = tail call i32 (...) @get_listen_sfd()
%37 = call i32 @setup_server_address_struct(%struct.sockaddr_in* %4, i64 %31)
%38 = call i32 @bind_listen_socket(i32 %36, %struct.sockaddr_in* %4)
%39 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %8, i64 0, i64 0
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
br label %42
42: ; preds = %100, %30
%43 = call i32 @listen(i32 %36, i32 1)
%44 = call i32 @get_client_control_sfd_and_info(i32 %36, i32* %3, %struct.sockaddr_in* %5)
%45 = load i32, i32* %3
%46 = icmp slt i32 %45, 0
br i1 %46, label %47, label %50
47: ; preds = %42
%48 = load i32, i32* @stderr
%49 = call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.6, i64 0, i64 0))
br label %100
50: ; preds = %42
%51 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.18, i64 0, i64 0))
%52 = call i32 @memset(i8* %39, i8 signext 0, i32 1024)
%53 = load i32, i32* %3
%54 = call i32 @read(i32 %53, i8* %39, i32 1024)
%55 = call i8* @atoi(i8* %39)
%56 = ptrtoint i8* %55 to i64
%57 = trunc i64 %56 to i32
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i32 %57)
%59 = load i32, i32* %3
%60 = call i32 @write(i32 %59, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 3)
%61 = call i32 @memset(i8* %39, i8 signext 0, i32 1024)
%62 = call i32 @memset(i8* %40, i8 signext 0, i32 3)
%63 = load i32, i32* %3
%64 = call i32 @read(i32 %63, i8* %39, i32 1024)
%65 = call i32 @strncpy(i8* %40, i8* %39, i32 2)
%66 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i8* %40)
%67 = load i32, i32* %3
%68 = call i32 @write(i32 %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 3)
%69 = call i64 @strcmp(i8* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %80
71: ; preds = %50
%72 = call i32 @memset(i8* %39, i8 signext 0, i32 1024)
%73 = call i32 @memset(i8* %41, i8 signext 0, i32 1024)
%74 = load i32, i32* %3
%75 = call i32 @read(i32 %74, i8* %39, i32 1024)
%76 = call i32 @strncpy(i8* %41, i8* %39, i32 1023)
%77 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.12, i64 0, i64 0), i8* %41)
%78 = load i32, i32* %3
%79 = call i32 @write(i32 %78, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i32 3)
br label %80
80: ; preds = %71, %50
%81 = call i32 @get_client_data_sfd_and_info(i32 %57, %struct.sockaddr_in* %5, %struct.sockaddr_in* %6)
%82 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.13, i64 0, i64 0))
%83 = icmp eq i64 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %80
%85 = load i32, i32* %3
%86 = call i32 @send_file_listing(i32 %85, i32 %81)
br label %95
87: ; preds = %80
%88 = call i64 @strcmp(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0))
%89 = icmp eq i64 %88, 0
%90 = load i32, i32* %3
br i1 %89, label %91, label %93
91: ; preds = %87
%92 = call i32 @send_file_if_available(i8* %41, i32 %90, i32 %81)
br label %95
93: ; preds = %87
%94 = call i32 @send_unknown_command_received(i32 %90)
br label %95
95: ; preds = %91, %93, %84
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.19, i64 0, i64 0))
%97 = load i32, i32* %3
%98 = call i32 @close(i32 %97)
%99 = call i32 @close(i32 %81)
br label %100
100: ; preds = %95, %47
br label %42
}