#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;
int /*<<< orphan*/ EXIT_SUCCESS;
int SQLITE_OK;
int SQLITE_ROW;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_column_text(int /*<<< orphan*/ *, int /*<<< orphan*/);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_finalize(int /*<<< orphan*/ *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int sqlite3_prepare_v2(int /*<<< orphan*/ *, char *, int, int /*<<< orphan*/ **,
                       int /*<<< orphan*/);
int sqlite3_step(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int main(void) {
  sqlite3 *db;
  sqlite3_stmt *res;
  int rc = sqlite3_open(":memory:", &db);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "could not open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(EXIT_FAILURE);
  }
  rc = sqlite3_prepare_v2(db, "SELECT SQLITE_VERSION()", -1, &res, 0);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "failed to fetch data: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    exit(EXIT_FAILURE);
  }
  rc = sqlite3_step(res);
  if (rc == SQLITE_ROW) {
    printf("Your sqlite version: %s\n", sqlite3_column_text(res, 0));
  }
  sqlite3_finalize(res);
  sqlite3_close(db);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe4a(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e1c(%rip),%rcx
cmp    (%rcx),%eax
je     1212 <main+0x72>
mov    0x2dfd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x20(%rbp),%edi
mov    %rax,%rdx
lea    0xe13(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    0x2dc5(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xe09(%rip),%rsi
mov    $0xffffffff,%edx
lea    -0x18(%rbp),%rcx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2dad(%rip),%rcx
cmp    (%rcx),%eax
je     1281 <main+0xe1>
mov    0x2d8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdd9(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x18(%rbp),%rdi
call   1060 <sqlite3_step@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d29(%rip),%rcx
cmp    (%rcx),%eax
jne    12b9 <main+0x119>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_text@plt>
mov    %rax,%rsi
lea    0xda4(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    -0x10(%rbp),%rdi
call   1080 <sqlite3_close@plt>
mov    0x2cf6(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xe54(%rip),%rdi
mov    %rsp,%rsi
call   1030 <sqlite3_open@plt>
mov    0x2e2d(%rip),%rbx
cmp    (%rbx),%eax
jne    1231 <main+0x91>
mov    (%rsp),%rdi
lea    0xe5c(%rip),%rsi
lea    0x8(%rsp),%rcx
mov    $0xffffffff,%edx
xor    %r8d,%r8d
call   10b0 <sqlite3_prepare_v2@plt>
cmp    (%rbx),%eax
jne    124c <main+0xac>
mov    0x8(%rsp),%rdi
call   1060 <sqlite3_step@plt>
mov    0x2dcf(%rip),%rcx
cmp    (%rcx),%eax
jne    1210 <main+0x70>
mov    0x8(%rsp),%rdi
xor    %esi,%esi
call   1090 <sqlite3_column_text@plt>
lea    0xe50(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   10a0 <sqlite3_finalize@plt>
mov    (%rsp),%rdi
call   1080 <sqlite3_close@plt>
mov    0x2d9e(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2da0(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xdbf(%rip),%rsi
jmp    1265 <main+0xc5>
mov    0x2d85(%rip),%rax
mov    (%rax),%ebx
mov    (%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xdd9(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1070 <fprintf@plt>
mov    (%rsp),%rdi
call   1080 <sqlite3_close@plt>
mov    0x2d51(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c":memory:\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"could not open database: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"SELECT SQLITE_VERSION()\00"
@.str.3 = [26 x i8] c"failed to fetch data: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.4 = [25 x i8] c"Your sqlite version: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca i32
store i32 0, i32* %1
%5 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32** %2)
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = load i32, i32* @SQLITE_OK
%8 = icmp ne i32 %6, %7
br i1 %8, label %9, label %18
9: ; preds = %0
%10 = load i32, i32* @stderr
%11 = load i32*, i32** %2
%12 = call i8* @sqlite3_errmsg(i32* %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32*, i32** %2
%15 = call i32 @sqlite3_close(i32* %14)
%16 = load i32, i32* @EXIT_FAILURE
%17 = call i32 @exit(i32 %16)
unreachable
18: ; preds = %0
%19 = load i32*, i32** %2
%20 = call i32 @sqlite3_prepare_v2(i32* %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %3, i32 0)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = load i32, i32* @SQLITE_OK
%23 = icmp ne i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %18
%25 = load i32, i32* @stderr
%26 = load i32*, i32** %2
%27 = call i8* @sqlite3_errmsg(i32* %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = load i32*, i32** %2
%30 = call i32 @sqlite3_close(i32* %29)
%31 = load i32, i32* @EXIT_FAILURE
%32 = call i32 @exit(i32 %31)
unreachable
33: ; preds = %18
%34 = load i32*, i32** %3
%35 = call i32 @sqlite3_step(i32* %34)
store i32 %35, i32* %4
%36 = load i32, i32* %4
%37 = load i32, i32* @SQLITE_ROW
%38 = icmp eq i32 %36, %37
br i1 %38, label %39, label %43
39: ; preds = %33
%40 = load i32*, i32** %3
%41 = call i8* @sqlite3_column_text(i32* %40, i32 0)
%42 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %41)
br label %43
43: ; preds = %39, %33
%44 = load i32*, i32** %3
%45 = call i32 @sqlite3_finalize(i32* %44)
%46 = load i32*, i32** %2
%47 = call i32 @sqlite3_close(i32* %46)
%48 = load i32, i32* @EXIT_SUCCESS
%49 = call i32 @exit(i32 %48)
unreachable
}

LLVM IR (-O2):
@.str = [9 x i8] c":memory:\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [29 x i8] c"could not open database: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [24 x i8] c"SELECT SQLITE_VERSION()\00"
@.str.3 = [26 x i8] c"failed to fetch data: %s\0A\00"
@SQLITE_ROW = global i32 0
@.str.4 = [25 x i8] c"Your sqlite version: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32*
%2 = alloca i32*
%3 = bitcast i32** %1 to i8*
%4 = bitcast i32** %2 to i8*
%5 = call i32 @sqlite3_open(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32** %1)
%6 = load i32, i32* @SQLITE_OK
%7 = icmp eq i32 %5, %6
br i1 %7, label %17, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = load i32*, i32** %1
%11 = call i8* @sqlite3_errmsg(i32* %10)
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %1
%14 = call i32 @sqlite3_close(i32* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %0
%18 = load i32*, i32** %1
%19 = call i32 @sqlite3_prepare_v2(i32* %18, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i32 -1, i32** %2, i32 0)
%20 = load i32, i32* @SQLITE_OK
%21 = icmp eq i32 %19, %20
br i1 %21, label %31, label %22
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i32*, i32** %1
%25 = call i8* @sqlite3_errmsg(i32* %24)
%26 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i32*, i32** %1
%28 = call i32 @sqlite3_close(i32* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %17
%32 = load i32*, i32** %2
%33 = call i32 @sqlite3_step(i32* %32)
%34 = load i32, i32* @SQLITE_ROW
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %31
%37 = load i32*, i32** %2
%38 = call i8* @sqlite3_column_text(i32* %37, i32 0)
%39 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0), i8* %38)
br label %40
40: ; preds = %36, %31
%41 = load i32*, i32** %2
%42 = call i32 @sqlite3_finalize(i32* %41)
%43 = load i32*, i32** %1
%44 = call i32 @sqlite3_close(i32* %43)
%45 = load i32, i32* @EXIT_SUCCESS
%46 = call i32 @exit(i32 %45)
unreachable
}