int login(int sockfd) {
  char sendbuf[1024] = {'\0'};
  char recvbuf[1024] = {'\0'};
  int ret = -1;
  if (sockfd < 0) {
    return ret;
  }
  sprintf(sendbuf, "USER %s\r\n", "jsh");
  ret = send_socket(sockfd, sendbuf, strlen(sendbuf));
  if (ret == -1) {
    printf("###%s(),send username failed!\n", __func__);
    return -1;
  }
  ret = read_socket(sockfd, recvbuf, sizeof(recvbuf));
  if (ret > 0) {
    if (strncmp(recvbuf, "331", 3) == 0) {
      printf("###%s(),send commend username sucessful!\n", __func__);
    } else {
      printf("###%s(),send commend username failed!\n", __func__);
      return -1;
    }
  }
  sprintf(sendbuf, "PASS %s\r\n", "jsh");
  ret = send_socket(sockfd, sendbuf, strlen(sendbuf));
  if (ret == -1) {
    printf("###%s(),send userpasswd failed!\n", __func__);
    return -1;
  }
  ret = read_socket(sockfd, recvbuf, sizeof(recvbuf));
  if (ret > 0) {
    if (strncmp(recvbuf, "230", 3) == 0) {
      printf("###%s(),send commend userpasswd sucessful!\n", __func__);
    } else {
      printf("###%s(),send commend userpasswd failed!\n", __func__);
      return -1;
    }
  }
  return ret;
}


x86 assembly (clang, -O0):
<login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x840,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
movl   $0xffffffff,-0x814(%rbp)
ff ff ff
cmpl   $0x0,-0x8(%rbp)
jge    11c6 <login+0x56>
mov    -0x814(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13f7 <login+0x287>
lea    -0x410(%rbp),%rdi
lea    0xe2c(%rip),%rsi
lea    0xe2f(%rip),%rdx
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x824(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x820(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x824(%rbp),%edi
mov    -0x820(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1080 <send_socket@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0xffffffff,-0x814(%rbp)
jne    1250 <login+0xe0>
lea    0xdd8(%rip),%rdi
lea    0xdf0(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <login+0x287>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1060 <read_socket@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jle    12da <login+0x16a>
lea    -0x810(%rbp),%rdi
lea    0xdac(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12b4 <login+0x144>
lea    0xd96(%rip),%rdi
lea    0xd85(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    12d5 <login+0x165>
lea    0xda6(%rip),%rdi
lea    0xd6b(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <login+0x287>
jmp    12da <login+0x16a>
lea    -0x410(%rbp),%rdi
lea    0xda0(%rip),%rsi
lea    0xd1b(%rip),%rdx
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x834(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x830(%rbp)
lea    -0x410(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x834(%rbp),%edi
mov    -0x830(%rbp),%rsi
mov    %rax,%rdx
mov    $0x0,%al
call   1080 <send_socket@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0xffffffff,-0x814(%rbp)
jne    1364 <login+0x1f4>
lea    0xd48(%rip),%rdi
lea    0xcdc(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <login+0x287>
mov    -0x8(%rbp),%edi
lea    -0x810(%rbp),%rsi
mov    $0x400,%edx
mov    $0x0,%al
call   1060 <read_socket@plt>
mov    %eax,-0x814(%rbp)
cmpl   $0x0,-0x814(%rbp)
jle    13ee <login+0x27e>
lea    -0x810(%rbp),%rdi
lea    0xd18(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    13c8 <login+0x258>
lea    0xd02(%rip),%rdi
lea    0xc71(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    13e9 <login+0x279>
lea    0xd14(%rip),%rdi
lea    0xc57(%rip),%rsi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    13f7 <login+0x287>
jmp    13ee <login+0x27e>
mov    -0x814(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x840,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<login>:
push   %rbp
push   %r14
push   %rbx
sub    $0x800,%rsp
mov    %edi,%ebp
lea    0x400(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1060 <memset@plt>
test   %ebp,%ebp
js     120b <login+0xab>
lea    0xe65(%rip),%rsi
lea    0xe68(%rip),%rdx
lea    0x400(%rsp),%rbx
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <send_socket@plt>
mov    $0xffffffff,%ebx
cmp    $0xffffffff,%eax
je     1215 <login+0xb5>
mov    %rsp,%rsi
mov    $0x400,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <read_socket@plt>
test   %eax,%eax
jle    1236 <login+0xd6>
mov    $0x3333,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
xor    $0x31,%ecx
or     %ax,%cx
je     1221 <login+0xc1>
lea    0xe5b(%rip),%rdi
jmp    12bf <login+0x15f>
mov    $0xffffffff,%ebx
jmp    12cd <login+0x16d>
lea    0xdf2(%rip),%rdi
jmp    12bf <login+0x15f>
lea    0xe0f(%rip),%rdi
lea    0xdfe(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4b(%rip),%rsi
lea    0xdc6(%rip),%rdx
lea    0x400(%rsp),%r14
mov    %r14,%rdi
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1070 <send_socket@plt>
cmp    $0xffffffff,%eax
je     12b8 <login+0x158>
mov    %rsp,%rsi
mov    $0x400,%edx
mov    %ebp,%edi
xor    %eax,%eax
call   1050 <read_socket@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    12cd <login+0x16d>
mov    $0x3332,%eax
xor    (%rsp),%eax
movzbl 0x2(%rsp),%ecx
xor    $0x30,%ecx
or     %ax,%cx
lea    0xe14(%rip),%rax
lea    0xe39(%rip),%rdi
cmove  %rax,%rdi
mov    $0xffffffff,%eax
cmovne %eax,%ebx
jmp    12bf <login+0x15f>
lea    0xdd3(%rip),%rdi
lea    0xd67(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0x800,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [10 x i8] c"USER %s\0D\0A\00"
@.str.1 = [4 x i8] c"jsh\00"
@.str.2 = [31 x i8] c"###%s(),send username failed!\0A\00"
@__func__.login = [6 x i8] c"login\00"
@.str.3 = [4 x i8] c"331\00"
@.str.4 = [42 x i8] c"###%s(),send commend username sucessful!\0A\00"
@.str.5 = [39 x i8] c"###%s(),send commend username failed!\0A\00"
@.str.6 = [10 x i8] c"PASS %s\0D\0A\00"
@.str.7 = [33 x i8] c"###%s(),send userpasswd failed!\0A\00"
@.str.8 = [4 x i8] c"230\00"
@.str.9 = [44 x i8] c"###%s(),send commend userpasswd sucessful!\0A\00"
@.str.10 = [41 x i8] c"###%s(),send commend userpasswd failed!\0A\00"
define i32 @login(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca i32
store i32 %0, i32* %3
%7 = bitcast [1024 x i8]* %4 to i8*
%8 = bitcast [1024 x i8]* %5 to i8*
store i32 -1, i32* %6
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %1
%12 = load i32, i32* %6
store i32 %12, i32* %2
br label %69
13: ; preds = %1
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%15 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%19 = call i64 @strlen(i8* %18)
%20 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @send_socket to i32 (i32, i8*, i64, ...)*)(i32 %16, i8* %17, i64 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %25
23: ; preds = %13
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
store i32 -1, i32* %2
br label %69
25: ; preds = %13
%26 = load i32, i32* %3
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%28 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read_socket to i32 (i32, i8*, i64, ...)*)(i32 %26, i8* %27, i64 1024)
store i32 %28, i32* %6
%29 = load i32, i32* %6
%30 = icmp sgt i32 %29, 0
br i1 %30, label %31, label %40
31: ; preds = %25
%32 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%33 = call i32 @strncmp(i8* %32, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3)
%34 = icmp eq i32 %33, 0
br i1 %34, label %35, label %37
35: ; preds = %31
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
br label %39
37: ; preds = %31
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
store i32 -1, i32* %2
br label %69
39: ; preds = %35
br label %40
40: ; preds = %39, %25
%41 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%42 = call i32 (i8*, i8*, ...) @sprintf(i8* %41, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%43 = load i32, i32* %3
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%46 = call i64 @strlen(i8* %45)
%47 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @send_socket to i32 (i32, i8*, i64, ...)*)(i32 %43, i8* %44, i64 %46)
store i32 %47, i32* %6
%48 = load i32, i32* %6
%49 = icmp eq i32 %48, -1
br i1 %49, label %50, label %52
50: ; preds = %40
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
store i32 -1, i32* %2
br label %69
52: ; preds = %40
%53 = load i32, i32* %3
%54 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%55 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read_socket to i32 (i32, i8*, i64, ...)*)(i32 %53, i8* %54, i64 1024)
store i32 %55, i32* %6
%56 = load i32, i32* %6
%57 = icmp sgt i32 %56, 0
br i1 %57, label %58, label %67
58: ; preds = %52
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%60 = call i32 @strncmp(i8* %59, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 3)
%61 = icmp eq i32 %60, 0
br i1 %61, label %62, label %64
62: ; preds = %58
%63 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
br label %66
64: ; preds = %58
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
store i32 -1, i32* %2
br label %69
66: ; preds = %62
br label %67
67: ; preds = %66, %52
%68 = load i32, i32* %6
store i32 %68, i32* %2
br label %69
69: ; preds = %67, %64, %50, %37, %23, %11
%70 = load i32, i32* %2
ret i32 %70
}

LLVM IR (-O2):
@.str = [10 x i8] c"USER %s\0D\0A\00"
@.str.1 = [4 x i8] c"jsh\00"
@.str.2 = [31 x i8] c"###%s(),send username failed!\0A\00"
@__func__.login = [6 x i8] c"login\00"
@.str.3 = [4 x i8] c"331\00"
@.str.4 = [42 x i8] c"###%s(),send commend username sucessful!\0A\00"
@.str.5 = [39 x i8] c"###%s(),send commend username failed!\0A\00"
@.str.6 = [10 x i8] c"PASS %s\0D\0A\00"
@.str.7 = [33 x i8] c"###%s(),send userpasswd failed!\0A\00"
@.str.8 = [4 x i8] c"230\00"
@.str.9 = [44 x i8] c"###%s(),send commend userpasswd sucessful!\0A\00"
@.str.10 = [41 x i8] c"###%s(),send commend userpasswd failed!\0A\00"
define i32 @login(i32 %0) {
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = icmp slt i32 %0, 0
br i1 %6, label %37, label %7
7: ; preds = %1
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = call i64 @strlen(i8* %4)
%10 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @send_socket to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* %4, i64 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %33, label %12
12: ; preds = %7
%13 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read_socket to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* %5, i64 1024)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %12
%16 = call i32 @bcmp(i8* dereferenceable(3) %5, i8* dereferenceable(3) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i64 3)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %33
18: ; preds = %15
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
br label %20
20: ; preds = %18, %12
%21 = call i32 (i8*, i8*, ...) @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%22 = call i64 @strlen(i8* %4)
%23 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @send_socket to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* %4, i64 %22)
%24 = icmp eq i32 %23, -1
br i1 %24, label %33, label %25
25: ; preds = %20
%26 = call i32 (i32, i8*, i64, ...) bitcast (i32 (...)* @read_socket to i32 (i32, i8*, i64, ...)*)(i32 %0, i8* %5, i64 1024)
%27 = icmp sgt i32 %26, 0
br i1 %27, label %28, label %37
28: ; preds = %25
%29 = call i32 @bcmp(i8* dereferenceable(3) %5, i8* dereferenceable(3) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i64 3)
%30 = icmp eq i32 %29, 0
%31 = select i1 %30, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0), i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0)
%32 = select i1 %30, i32 %26, i32 -1
br label %33
33: ; preds = %28, %20, %15, %7
%34 = phi i8* [ getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), %7 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.5, i64 0, i64 0), %15 ], [ getelementptr inbounds ([33 x i8], [33 x i8]* @.str.7, i64 0, i64 0), %20 ], [ %31, %28 ]
%35 = phi i32 [ -1, %7 ], [ -1, %15 ], [ -1, %20 ], [ %32, %28 ]
%36 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) %34, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @__func__.login, i64 0, i64 0))
br label %37
37: ; preds = %33, %25, %1
%38 = phi i32 [ -1, %1 ], [ %26, %25 ], [ %35, %33 ]
ret i32 %38
}