#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 */

/* Variables and functions */
int /*<<< orphan*/ login_input(char *, char *);
int /*<<< orphan*/ packet_disp_err(int);
int packet_pack_login_req(char *, char *, char *);
int packet_unpack_login_resp(char *);
int recv_packet(int, char *);
int send_fix_len(int, char *, int);
int do_login(int sockfd) {
  int ret = 0;
  char name[32];
  char password[32];
  char packet[1024];
  login_input(name, password);
  ret = packet_pack_login_req(packet, name, password);
  ret = send_fix_len(sockfd, packet, ret);
  if (-1 == ret) {
    goto exit;
  }
  ret = recv_packet(sockfd, packet);
  if (ret <= 0) {
    goto exit;
  }
  ret = packet_unpack_login_resp(packet);
  if (0 == ret) {
    ret = 1;
  } else {
    packet_disp_err(ret);
    ret = 2;
  }
exit:
  return ret;
}


x86 assembly (clang, -O0):
<do_login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1040 <login_input@plt>
lea    -0x450(%rbp),%rdi
lea    -0x30(%rbp),%rsi
lea    -0x50(%rbp),%rdx
call   1070 <packet_pack_login_req@plt>
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x450(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <send_fix_len@plt>
mov    %eax,-0x8(%rbp)
mov    $0xffffffff,%eax
cmp    -0x8(%rbp),%eax
jne    11c1 <do_login+0x61>
jmp    121c <do_login+0xbc>
mov    -0x4(%rbp),%edi
lea    -0x450(%rbp),%rsi
call   1080 <recv_packet@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jg     11e2 <do_login+0x82>
jmp    121c <do_login+0xbc>
lea    -0x450(%rbp),%rdi
call   1050 <packet_unpack_login_resp@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jne    1208 <do_login+0xa8>
movl   $0x1,-0x8(%rbp)
jmp    1217 <do_login+0xb7>
mov    -0x8(%rbp),%edi
call   1060 <packet_disp_err@plt>
movl   $0x2,-0x8(%rbp)
jmp    121c <do_login+0xbc>
mov    -0x8(%rbp),%eax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_login>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x448,%rsp
mov    %edi,%ebx
lea    0x20(%rsp),%r14
mov    %rsp,%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1040 <login_input@plt>
lea    0x40(%rsp),%r12
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
call   1070 <packet_pack_login_req@plt>
mov    %ebx,%edi
mov    %r12,%rsi
mov    %eax,%edx
call   1030 <send_fix_len@plt>
cmp    $0xffffffff,%eax
je     11d3 <do_login+0x73>
lea    0x40(%rsp),%rsi
mov    %ebx,%edi
call   1080 <recv_packet@plt>
test   %eax,%eax
jle    11df <do_login+0x7f>
lea    0x40(%rsp),%rdi
call   1050 <packet_unpack_login_resp@plt>
test   %eax,%eax
je     11da <do_login+0x7a>
mov    %eax,%edi
call   1060 <packet_disp_err@plt>
mov    $0x2,%eax
jmp    11df <do_login+0x7f>
mov    $0xffffffff,%eax
jmp    11df <do_login+0x7f>
mov    $0x1,%eax
add    $0x448,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @do_login(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca [1024 x i8]
store i32 %0, i32* %2
store i32 0, i32* %3
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%9 = call i32 @login_input(i8* %7, i8* %8)
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%13 = call i32 @packet_pack_login_req(i8* %10, i8* %11, i8* %12)
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%16 = load i32, i32* %3
%17 = call i32 @send_fix_len(i32 %14, i8* %15, i32 %16)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = icmp eq i32 -1, %18
br i1 %19, label %20, label %21
20: ; preds = %1
br label %38
21: ; preds = %1
%22 = load i32, i32* %2
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%24 = call i32 @recv_packet(i32 %22, i8* %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = icmp sle i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %21
br label %38
28: ; preds = %21
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%30 = call i32 @packet_unpack_login_resp(i8* %29)
store i32 %30, i32* %3
%31 = load i32, i32* %3
%32 = icmp eq i32 0, %31
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 1, i32* %3
br label %37
34: ; preds = %28
%35 = load i32, i32* %3
%36 = call i32 @packet_disp_err(i32 %35)
store i32 2, i32* %3
br label %37
37: ; preds = %34, %33
br label %38
38: ; preds = %37, %27, %20
%39 = load i32, i32* %3
ret i32 %39
}

LLVM IR (-O2):
define i32 @do_login(i32 %0) {
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%8 = call i32 @login_input(i8* %5, i8* %6)
%9 = call i32 @packet_pack_login_req(i8* %7, i8* %5, i8* %6)
%10 = call i32 @send_fix_len(i32 %0, i8* %7, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %20, label %12
12: ; preds = %1
%13 = call i32 @recv_packet(i32 %0, i8* %7)
%14 = icmp slt i32 %13, 1
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = call i32 @packet_unpack_login_resp(i8* %7)
%17 = icmp eq i32 %16, 0
br i1 %17, label %20, label %18
18: ; preds = %15
%19 = call i32 @packet_disp_err(i32 %16)
br label %20
20: ; preds = %15, %18, %12, %1
%21 = phi i32 [ -1, %1 ], [ %13, %12 ], [ 2, %18 ], [ 1, %15 ]
ret i32 %21
}