void ftp_quit(int sockfd) {
  char recvbuf[1024] = {'\0'};
  int ret = -1;
  if (sockfd < 0) {
    return;
  }
  ret = send_socket(sockfd, "QUIT\r\n", strlen("QUIT\r\n"));
  if (ret == -1) {
    printf("###%s(),send ftp quit failed!\n", __func__);
    return;
  }
  ret = read_socket(sockfd, recvbuf, sizeof(recvbuf));
  if (ret > 0) {
    if (strncmp(recvbuf, "221", 3) == 0) {
      printf("###%s(),send commend quit sucessful!\n", __func__);
    } else {
      printf("###%s(),send commend quit failed:%s!\n", __func__, recvbuf);
      return;
    }
  }
}


x86 assembly (clang, -O0):
<ftp_quit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1060 <memset@plt>
movl   $0xffffffff,-0x414(%rbp)
ff ff ff
cmpl   $0x0,-0x4(%rbp)
jge    118a <ftp_quit+0x3a>
jmp    1257 <ftp_quit+0x107>
mov    -0x4(%rbp),%edi
lea    0xe6c(%rip),%rsi
mov    $0x6,%edx
mov    $0x0,%al
call   1070 <send_socket@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    11cd <ftp_quit+0x7d>
lea    0xe4d(%rip),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1257 <ftp_quit+0x107>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1050 <read_socket@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x0,-0x414(%rbp)
jle    1257 <ftp_quit+0x107>
lea    -0x410(%rbp),%rdi
lea    0xe2b(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1231 <ftp_quit+0xe1>
lea    0xe15(%rip),%rdi
lea    0xe01(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1252 <ftp_quit+0x102>
lea    -0x410(%rbp),%rdx
lea    0xe1a(%rip),%rdi
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1257 <ftp_quit+0x107>
jmp    1257 <ftp_quit+0x107>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_quit>:
push   %rbx
sub    $0x400,%rsp
mov    %edi,%ebx
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1050 <memset@plt>
test   %ebx,%ebx
js     11f1 <ftp_quit+0xb1>
lea    0xe98(%rip),%rsi
mov    $0x6,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <send_socket@plt>
cmp    $0xffffffff,%eax
je     11bf <ftp_quit+0x7f>
mov    %rsp,%rsi
mov    $0x400,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <read_socket@plt>
test   %eax,%eax
jle    11f1 <ftp_quit+0xb1>
mov    $0x3232,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
xor    $0x31,%ecx
or     %ax,%cx
je     11dc <ftp_quit+0x9c>
lea    0xead(%rip),%rdi
lea    0xe73(%rip),%rsi
mov    %rsp,%rdx
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11f1 <ftp_quit+0xb1>
lea    0xe41(%rip),%rdi
lea    0xe59(%rip),%rsi
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
jmp    1030 <printf@plt>
lea    0xe50(%rip),%rdi
lea    0xe3c(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [7 x i8] c"QUIT\0D\0A\00"
@.str.1 = [31 x i8] c"###%s(),send ftp quit failed!\0A\00"
@__func__.ftp_quit = [9 x i8] c"ftp_quit\00"
@.str.2 = [4 x i8] c"221\00"
@.str.3 = [38 x i8] c"###%s(),send commend quit sucessful!\0A\00"
@.str.4 = [38 x i8] c"###%s(),send commend quit failed:%s!\0A\00"
define void @ftp_quit(i32 %0) {
%2 = alloca i32
%3 = alloca [1024 x i8]
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast [1024 x i8]* %3 to i8*
store i32 -1, i32* %4
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %1
br label %32
9: ; preds = %1
%10 = load i32, i32* %2
%11 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @send_socket to i32 (i32, i8*, i64, ...)*)(i32 %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 6)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 %12, -1
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.ftp_quit, i64 0, i64 0))
br label %32
16: ; preds = %9
%17 = load i32, i32* %2
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%19 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read_socket to i32 (i32, i8*, i64, ...)*)(i32 %17, i8* %18, i64 1024)
store i32 %19, i32* %4
%20 = load i32, i32* %4
%21 = icmp sgt i32 %20, 0
br i1 %21, label %22, label %32
22: ; preds = %16
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%24 = call i32 @strncmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3)
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %28
26: ; preds = %22
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.ftp_quit, i64 0, i64 0))
br label %31
28: ; preds = %22
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.ftp_quit, i64 0, i64 0), i8* %29)
br label %32
31: ; preds = %26
br label %32
32: ; preds = %8, %14, %28, %31, %16
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"QUIT\0D\0A\00"
@.str.1 = [31 x i8] c"###%s(),send ftp quit failed!\0A\00"
@__func__.ftp_quit = [9 x i8] c"ftp_quit\00"
@.str.2 = [4 x i8] c"221\00"
@.str.3 = [38 x i8] c"###%s(),send commend quit sucessful!\0A\00"
@.str.4 = [38 x i8] c"###%s(),send commend quit failed:%s!\0A\00"
define void @ftp_quit(i32 %0) {
%2 = alloca [1024 x i8]
%3 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%4 = icmp slt i32 %0, 0
br i1 %4, label %20, label %5
5: ; preds = %1
%6 = tail call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @send_socket to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 6)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.ftp_quit, i64 0, i64 0))
br label %20
10: ; preds = %5
%11 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read_socket to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* %3, i64 1024)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %20
13: ; preds = %10
%14 = call i32 @bcmp(i8* dereferenceable(3) %3, i8* dereferenceable(3) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3)
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.ftp_quit, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__func__.ftp_quit, i64 0, i64 0), i8* %3)
br label %20
20: ; preds = %10, %16, %1, %18, %8
ret void
}