#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 */
int SQLITE_OK;
int /*<<< orphan*/ evlog(int, char *, char const *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char const *, int,
                       int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite_error(int, int /*<<< orphan*/ *, char *,
                                char const *);
sqlite3_stmt *prepareStatement(sqlite3 *db, const char *sql) {
  int res;
  sqlite3_stmt *statement;
  evlog(3, "Preparing statement %s", sql);
  res = sqlite3_prepare_v2(db, sql, -1, &statement, NULL);
  if (res != SQLITE_OK)
    sqlite_error(res, db, "statement preparation failed: %s", sql);
  return statement;
}


x86 assembly (clang, -O0):
<prepareStatement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdx
mov    $0x3,%edi
lea    0xeb0(%rip),%rsi
call   1040 <evlog@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xffffffff,%edx
lea    -0x20(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1050 <sqlite3_prepare_v2@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%eax
je     119c <prepareStatement+0x6c>
mov    -0x14(%rbp),%edi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    0xe80(%rip),%rdx
call   1030 <sqlite_error@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepareStatement>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0xebf(%rip),%rsi
mov    $0x3,%edi
mov    %rbx,%rdx
call   1040 <evlog@plt>
mov    %rsp,%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   1050 <sqlite3_prepare_v2@plt>
mov    0x2e7d(%rip),%rcx
cmp    (%rcx),%eax
je     1183 <prepareStatement+0x53>
lea    0xea1(%rip),%rdx
mov    %eax,%edi
mov    %r14,%rsi
mov    %rbx,%rcx
call   1030 <sqlite_error@plt>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Preparing statement %s\00"
@SQLITE_OK = global i32 0
@.str.1 = [33 x i8] c"statement preparation failed: %s\00"
define i32* @prepareStatement(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
%7 = load i8*, i8** %4
%8 = call i32 @evlog(i32 3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = load i32*, i32** %3
%10 = load i8*, i8** %4
%11 = call i32 @sqlite3_prepare_v2(i32* %9, i8* %10, i32 -1, i32** %6, i32* null)
store i32 %11, i32* %5
%12 = load i32, i32* %5
%13 = load i32, i32* @SQLITE_OK
%14 = icmp ne i32 %12, %13
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* %5
%17 = load i32*, i32** %3
%18 = load i8*, i8** %4
%19 = call i32 @sqlite_error(i32 %16, i32* %17, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %18)
br label %20
20: ; preds = %15, %2
%21 = load i32*, i32** %6
ret i32* %21
}

LLVM IR (-O2):
@.str = [23 x i8] c"Preparing statement %s\00"
@SQLITE_OK = global i32 0
@.str.1 = [33 x i8] c"statement preparation failed: %s\00"
define i32* @prepareStatement(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = tail call i32 @evlog(i32 3, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %1)
%6 = call i32 @sqlite3_prepare_v2(i32* %0, i8* %1, i32 -1, i32** %3, i32* null)
%7 = load i32, i32* @SQLITE_OK
%8 = icmp eq i32 %6, %7
br i1 %8, label %11, label %9
9: ; preds = %2
%10 = call i32 @sqlite_error(i32 %6, i32* %0, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %11
11: ; preds = %9, %2
%12 = load i32*, i32** %3
ret i32* %12
}