long long ftp_get_file_size(int sockfd, char *filename) {
  char sendbuf[1024] = {'\0'};
  char recvbuf[1024] = {'\0'};
  int ret = -1;
  long long file_size = -1;
  if (sockfd < 0) {
    return -1;
  }
  sprintf(sendbuf, "SIZE %s\r\n", filename);
  ret = send_socket(sockfd, sendbuf, strlen(sendbuf));
  if (ret == -1) {
    printf("###%s(),send ftp type failed!\n", __func__);
    return -1;
  }
  ret = read_socket(sockfd, recvbuf, sizeof(recvbuf));
  if (ret > 0) {
    if (strncmp(recvbuf, "213", 3) == 0) {
      printf("###%s(),send commend type sucessful!\n", __func__);
      sscanf(recvbuf, "213 %lld", &file_size);
      return file_size;
    }
  }
  printf("###%s(),send commend type failed!\n", __func__);
  return -1;
}


x86 assembly (clang, -O0):
<ftp_get_file_size>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %edi,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x820(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movl   $0xffffffff,-0x824(%rbp)
ff ff ff
movq   $0xffffffffffffffff,-0x830(%rbp)
ff ff ff ff
cmpl   $0x0,-0xc(%rbp)
jge    11e4 <ftp_get_file_size+0x64>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1319 <ftp_get_file_size+0x199>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe0a(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x83c(%rbp)
lea    -0x420(%rbp),%rax
mov    %rax,-0x838(%rbp)
lea    -0x420(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x83c(%rbp),%edi
mov    -0x838(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1090 <send_socket@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0xffffffff,-0x824(%rbp)
jne    126c <ftp_get_file_size+0xec>
lea    0xdb9(%rip),%rdi
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
jmp    1319 <ftp_get_file_size+0x199>
mov    -0xc(%rbp),%edi
lea    -0x820(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1060 <read_socket@plt>
mov    %eax,-0x824(%rbp)
cmpl   $0x0,-0x824(%rbp)
jle    12fc <ftp_get_file_size+0x17c>
lea    -0x820(%rbp),%rdi
lea    0xd98(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12f7 <ftp_get_file_size+0x177>
lea    0xd82(%rip),%rdi
lea    0xd65(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x820(%rbp),%rdi
lea    0xd8c(%rip),%rsi
lea    -0x830(%rbp),%rdx
mov    $0x0,%al
call   1080 <sscanf@plt>
mov    -0x830(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1319 <ftp_get_file_size+0x199>
jmp    12fc <ftp_get_file_size+0x17c>
lea    0xd6b(%rip),%rdi
lea    0xd1f(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0xffffffffffffffff,-0x8(%rbp)
ff
mov    -0x8(%rbp),%rax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ftp_get_file_size>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r15
mov    %edi,%ebp
lea    0x410(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
lea    0x10(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
movq   $0xffffffffffffffff,0x8(%rsp)
ff ff
mov    $0xffffffffffffffff,%r14
test   %ebp,%ebp
js     1242 <ftp_get_file_size+0xd2>
lea    0xe3a(%rip),%rsi
lea    0x410(%rsp),%rbx
mov    %rbx,%rdi
mov    %r15,%rdx
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1080 <send_socket@plt>
cmp    $0xffffffff,%eax
je     122d <ftp_get_file_size+0xbd>
lea    0x10(%rsp),%rsi
mov    $0x400,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <read_socket@plt>
test   %eax,%eax
jle    1224 <ftp_get_file_size+0xb4>
mov    $0x3132,%eax
xor    0x10(%rsp),%eax
movzbl 0x12(%rsp),%ecx
xor    $0x33,%ecx
or     %ax,%cx
je     1253 <ftp_get_file_size+0xe3>
lea    0xe43(%rip),%rdi
jmp    1234 <ftp_get_file_size+0xc4>
lea    0xdd6(%rip),%rdi
lea    0xdee(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rax
add    $0x818,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xde5(%rip),%rdi
lea    0xdc8(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdf6(%rip),%rsi
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rdx
xor    %eax,%eax
call   1070 <sscanf@plt>
mov    0x8(%rsp),%r14
jmp    1242 <ftp_get_file_size+0xd2>

LLVM IR (-O0):
@.str = [10 x i8] c"SIZE %s\0D\0A\00"
@.str.1 = [31 x i8] c"###%s(),send ftp type failed!\0A\00"
@__func__.ftp_get_file_size = [18 x i8] c"ftp_get_file_size\00"
@.str.2 = [4 x i8] c"213\00"
@.str.3 = [38 x i8] c"###%s(),send commend type sucessful!\0A\00"
@.str.4 = [9 x i8] c"213 %lld\00"
@.str.5 = [35 x i8] c"###%s(),send commend type failed!\0A\00"
define i64 @ftp_get_file_size(i32 %0, i8* %1) {
%3 = alloca i64
%4 = alloca i32
%5 = alloca i8*
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca i32
%9 = alloca i64
store i32 %0, i32* %4
store i8* %1, i8** %5
%10 = bitcast [1024 x i8]* %6 to i8*
%11 = bitcast [1024 x i8]* %7 to i8*
store i32 -1, i32* %8
store i64 -1, i64* %9
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %2
store i64 -1, i64* %3
br label %46
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%17 = load i8*, i8** %5
%18 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = load i32, i32* %4
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @send_socket to i32 (i32, i8*, i64, ...)*)(i32 %19, i8* %20, i64 %22)
store i32 %23, i32* %8
%24 = load i32, i32* %8
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %28
26: ; preds = %15
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__func__.ftp_get_file_size, i64 0, i64 0))
store i64 -1, i64* %3
br label %46
28: ; preds = %15
%29 = load i32, i32* %4
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%31 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read_socket to i32 (i32, i8*, i64, ...)*)(i32 %29, i8* %30, i64 1024)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %44
34: ; preds = %28
%35 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%36 = call i32 @strncmp(i8* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i64 3)
%37 = icmp eq i32 %36, 0
br i1 %37, label %38, label %43
38: ; preds = %34
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__func__.ftp_get_file_size, i64 0, i64 0))
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%41 = call i32 (i8*, i8*, ...) @sscanf(i8* %40, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i64* %9)
%42 = load i64, i64* %9
store i64 %42, i64* %3
br label %46
43: ; preds = %34
br label %44
44: ; preds = %43, %28
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @__func__.ftp_get_file_size, i64 0, i64 0))
store i64 -1, i64* %3
br label %46
46: ; preds = %44, %38, %26, %14
%47 = load i64, i64* %3
ret i64 %47
}

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