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

/* Variables and functions */
#define SQLITE_DONE 128
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ log_message(char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
scalar_t__ sqlite3_prepare_v2(int /*<<< orphan*/ *, char const *, int,
                              int /*<<< orphan*/ **, int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int dao_easy_exec(sqlite3 *db, const char *sql) {
  sqlite3_stmt *stmt;
  int rc = 0;
  if (sqlite3_prepare_v2(db, sql, -1, &stmt, 0) != SQLITE_OK) {
    log_message("[ERROR][%d-%d-%d %d:%d:%d] ",
                "Could not prepare SQL statement: %s\r\n", sqlite3_errmsg(db));
    rc = 1;
    goto finalize;
  }
  while ((rc = sqlite3_step(stmt)) != SQLITE_DONE) {
    switch (rc) {
    case SQLITE_DONE:
      break;
    default:
      log_message("[ERROR][%d-%d-%d %d:%d:%d] ",
                  "Error while executing SQL statement: %s\r\n",
                  sqlite3_errmsg(db));
      rc = 1;
      goto finalize;
      break;
    }
  }
  rc = 0;
finalize:
  sqlite3_finalize(stmt);
  return rc;
}


x86 assembly (clang, -O0):
<dao_easy_exec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   1070 <sqlite3_prepare_v2@plt>
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%rax
je     11ba <dao_easy_exec+0x6a>
mov    -0x8(%rbp),%rdi
call   1030 <sqlite3_errmsg@plt>
mov    %eax,%edx
lea    0xe5e(%rip),%rdi
lea    0xe73(%rip),%rsi
call   1050 <log_message@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1224 <dao_easy_exec+0xd4>
jmp    11bf <dao_easy_exec+0x6f>
mov    -0x18(%rbp),%rdi
call   1040 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x80,%eax
je     121d <dao_easy_exec+0xcd>
mov    -0x1c(%rbp),%eax
sub    $0x80,%eax
jne    11ee <dao_easy_exec+0x9e>
jmp    11e9 <dao_easy_exec+0x99>
jmp    1218 <dao_easy_exec+0xc8>
mov    -0x8(%rbp),%rdi
call   1030 <sqlite3_errmsg@plt>
mov    %eax,%edx
lea    0xe00(%rip),%rdi
lea    0xe3b(%rip),%rsi
call   1050 <log_message@plt>
movl   $0x1,-0x1c(%rbp)
jmp    1224 <dao_easy_exec+0xd4>
jmp    11bf <dao_easy_exec+0x6f>
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_finalize@plt>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dao_easy_exec>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    %rsp,%rcx
xor    %ebp,%ebp
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1070 <sqlite3_prepare_v2@plt>
mov    0x2e79(%rip),%rcx
cmp    (%rcx),%rax
jne    118d <dao_easy_exec+0x3d>
mov    (%rsp),%rdi
call   1040 <sqlite3_step@plt>
cmp    $0x80,%eax
je     11b2 <dao_easy_exec+0x62>
lea    0xeb7(%rip),%rbp
jmp    1194 <dao_easy_exec+0x44>
lea    0xe88(%rip),%rbp
mov    %rbx,%rdi
call   1030 <sqlite3_errmsg@plt>
lea    0xe5d(%rip),%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <log_message@plt>
mov    $0x1,%ebp
mov    (%rsp),%rdi
call   1060 <sqlite3_finalize@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_OK = global i64 0
@.str = [28 x i8] c"[ERROR][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [38 x i8] c"Could not prepare SQL statement: %s\0D\0A\00"
@.str.2 = [42 x i8] c"Error while executing SQL statement: %s\0D\0A\00"
define i32 @dao_easy_exec(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %6
%7 = load i32*, i32** %3
%8 = load i8*, i8** %4
%9 = call i64 @sqlite3_prepare_v2(i32* %7, i8* %8, i32 -1, i32** %5, i32 0)
%10 = load i64, i64* @SQLITE_OK
%11 = icmp ne i64 %9, %10
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i32*, i32** %3
%14 = call i32 @sqlite3_errmsg(i32* %13)
%15 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i32 %14)
store i32 1, i32* %6
br label %30
16: ; preds = %2
br label %17
17: ; preds = %28, %16
%18 = load i32*, i32** %5
%19 = call i32 @sqlite3_step(i32* %18)
store i32 %19, i32* %6
%20 = icmp ne i32 %19, 128
br i1 %20, label %21, label %29
21: ; preds = %17
%22 = load i32, i32* %6
switch i32 %22, label %24 [
i32 128, label %23
]
23: ; preds = %21
br label %28
24: ; preds = %21
%25 = load i32*, i32** %3
%26 = call i32 @sqlite3_errmsg(i32* %25)
%27 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i32 %26)
store i32 1, i32* %6
br label %30
28: ; preds = %23
br label %17
29: ; preds = %17
store i32 0, i32* %6
br label %30
30: ; preds = %29, %24, %12
%31 = load i32*, i32** %5
%32 = call i32 @sqlite3_finalize(i32* %31)
%33 = load i32, i32* %6
ret i32 %33
}

LLVM IR (-O2):
@SQLITE_OK = global i64 0
@.str = [28 x i8] c"[ERROR][%d-%d-%d %d:%d:%d] \00"
@.str.1 = [38 x i8] c"Could not prepare SQL statement: %s\0D\0A\00"
@.str.2 = [42 x i8] c"Error while executing SQL statement: %s\0D\0A\00"
define i32 @dao_easy_exec(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = call i64 @sqlite3_prepare_v2(i32* %0, i8* %1, i32 -1, i32** %3, i32 0)
%6 = load i64, i64* @SQLITE_OK
%7 = icmp eq i64 %5, %6
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32*, i32** %3
%10 = call i32 @sqlite3_step(i32* %9)
%11 = icmp eq i32 %10, 128
br i1 %11, label %16, label %12
12: ; preds = %8, %2
%13 = phi i8* [ getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), %8 ]
%14 = call i32 @sqlite3_errmsg(i32* %0)
%15 = call i32 @log_message(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %13, i32 %14)
br label %16
16: ; preds = %12, %8
%17 = phi i32 [ 0, %8 ], [ 1, %12 ]
%18 = load i32*, i32** %3
%19 = call i32 @sqlite3_finalize(i32* %18)
ret i32 %17
}