#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_OK 128
int /*<<< orphan*/ logprintf(int, char *, char *, ...);
int /*<<< orphan*/ sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                       int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int /*<<< orphan*/ strlen(char *);
sqlite3_stmt *database_prepare(sqlite3 *conn, char *query) {
  int status;
  sqlite3_stmt *target = NULL;
  status = sqlite3_prepare_v2(conn, query, strlen(query), &target, NULL);
  switch (status) {
  case SQLITE_OK:
    logprintf(3, "Statement (%s) compiled ok\n", query);
    return target;
  default:
    logprintf(0, "Failed to prepare statement (%s): %s\n", query,
              sqlite3_errmsg(conn));
  }
  return NULL;
}


x86 assembly (clang, -O0):
<database_prepare>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    %rdi,-0x30(%rbp)
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    %eax,%edx
xor    %eax,%eax
mov    %eax,%r8d
lea    -0x28(%rbp),%rcx
call   1050 <sqlite3_prepare_v2@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
sub    $0x80,%eax
jne    11bf <database_prepare+0x7f>
jmp    119b <database_prepare+0x5b>
mov    -0x18(%rbp),%rdx
mov    $0x3,%edi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1060 <logprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11ee <database_prepare+0xae>
mov    -0x18(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <sqlite3_errmsg@plt>
mov    -0x40(%rbp),%rdx
mov    %eax,%ecx
xor    %edi,%edi
lea    0xe3d(%rip),%rsi
mov    $0x0,%al
call   1060 <logprintf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<database_prepare>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
movq   $0x0,(%rsp)
mov    %rsi,%rdi
call   1030 <strlen@plt>
mov    %rsp,%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %r8d,%r8d
call   1050 <sqlite3_prepare_v2@plt>
cmp    $0x80,%eax
jne    1190 <database_prepare+0x50>
lea    0xe85(%rip),%rsi
mov    $0x3,%edi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <logprintf@plt>
mov    (%rsp),%r14
jmp    11b0 <database_prepare+0x70>
mov    %r14,%rdi
call   1040 <sqlite3_errmsg@plt>
lea    0xe7d(%rip),%rsi
xor    %r14d,%r14d
xor    %edi,%edi
mov    %rbx,%rdx
mov    %eax,%ecx
xor    %eax,%eax
call   1060 <logprintf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [28 x i8] c"Statement (%s) compiled ok\0A\00"
@.str.1 = [38 x i8] c"Failed to prepare statement (%s): %s\0A\00"
define i32* @database_prepare(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32* null, i32** %7
%8 = load i32*, i32** %4
%9 = load i8*, i8** %5
%10 = load i8*, i8** %5
%11 = call i32 @strlen(i8* %10)
%12 = call i32 @sqlite3_prepare_v2(i32* %8, i8* %9, i32 %11, i32** %7, i32* null)
store i32 %12, i32* %6
%13 = load i32, i32* %6
switch i32 %13, label %18 [
i32 128, label %14
]
14: ; preds = %2
%15 = load i8*, i8** %5
%16 = call i32 (i32, i8*, i8*, ...) @logprintf(i32 3, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %7
store i32* %17, i32** %3
br label %24
18: ; preds = %2
%19 = load i8*, i8** %5
%20 = load i32*, i32** %4
%21 = call i32 @sqlite3_errmsg(i32* %20)
%22 = call i32 (i32, i8*, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %19, i32 %21)
br label %23
23: ; preds = %18
store i32* null, i32** %3
br label %24
24: ; preds = %23, %14
%25 = load i32*, i32** %3
ret i32* %25
}

LLVM IR (-O2):
@.str = [28 x i8] c"Statement (%s) compiled ok\0A\00"
@.str.1 = [38 x i8] c"Failed to prepare statement (%s): %s\0A\00"
define i32* @database_prepare(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
store i32* null, i32** %3
%5 = tail call i32 @strlen(i8* %1)
%6 = call i32 @sqlite3_prepare_v2(i32* %0, i8* %1, i32 %5, i32** %3, i32* null)
%7 = icmp eq i32 %6, 128
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 (i32, i8*, i8*, ...) @logprintf(i32 3, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0), i8* %1)
%10 = load i32*, i32** %3
br label %14
11: ; preds = %2
%12 = call i32 @sqlite3_errmsg(i32* %0)
%13 = call i32 (i32, i8*, i8*, ...) @logprintf(i32 0, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %1, i32 %12)
br label %14
14: ; preds = %11, %8
%15 = phi i32* [ %10, %8 ], [ null, %11 ]
ret i32* %15
}