#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 /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ SQLITE_OK;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
scalar_t__ sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, scalar_t__,
                              int /*<<< orphan*/ **, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
sqlite3_stmt *get_sql_statement(char *sqlstmt, sqlite3 *db) {
  sqlite3_stmt *stmt;
  if ((sqlite3_prepare_v2(db, sqlstmt, strlen(sqlstmt) + 1, &stmt, NULL)) !=
      SQLITE_OK) {
    fprintf(stderr, "Failed to prepare Database\n");
    sqlite3_close(db);
    exit(EXIT_FAILURE);
  }
  return stmt;
}


x86 assembly (clang, -O0):
<get_sql_statement>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
lea    -0x18(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e4b(%rip),%rcx
cmp    (%rcx),%rax
je     11d2 <get_sql_statement+0x82>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    0xe4a(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_close@plt>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_sql_statement>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    0x1(%rax),%rdx
mov    %rsp,%rcx
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %r8d,%r8d
call   1060 <sqlite3_prepare_v2@plt>
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    118c <get_sql_statement+0x3c>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e45(%rip),%rax
mov    (%rax),%edi
lea    0xe64(%rip),%rsi
call   1040 <fprintf@plt>
mov    %r14,%rdi
call   1050 <sqlite3_close@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str = [28 x i8] c"Failed to prepare Database\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @get_sql_statement(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32*
store i8* %0, i8** %3
store i32* %1, i32** %4
%6 = load i32*, i32** %4
%7 = load i8*, i8** %3
%8 = load i8*, i8** %3
%9 = call i64 @strlen(i8* %8)
%10 = add nsw i64 %9, 1
%11 = call i64 @sqlite3_prepare_v2(i32* %6, i8* %7, i64 %10, i32** %5, i32* null)
%12 = load i64, i64* @SQLITE_OK
%13 = icmp ne i64 %11, %12
br i1 %13, label %14, label %21
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%17 = load i32*, i32** %4
%18 = call i32 @sqlite3_close(i32* %17)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %2
%22 = load i32*, i32** %5
ret i32* %22
}

LLVM IR (-O2):
@SQLITE_OK = global i64 0
@stderr = global i32 0
@.str = [28 x i8] c"Failed to prepare Database\0A\00"
@EXIT_FAILURE = global i32 0
define i32* @get_sql_statement(i8* %0, i32* %1) {
%3 = alloca i32*
%4 = bitcast i32** %3 to i8*
%5 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%6 = add nsw i64 %5, 1
%7 = call i64 @sqlite3_prepare_v2(i32* %1, i8* %0, i64 %6, i32** %3, i32* null)
%8 = load i64, i64* @SQLITE_OK
%9 = icmp eq i64 %7, %8
br i1 %9, label %16, label %10
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @sqlite3_close(i32* %1)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %2
%17 = load i32*, i32** %3
ret i32* %17
}