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


x86 assembly (clang, -O0):
<ftp_reset>:
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_reset+0x3a>
jmp    1250 <ftp_reset+0x100>
mov    -0x4(%rbp),%edi
lea    0xe6c(%rip),%rsi
mov    $0x8,%edx
mov    $0x0,%al
call   1070 <send_socket@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0xffffffff,-0x414(%rbp)
jne    11cd <ftp_reset+0x7d>
lea    0xe4f(%rip),%rdi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1250 <ftp_reset+0x100>
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    1250 <ftp_reset+0x100>
lea    -0x410(%rbp),%rdi
lea    0xe2f(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1231 <ftp_reset+0xe1>
lea    0xe19(%rip),%rdi
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    124b <ftp_reset+0xfb>
lea    0xe26(%rip),%rdi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1250 <ftp_reset+0x100>
jmp    1250 <ftp_reset+0x100>
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_reset>:
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     11dc <ftp_reset+0x9c>
lea    0xe9c(%rip),%rsi
mov    $0x8,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1060 <send_socket@plt>
cmp    $0xffffffff,%eax
je     11aa <ftp_reset+0x6a>
mov    %rsp,%rsi
mov    $0x400,%edx
mov    %ebx,%edi
xor    %eax,%eax
call   1040 <read_socket@plt>
test   %eax,%eax
jle    11dc <ftp_reset+0x9c>
mov    $0x3533,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
xor    $0x30,%ecx
or     %ax,%cx
je     11c7 <ftp_reset+0x87>
lea    0xeb6(%rip),%rdi
jmp    11ce <ftp_reset+0x8e>
lea    0xe58(%rip),%rdi
lea    0xe71(%rip),%rsi
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
jmp    1030 <printf@plt>
lea    0xe69(%rip),%rdi
lea    0xe54(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [9 x i8] c"REST 0\0D\0A\00"
@.str.1 = [32 x i8] c"###%s(),send ftp reset failed!\0A\00"
@__func__.ftp_reset = [10 x i8] c"ftp_reset\00"
@.str.2 = [4 x i8] c"350\00"
@.str.3 = [39 x i8] c"###%s(),send commend reset sucessful!\0A\00"
@.str.4 = [36 x i8] c"###%s(),send commend reset failed!\0A\00"
define void @ftp_reset(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 %31
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 ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 8)
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 ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.ftp_reset, i64 0, i64 0))
br label %31
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 %31
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 ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.ftp_reset, i64 0, i64 0))
br label %30
28: ; preds = %22
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.ftp_reset, i64 0, i64 0))
br label %31
30: ; preds = %26
br label %31
31: ; preds = %8, %14, %28, %30, %16
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"REST 0\0D\0A\00"
@.str.1 = [32 x i8] c"###%s(),send ftp reset failed!\0A\00"
@__func__.ftp_reset = [10 x i8] c"ftp_reset\00"
@.str.2 = [4 x i8] c"350\00"
@.str.3 = [39 x i8] c"###%s(),send commend reset sucessful!\0A\00"
@.str.4 = [36 x i8] c"###%s(),send commend reset failed!\0A\00"
define void @ftp_reset(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 ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i64 8)
%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 ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.ftp_reset, 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 ([39 x i8], [39 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.ftp_reset, i64 0, i64 0))
br label %20
18: ; preds = %13
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @__func__.ftp_reset, i64 0, i64 0))
br label %20
20: ; preds = %10, %16, %1, %18, %8
ret void
}