#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_reg_resp(char *, int);
int /*<<< orphan*/ packet_unpack_reg_req(char *, char *, char *);
int sqlite_insert_user(int /*<<< orphan*/ *, char *, char *);
int do_register(char *packet, sqlite3 *db) {
  int ret = 0;
  char user_name[32];
  char password[32];
  packet_unpack_reg_req(packet, user_name, password);
  ret = sqlite_insert_user(db, user_name, password);
  if (ret > 0) {
    ret = 1;
  } else if (0 == ret) {
    ret = 0;
  } else if (ret < 0) {
    ret = 2;
  }
  return packet_pack_reg_resp(packet, ret);
}


x86 assembly (clang, -O0):
<do_register>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%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   1040 <packet_unpack_reg_req@plt>
mov    -0x10(%rbp),%rdi
lea    -0x40(%rbp),%rsi
lea    -0x60(%rbp),%rdx
call   1030 <sqlite_insert_user@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    1182 <do_register+0x52>
movl   $0x1,-0x14(%rbp)
jmp    11b4 <do_register+0x84>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    1199 <do_register+0x69>
movl   $0x0,-0x14(%rbp)
jmp    11af <do_register+0x7f>
cmpl   $0x0,-0x14(%rbp)
jge    11aa <do_register+0x7a>
movl   $0x2,-0x14(%rbp)
jmp    11af <do_register+0x7f>
jmp    11b4 <do_register+0x84>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1050 <packet_pack_reg_resp@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_register>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x20(%rsp),%r15
mov    %rsp,%r12
mov    %r15,%rsi
mov    %r12,%rdx
call   1040 <packet_unpack_reg_req@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <sqlite_insert_user@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
add    %ecx,%ecx
test   %eax,%eax
mov    $0x1,%esi
cmovle %ecx,%esi
mov    %rbx,%rdi
call   1050 <packet_pack_reg_resp@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @do_register(i8* %0, i32* %1) {
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = call i32 @packet_unpack_reg_req(i8* %0, i8* %5, i8* %6)
%8 = call i32 @sqlite_insert_user(i32* %1, i8* %5, i8* %6)
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i32 0, i32 2
%11 = icmp slt i32 %8, 1
%12 = select i1 %11, i32 %10, i32 1
%13 = call i32 @packet_pack_reg_resp(i8* %0, i32 %12)
ret i32 %13
}