#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 */
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int recv_data(int, char *, int);
int /*<<< orphan*/ send_response(int, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int ftserve_recv_cmd(int sock_control, char *cmd, char *arg) {
  int rc = 200;
  char buffer[512];
  memset(buffer, 0, 512);
  memset(cmd, 0, 5);
  memset(arg, 0, 512);
  if ((recv_data(sock_control, buffer, sizeof(buffer))) == -1) {
    perror("recv error\n");
    return -1;
  }
  strncpy(cmd, buffer, 4);
  char *tmp = buffer + 5;
  strcpy(arg, tmp);
  if (strcmp(cmd, "QUIT") == 0) {
    rc = 221;
  } else if ((strcmp(cmd, "USER") == 0) || (strcmp(cmd, "PASS") == 0) ||
             (strcmp(cmd, "LIST") == 0) || (strcmp(cmd, "RETR") == 0)) {
    rc = 200;
  } else {
    rc = 502;
  }
  send_response(sock_control, rc);
  return rc;
}


x86 assembly (clang, -O0):
<ftserve_recv_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0xc8,-0x1c(%rbp)
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1070 <memset@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x200,%edx
call   1050 <recv_data@plt>
cmp    $0xffffffff,%eax
jne    11f5 <ftserve_recv_cmd+0x85>
lea    0xe1c(%rip),%rdi
call   1090 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12e3 <ftserve_recv_cmd+0x173>
mov    -0x10(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    -0x220(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x228(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x228(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdi
lea    0xdd5(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1252 <ftserve_recv_cmd+0xe2>
movl   $0xdd,-0x1c(%rbp)
jmp    12d2 <ftserve_recv_cmd+0x162>
mov    -0x10(%rbp),%rdi
lea    0xdb4(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12ba <ftserve_recv_cmd+0x14a>
mov    -0x10(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12ba <ftserve_recv_cmd+0x14a>
mov    -0x10(%rbp),%rdi
lea    0xd8a(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
je     12ba <ftserve_recv_cmd+0x14a>
mov    -0x10(%rbp),%rdi
lea    0xd75(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12c6 <ftserve_recv_cmd+0x156>
movl   $0xc8,-0x1c(%rbp)
jmp    12cd <ftserve_recv_cmd+0x15d>
movl   $0x1f6,-0x1c(%rbp)
jmp    12d2 <ftserve_recv_cmd+0x162>
mov    -0x8(%rbp),%edi
mov    -0x1c(%rbp),%esi
call   1060 <send_response@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftserve_recv_cmd>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdx,%rbp
mov    %rsi,%rbx
mov    %edi,%r14d
mov    %rsp,%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1070 <memset@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x200,%edx
call   1070 <memset@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x200,%edx
call   1050 <recv_data@plt>
cmp    $0xffffffff,%eax
je     1281 <ftserve_recv_cmd+0x111>
mov    %rsp,%rsi
mov    %rbx,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
lea    0x5(%rsp),%rsi
mov    %rbp,%rdi
call   1040 <strcpy@plt>
lea    0xe19(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1262 <ftserve_recv_cmd+0xf2>
lea    0xe0a(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
mov    $0xc8,%ebp
test   %rax,%rax
je     1267 <ftserve_recv_cmd+0xf7>
lea    0xdf6(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1267 <ftserve_recv_cmd+0xf7>
lea    0xde7(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
je     1267 <ftserve_recv_cmd+0xf7>
lea    0xdd8(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
mov    $0xc8,%eax
mov    $0x1f6,%ebp
cmove  %eax,%ebp
jmp    1267 <ftserve_recv_cmd+0xf7>
mov    $0xdd,%ebp
mov    %r14d,%edi
mov    %ebp,%esi
call   1060 <send_response@plt>
mov    %ebp,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd78(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1271 <ftserve_recv_cmd+0x101>

LLVM IR (-O0):
@.str = [12 x i8] c"recv error\0A\00"
@.str.1 = [5 x i8] c"QUIT\00"
@.str.2 = [5 x i8] c"USER\00"
@.str.3 = [5 x i8] c"PASS\00"
@.str.4 = [5 x i8] c"LIST\00"
@.str.5 = [5 x i8] c"RETR\00"
define i32 @ftserve_recv_cmd(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [512 x i8]
%10 = alloca i8*
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i32 200, i32* %8
%11 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%12 = call i32 @memset(i8* %11, i32 0, i32 512)
%13 = load i8*, i8** %6
%14 = call i32 @memset(i8* %13, i32 0, i32 5)
%15 = load i8*, i8** %7
%16 = call i32 @memset(i8* %15, i32 0, i32 512)
%17 = load i32, i32* %5
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%19 = call i32 @recv_data(i32 %17, i8* %18, i32 512)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %60
23: ; preds = %3
%24 = load i8*, i8** %6
%25 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%26 = call i32 @strncpy(i8* %24, i8* %25, i32 4)
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%28 = getelementptr inbounds i8, i8* %27, i64 5
store i8* %28, i8** %10
%29 = load i8*, i8** %7
%30 = load i8*, i8** %10
%31 = call i32 @strcpy(i8* %29, i8* %30)
%32 = load i8*, i8** %6
%33 = call i64 @strcmp(i8* %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %23
store i32 221, i32* %8
br label %55
36: ; preds = %23
%37 = load i8*, i8** %6
%38 = call i64 @strcmp(i8* %37, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%39 = icmp eq i64 %38, 0
br i1 %39, label %52, label %40
40: ; preds = %36
%41 = load i8*, i8** %6
%42 = call i64 @strcmp(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%43 = icmp eq i64 %42, 0
br i1 %43, label %52, label %44
44: ; preds = %40
%45 = load i8*, i8** %6
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %52, label %48
48: ; preds = %44
%49 = load i8*, i8** %6
%50 = call i64 @strcmp(i8* %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %53
52: ; preds = %48, %44, %40, %36
store i32 200, i32* %8
br label %54
53: ; preds = %48
store i32 502, i32* %8
br label %54
54: ; preds = %53, %52
br label %55
55: ; preds = %54, %35
%56 = load i32, i32* %5
%57 = load i32, i32* %8
%58 = call i32 @send_response(i32 %56, i32 %57)
%59 = load i32, i32* %8
store i32 %59, i32* %4
br label %60
60: ; preds = %55, %21
%61 = load i32, i32* %4
ret i32 %61
}

LLVM IR (-O2):
@.str = [12 x i8] c"recv error\0A\00"
@.str.1 = [5 x i8] c"QUIT\00"
@.str.2 = [5 x i8] c"USER\00"
@.str.3 = [5 x i8] c"PASS\00"
@.str.4 = [5 x i8] c"LIST\00"
@.str.5 = [5 x i8] c"RETR\00"
define i32 @ftserve_recv_cmd(i32 %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i32 @memset(i8* %5, i32 0, i32 512)
%7 = call i32 @memset(i8* %1, i32 0, i32 5)
%8 = call i32 @memset(i8* %2, i32 0, i32 512)
%9 = call i32 @recv_data(i32 %0, i8* %5, i32 512)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %35
13: ; preds = %3
%14 = call i32 @strncpy(i8* %1, i8* %5, i32 4)
%15 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 5
%16 = call i32 @strcpy(i8* %2, i8* %15)
%17 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %32, label %19
19: ; preds = %13
%20 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = icmp eq i64 %20, 0
br i1 %21, label %32, label %22
22: ; preds = %19
%23 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %32, label %25
25: ; preds = %22
%26 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
%27 = icmp eq i64 %26, 0
br i1 %27, label %32, label %28
28: ; preds = %25
%29 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%30 = icmp eq i64 %29, 0
%31 = select i1 %30, i32 200, i32 502
br label %32
32: ; preds = %28, %19, %22, %25, %13
%33 = phi i32 [ 221, %13 ], [ 200, %25 ], [ 200, %22 ], [ 200, %19 ], [ %31, %28 ]
%34 = call i32 @send_response(i32 %0, i32 %33)
br label %35
35: ; preds = %32, %11
%36 = phi i32 [ -1, %11 ], [ %33, %32 ]
ret i32 %36
}