#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 */
typedef int /*<<< orphan*/ sqlite3;

/* Variables and functions */
int packet_pack_login_resp(char *, int);
int /*<<< orphan*/ packet_unpack_login_req(char *, char *, char *);
int sqlite_find_user(int /*<<< orphan*/ *, char *, char *);
scalar_t__ strcmp(char *, char *);
int do_login(char *packet, sqlite3 *db) {
  int ret = 0;
  char user_name[32];
  char password[32];
  char tmp[32];
  packet_unpack_login_req(packet, user_name, password);
  ret = sqlite_find_user(db, user_name, tmp);
  if (ret > 0) {
    if (strcmp(tmp, password) == 0) {
      ret = 0;
    } else {
      ret = 3;
    }
  } else if (0 == ret) {
    ret = 3;
  } else if (ret < 0) {
    ret = 2;
  }
  return packet_pack_login_resp(packet, ret);
}


x86 assembly (clang, -O0):
<do_login>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1060 <packet_unpack_login_req@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x80(%rbp),%rdx
call   1030 <sqlite_find_user@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    11b8 <do_login+0x78>
lea    -0x80(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
jne    11ac <do_login+0x6c>
movl   $0x0,-0x14(%rbp)
jmp    11b3 <do_login+0x73>
movl   $0x3,-0x14(%rbp)
jmp    11ea <do_login+0xaa>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11cf <do_login+0x8f>
movl   $0x3,-0x14(%rbp)
jmp    11e5 <do_login+0xa5>
cmpl   $0x0,-0x14(%rbp)
jge    11e0 <do_login+0xa0>
movl   $0x2,-0x14(%rbp)
jmp    11e5 <do_login+0xa5>
jmp    11ea <do_login+0xaa>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <packet_pack_login_resp@plt>
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_login>:
push   %r15
push   %r14
push   %rbx
sub    $0x60,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x40(%rsp),%r15
lea    0x20(%rsp),%rdx
mov    %r15,%rsi
call   1060 <packet_unpack_login_req@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1030 <sqlite_find_user@plt>
test   %eax,%eax
jle    118d <do_login+0x4d>
mov    %rsp,%rdi
lea    0x20(%rsp),%rsi
call   1040 <strcmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
lea    (%rcx,%rcx,2),%esi
jmp    1196 <do_login+0x56>
sete   %al
movzbl %al,%esi
or     $0x2,%esi
mov    %r14,%rdi
call   1050 <packet_pack_login_resp@plt>
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @do_login(i8* %0, i32* %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%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 @packet_unpack_login_req(i8* %0, i8* %6, i8* %7)
%10 = call i32 @sqlite_find_user(i32* %1, i8* %6, i8* %8)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = call i64 @strcmp(i8* %8, i8* %7)
%14 = icmp eq i64 %13, 0
%15 = select i1 %14, i32 0, i32 3
br label %19
16: ; preds = %2
%17 = icmp eq i32 %10, 0
%18 = select i1 %17, i32 3, i32 2
br label %19
19: ; preds = %16, %12
%20 = phi i32 [ %15, %12 ], [ %18, %16 ]
%21 = call i32 @packet_pack_login_resp(i8* %0, i32 %20)
ret i32 %21
}