#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_word_resp(char *, int, char *);
int /*<<< orphan*/ packet_unpack_word_req(char *, char *);
int sqlite_find_word(int /*<<< orphan*/ *, char *, char *);
int do_word(char *packet, sqlite3 *db) {
  int ret = 0;
  char word[1024];
  char explain[1024];
  packet_unpack_word_req(packet, word);
  ret = sqlite_find_word(db, word, explain);
  if (ret > 0) {
    ret = 0;
  } else if (0 == ret) {
    ret = 4;
  } else if (ret < 0) {
    ret = 2;
  }
  return packet_pack_word_resp(packet, ret, explain);
}


x86 assembly (clang, -O0):
<do_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x820,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1050 <packet_unpack_word_req@plt>
mov    -0x10(%rbp),%rdi
lea    -0x420(%rbp),%rsi
lea    -0x820(%rbp),%rdx
call   1030 <sqlite_find_word@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jle    118a <do_word+0x5a>
movl   $0x0,-0x14(%rbp)
jmp    11bc <do_word+0x8c>
xor    %eax,%eax
cmp    -0x14(%rbp),%eax
jne    11a1 <do_word+0x71>
movl   $0x4,-0x14(%rbp)
jmp    11b7 <do_word+0x87>
cmpl   $0x0,-0x14(%rbp)
jge    11b2 <do_word+0x82>
movl   $0x2,-0x14(%rbp)
jmp    11b7 <do_word+0x87>
jmp    11bc <do_word+0x8c>
mov    -0x8(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x820(%rbp),%rdx
call   1040 <packet_pack_word_resp@plt>
add    $0x820,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_word>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x808,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x400(%rsp),%r15
mov    %r15,%rsi
call   1050 <packet_unpack_word_req@plt>
mov    %rsp,%r12
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <sqlite_find_word@plt>
xor    %ecx,%ecx
xor    %edx,%edx
test   %eax,%eax
sete   %dl
lea    0x2(%rdx,%rdx,1),%esi
cmovg  %ecx,%esi
mov    %rbx,%rdi
mov    %r12,%rdx
call   1040 <packet_pack_word_resp@plt>
add    $0x808,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define i32 @do_word(i8* %0, i32* %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = call i32 @packet_unpack_word_req(i8* %0, i8* %5)
%8 = call i32 @sqlite_find_word(i32* %1, i8* %5, i8* %6)
%9 = icmp sgt i32 %8, 0
%10 = icmp eq i32 %8, 0
%11 = select i1 %10, i32 4, i32 2
%12 = select i1 %9, i32 0, i32 %11
%13 = call i32 @packet_pack_word_resp(i8* %0, i32 %12, i8* %6)
ret i32 %13
}