#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 SQLITE_OK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int /*<<< orphan*/ sqlite3_free_table(char **);
int sqlite3_get_table(int /*<<< orphan*/ *, char *, char ***, int *, int *,
                      char **);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int sqlite_find_word(sqlite3 *db, const char *word, char *explain) {
  int ret = 0;
  char password[128];
  char sql[512];
  char *errmsg;
  char **resultp;
  int row, column;
  sprintf(sql, "select explain from words where word='%s';", word);
  ret = sqlite3_get_table(db, sql, &resultp, &row, &column, &errmsg);
  if (ret != SQLITE_OK) {
    fprintf(stderr, "Fail to sqlite3_get_table : %s\n", errmsg);
    ret = -1;
    goto exit;
  }
  if (row >= 1) {
    strcpy(explain, resultp[1]);
  }
  ret = row;
  sqlite3_free_table(resultp);
exit:
  return ret;
}


x86 assembly (clang, -O0):
<sqlite_find_word>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2c0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x2a0(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe80(%rip),%rsi
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x2a0(%rbp),%rsi
lea    -0x2b0(%rbp),%rdx
lea    -0x2b4(%rbp),%rcx
lea    -0x2b8(%rbp),%r8
lea    -0x2a8(%rbp),%r9
call   1040 <sqlite3_get_table@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e2a(%rip),%rcx
cmp    (%rcx),%eax
je     11ee <sqlite_find_word+0x9e>
mov    0x2e0b(%rip),%rax
mov    (%rax),%edi
mov    -0x2a8(%rbp),%rdx
lea    0xe4e(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
jmp    1224 <sqlite_find_word+0xd4>
cmpl   $0x1,-0x2b4(%rbp)
jl     120f <sqlite_find_word+0xbf>
mov    -0x18(%rbp),%rdi
mov    -0x2b0(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x2b4(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x2b0(%rbp),%rdi
call   1060 <sqlite3_free_table@plt>
mov    -0x1c(%rbp),%eax
add    $0x2c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sqlite_find_word>:
push   %rbp
push   %r14
push   %rbx
sub    $0x220,%rsp
mov    %rdx,%r14
mov    %rsi,%rdx
mov    %rdi,%rbp
lea    0xe95(%rip),%rsi
lea    0x20(%rsp),%rbx
mov    %rbx,%rdi
call   1070 <sprintf@plt>
lea    0x8(%rsp),%rdx
lea    0x4(%rsp),%rcx
lea    0x1c(%rsp),%r8
lea    0x10(%rsp),%r9
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1040 <sqlite3_get_table@plt>
mov    0x2e4a(%rip),%rcx
cmp    (%rcx),%eax
jne    11cb <sqlite_find_word+0x7b>
mov    0x4(%rsp),%ebp
test   %ebp,%ebp
jle    11bf <sqlite_find_word+0x6f>
mov    0x8(%rsp),%rax
mov    0x8(%rax),%rsi
mov    %r14,%rdi
call   1030 <strcpy@plt>
mov    0x4(%rsp),%ebp
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_free_table@plt>
jmp    11ea <sqlite_find_word+0x9a>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    0x10(%rsp),%rdx
lea    0xe4b(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x220,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [43 x i8] c"select explain from words where word='%s';\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Fail to sqlite3_get_table : %s\0A\00"
define i32 @sqlite_find_word(i32* %0, i8* %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca [128 x i8]
%9 = alloca [512 x i8]
%10 = alloca i8*
%11 = alloca i8**
%12 = alloca i32
%13 = alloca i32
store i32* %0, i32** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 0, i32* %7
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%15 = load i8*, i8** %5
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %4
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%19 = call i32 @sqlite3_get_table(i32* %17, i8* %18, i8*** %11, i32* %12, i32* %13, i8** %10)
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = load i32, i32* @SQLITE_OK
%22 = icmp ne i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %3
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %10
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %25)
store i32 -1, i32* %7
br label %40
27: ; preds = %3
%28 = load i32, i32* %12
%29 = icmp sge i32 %28, 1
br i1 %29, label %30, label %36
30: ; preds = %27
%31 = load i8*, i8** %6
%32 = load i8**, i8*** %11
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @strcpy(i8* %31, i8* %34)
br label %36
36: ; preds = %30, %27
%37 = load i32, i32* %12
store i32 %37, i32* %7
%38 = load i8**, i8*** %11
%39 = call i32 @sqlite3_free_table(i8** %38)
br label %40
40: ; preds = %36, %23
%41 = load i32, i32* %7
ret i32 %41
}

LLVM IR (-O2):
@.str = [43 x i8] c"select explain from words where word='%s';\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [32 x i8] c"Fail to sqlite3_get_table : %s\0A\00"
define i32 @sqlite_find_word(i32* %0, i8* %1, i8* %2) {
%4 = alloca [512 x i8]
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i32
%8 = alloca i32
%9 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%10 = bitcast i8** %5 to i8*
%11 = bitcast i8*** %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = bitcast i32* %8 to i8*
%14 = call i32 @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str, i64 0, i64 0), i8* %1)
%15 = call i32 @sqlite3_get_table(i32* %0, i8* %9, i8*** %6, i32* %7, i32* %8, i8** %5)
%16 = load i32, i32* @SQLITE_OK
%17 = icmp eq i32 %15, %16
br i1 %17, label %22, label %18
18: ; preds = %3
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %5
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %35
22: ; preds = %3
%23 = load i32, i32* %7
%24 = icmp sgt i32 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i8**, i8*** %6
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @strcpy(i8* %2, i8* %28)
%30 = load i32, i32* %7
br label %31
31: ; preds = %25, %22
%32 = phi i32 [ %30, %25 ], [ %23, %22 ]
%33 = load i8**, i8*** %6
%34 = call i32 @sqlite3_free_table(i8** %33)
br label %35
35: ; preds = %31, %18
%36 = phi i32 [ -1, %18 ], [ %32, %31 ]
ret i32 %36
}