#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ftserve_list(int, int);
int ftserve_login(int);
int ftserve_recv_cmd(int, char *, char *);
int /*<<< orphan*/ ftserve_retr(int, int, char *);
int ftserve_start_data_conn(int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ send_response(int, int);
scalar_t__ strcmp(char *, char *);
void ftserve_process(int sock_controll) {
  int sock_data;
  char cmd[5];
  char arg[512];
  send_response(sock_controll, 220);
  if (ftserve_login(sock_controll) == 1) {
    send_response(sock_controll, 230);
  } else {
    send_response(sock_controll, 430);
  }
  while (1) {
    printf("Wait for command \n");
    int rc = ftserve_recv_cmd(sock_controll, cmd, arg);
    if ((rc < 0) || (rc == 221)) {
      break;
    }
    if (rc == 200) {
      if ((sock_data = ftserve_start_data_conn(sock_controll)) < 0) {
        close(sock_controll);
        exit(1);
      }
      if (strcmp(cmd, "LIST") == 0) {
        ftserve_list(sock_data, sock_controll);
      } else if (strcmp(cmd, "RETR") == 0) {
        ftserve_retr(sock_controll, sock_data, arg);
      }
      close(sock_data);
    }
  }
}


x86 assembly (clang, -O0):
<ftserve_process>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
mov    $0xdc,%esi
call   1030 <send_response@plt>
mov    -0x4(%rbp),%edi
call   10c0 <ftserve_login@plt>
cmp    $0x1,%eax
jne    11de <ftserve_process+0x3e>
mov    -0x4(%rbp),%edi
mov    $0xe6,%esi
call   1030 <send_response@plt>
jmp    11eb <ftserve_process+0x4b>
mov    -0x4(%rbp),%edi
mov    $0x1ae,%esi
call   1030 <send_response@plt>
jmp    11f0 <ftserve_process+0x50>
lea    0xe09(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
lea    -0xd(%rbp),%rsi
lea    -0x210(%rbp),%rdx
call   10a0 <ftserve_recv_cmd@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
jl     1232 <ftserve_process+0x92>
cmpl   $0xdd,-0x214(%rbp)
jne    1237 <ftserve_process+0x97>
jmp    12d5 <ftserve_process+0x135>
cmpl   $0xc8,-0x214(%rbp)
jne    12d0 <ftserve_process+0x130>
mov    -0x4(%rbp),%edi
call   1090 <ftserve_start_data_conn@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    126d <ftserve_process+0xcd>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    -0xd(%rbp),%rdi
lea    0xd9b(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    1297 <ftserve_process+0xf7>
mov    -0x8(%rbp),%edi
mov    -0x4(%rbp),%esi
call   1060 <ftserve_list@plt>
jmp    12c8 <ftserve_process+0x128>
lea    -0xd(%rbp),%rdi
lea    0xd76(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12c3 <ftserve_process+0x123>
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
lea    -0x210(%rbp),%rdx
call   1080 <ftserve_retr@plt>
jmp    12c8 <ftserve_process+0x128>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
jmp    11f0 <ftserve_process+0x50>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftserve_process>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x218,%rsp
mov    %edi,%ebx
mov    $0xdc,%esi
call   1040 <send_response@plt>
mov    %ebx,%edi
call   10c0 <ftserve_login@plt>
cmp    $0x1,%eax
mov    $0xe6,%eax
mov    $0x1ae,%esi
cmove  %eax,%esi
mov    %ebx,%edi
call   1040 <send_response@plt>
lea    0xe28(%rip),%rdi
call   1030 <puts@plt>
lea    0xb(%rsp),%rsi
lea    0x10(%rsp),%rdx
mov    %ebx,%edi
call   10a0 <ftserve_recv_cmd@plt>
test   %eax,%eax
js     12aa <ftserve_process+0x10a>
cmp    $0xdd,%eax
je     12aa <ftserve_process+0x10a>
lea    0xdee(%rip),%r14
lea    0xb(%rsp),%r15
lea    0x10(%rsp),%r13
lea    0xde7(%rip),%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
cmp    $0xc8,%eax
jne    128a <ftserve_process+0xea>
mov    %ebx,%edi
call   1090 <ftserve_start_data_conn@plt>
test   %eax,%eax
js     12bc <ftserve_process+0x11c>
mov    %eax,%r12d
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1278 <ftserve_process+0xd8>
mov    %r15,%rdi
lea    0xda6(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
jne    1282 <ftserve_process+0xe2>
mov    %ebx,%edi
mov    %r12d,%esi
mov    %r13,%rdx
call   1080 <ftserve_retr@plt>
jmp    1282 <ftserve_process+0xe2>
mov    %r12d,%edi
mov    %ebx,%esi
call   1060 <ftserve_list@plt>
mov    %r12d,%edi
call   1050 <close@plt>
mov    %rbp,%rdi
call   1030 <puts@plt>
mov    %ebx,%edi
mov    %r15,%rsi
mov    %r13,%rdx
call   10a0 <ftserve_recv_cmd@plt>
test   %eax,%eax
js     12aa <ftserve_process+0x10a>
cmp    $0xdd,%eax
jne    1230 <ftserve_process+0x90>
add    $0x218,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [19 x i8] c"Wait for command \0A\00"
@.str.1 = [5 x i8] c"LIST\00"
@.str.2 = [5 x i8] c"RETR\00"
define void @ftserve_process(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [5 x i8]
%5 = alloca [512 x i8]
%6 = alloca i32
store i32 %0, i32* %2
%7 = load i32, i32* %2
%8 = call i32 @send_response(i32 %7, i32 220)
%9 = load i32, i32* %2
%10 = call i32 @ftserve_login(i32 %9)
%11 = icmp eq i32 %10, 1
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = load i32, i32* %2
%14 = call i32 @send_response(i32 %13, i32 230)
br label %18
15: ; preds = %1
%16 = load i32, i32* %2
%17 = call i32 @send_response(i32 %16, i32 430)
br label %18
18: ; preds = %15, %12
br label %19
19: ; preds = %18, %63
%20 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%21 = load i32, i32* %2
%22 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%24 = call i32 @ftserve_recv_cmd(i32 %21, i8* %22, i8* %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp slt i32 %25, 0
br i1 %26, label %30, label %27
27: ; preds = %19
%28 = load i32, i32* %6
%29 = icmp eq i32 %28, 221
br i1 %29, label %30, label %31
30: ; preds = %27, %19
br label %64
31: ; preds = %27
%32 = load i32, i32* %6
%33 = icmp eq i32 %32, 200
br i1 %33, label %34, label %63
34: ; preds = %31
%35 = load i32, i32* %2
%36 = call i32 @ftserve_start_data_conn(i32 %35)
store i32 %36, i32* %3
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %34
%39 = load i32, i32* %2
%40 = call i32 @close(i32 %39)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %34
%43 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%44 = call i64 @strcmp(i8* %43, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %50
46: ; preds = %42
%47 = load i32, i32* %3
%48 = load i32, i32* %2
%49 = call i32 @ftserve_list(i32 %47, i32 %48)
br label %60
50: ; preds = %42
%51 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %50
%55 = load i32, i32* %2
%56 = load i32, i32* %3
%57 = getelementptr inbounds [512 x i8], [512 x i8]* %5, i64 0, i64 0
%58 = call i32 @ftserve_retr(i32 %55, i32 %56, i8* %57)
br label %59
59: ; preds = %54, %50
br label %60
60: ; preds = %59, %46
%61 = load i32, i32* %3
%62 = call i32 @close(i32 %61)
br label %63
63: ; preds = %60, %31
br label %19
64: ; preds = %30
ret void
}

LLVM IR (-O2):
@.str.1 = [5 x i8] c"LIST\00"
@.str.2 = [5 x i8] c"RETR\00"
@str = [18 x i8] c"Wait for command \00"
define void @ftserve_process(i32 %0) {
%2 = alloca [5 x i8]
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @send_response(i32 %0, i32 220)
%7 = tail call i32 @ftserve_login(i32 %0)
%8 = icmp eq i32 %7, 1
%9 = select i1 %8, i32 230, i32 430
%10 = tail call i32 @send_response(i32 %0, i32 %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%12 = call i32 @ftserve_recv_cmd(i32 %0, i8* %4, i8* %5)
%13 = icmp slt i32 %12, 0
%14 = icmp eq i32 %12, 221
%15 = or i1 %13, %14
br i1 %15, label %43, label %16
16: ; preds = %1, %37
%17 = phi i32 [ %39, %37 ], [ %12, %1 ]
%18 = icmp eq i32 %17, 200
br i1 %18, label %19, label %37
19: ; preds = %16
%20 = call i32 @ftserve_start_data_conn(i32 %0)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %19
%23 = call i32 @close(i32 %0)
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %19
%26 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = call i32 @ftserve_list(i32 %20, i32 %0)
br label %35
30: ; preds = %25
%31 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %30
%34 = call i32 @ftserve_retr(i32 %0, i32 %20, i8* %5)
br label %35
35: ; preds = %30, %33, %28
%36 = call i32 @close(i32 %20)
br label %37
37: ; preds = %16, %35
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%39 = call i32 @ftserve_recv_cmd(i32 %0, i8* %4, i8* %5)
%40 = icmp slt i32 %39, 0
%41 = icmp eq i32 %39, 221
%42 = or i1 %40, %41
br i1 %42, label %43, label %16
43: ; preds = %37, %1
ret void
}