#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;

/* Variables and functions */
int SQLITE_OK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/,
                 int /*<<< orphan*/, char **);
int /*<<< orphan*/ sqlite3_free(char *);
int sqlite3_open(char *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int main(void) {
  sqlite3 *database;
  char *err_msg = 0;
  int return_code = sqlite3_open("test.db", &database);
  if (return_code != SQLITE_OK) {
    fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(database));
    sqlite3_close(database);
    return 1;
  }
  char *sql_statement = "DROP TABLE IF EXISTS Students;"
                        "CREATE TABLE Students(Id INT, Name TEXT, Number INT);"
                        "INSERT INTO Students VALUES(1, 'Linus', 42);"
                        "INSERT INTO Students VALUES(2, 'Richard', 1);"
                        "INSERT INTO Students VALUES(3, 'Greg', 666);"
                        "INSERT INTO Students VALUES(4, 'Andrew', 4242);";
  return_code = sqlite3_exec(database, sql_statement, 0, 0, &err_msg);
  if (return_code != SQLITE_OK) {
    fprintf(stderr, "SQLite error: %s\n", err_msg);
    sqlite3_free(err_msg);
    sqlite3_close(database);
    return 1;
  }
  sqlite3_close(database);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe82(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e54(%rip),%rcx
cmp    (%rcx),%eax
je     11d8 <main+0x78>
mov    0x2e35(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x2c(%rbp),%edi
mov    %rax,%rdx
lea    0xe4a(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0xf4>
lea    0xe43(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %ecx,%ecx
lea    -0x18(%rbp),%r8
mov    %ecx,%edx
call   1030 <sqlite3_exec@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%eax
je     1244 <main+0xe4>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xf09(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1080 <sqlite3_free@plt>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_close@plt>
movl   $0x1,-0x4(%rbp)
jmp    1254 <main+0xf4>
mov    -0x10(%rbp),%rdi
call   1070 <sqlite3_close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
lea    0xe89(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2e60(%rip),%r14
cmp    (%r14),%eax
jne    11d4 <main+0x74>
mov    0x10(%rsp),%rdi
lea    0xe89(%rip),%rsi
xor    %ebx,%ebx
lea    0x8(%rsp),%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmp    (%r14),%eax
je     11fd <main+0x9d>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
mov    0x8(%rsp),%rdx
lea    0xf67(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x8(%rsp),%rdi
call   1080 <sqlite3_free@plt>
jmp    11f8 <main+0x98>
mov    0x2dfd(%rip),%rax
mov    (%rax),%ebx
mov    0x10(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xe1a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    $0x1,%ebx
mov    0x10(%rsp),%rdi
call   1070 <sqlite3_close@plt>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [8 x i8] c"test.db\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Cannot open database: %s\0A\00"
@.str.2 = [264 x i8] c"DROP TABLE IF EXISTS Students;CREATE TABLE Students(Id INT, Name TEXT, Number INT);INSERT INTO Students VALUES(1, 'Linus', 42);INSERT INTO Students VALUES(2, 'Richard', 1);INSERT INTO Students VALUES(3, 'Greg', 666);INSERT INTO Students VALUES(4, 'Andrew', 4242);\00"
@.str.3 = [18 x i8] c"SQLite error: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i32 0, i32* %1
store i8* null, i8** %3
%6 = call i32 @sqlite3_open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32** %2)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = load i32, i32* @SQLITE_OK
%9 = icmp ne i32 %7, %8
br i1 %9, label %10, label %17
10: ; preds = %0
%11 = load i32, i32* @stderr
%12 = load i32*, i32** %2
%13 = call i8* @sqlite3_errmsg(i32* %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %13)
%15 = load i32*, i32** %2
%16 = call i32 @sqlite3_close(i32* %15)
store i32 1, i32* %1
br label %35
17: ; preds = %0
store i8* getelementptr inbounds ([264 x i8], [264 x i8]* @.str.2, i64 0, i64 0), i8** %5
%18 = load i32*, i32** %2
%19 = load i8*, i8** %5
%20 = call i32 @sqlite3_exec(i32* %18, i8* %19, i32 0, i32 0, i8** %3)
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 %32
24: ; preds = %17
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %3
%27 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %26)
%28 = load i8*, i8** %3
%29 = call i32 @sqlite3_free(i8* %28)
%30 = load i32*, i32** %2
%31 = call i32 @sqlite3_close(i32* %30)
store i32 1, i32* %1
br label %35
32: ; preds = %17
%33 = load i32*, i32** %2
%34 = call i32 @sqlite3_close(i32* %33)
store i32 0, i32* %1
br label %35
35: ; preds = %32, %24, %10
%36 = load i32, i32* %1
ret i32 %36
}

LLVM IR (-O2):
@.str = [8 x i8] c"test.db\00"
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str.1 = [26 x i8] c"Cannot open database: %s\0A\00"
@.str.2 = [264 x i8] c"DROP TABLE IF EXISTS Students;CREATE TABLE Students(Id INT, Name TEXT, Number INT);INSERT INTO Students VALUES(1, 'Linus', 42);INSERT INTO Students VALUES(2, 'Richard', 1);INSERT INTO Students VALUES(3, 'Greg', 666);INSERT INTO Students VALUES(4, 'Andrew', 4242);\00"
@.str.3 = [18 x i8] c"SQLite error: %s\0A\00"
define i32 @main() {
%1 = alloca i32*
%2 = alloca i8*
%3 = bitcast i32** %1 to i8*
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = call i32 @sqlite3_open(i8* getelementptr inbounds ([8 x i8], [8 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 %13, 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 ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i8* %11)
br label %24
13: ; preds = %0
%14 = load i32*, i32** %1
%15 = call i32 @sqlite3_exec(i32* %14, i8* getelementptr inbounds ([264 x i8], [264 x i8]* @.str.2, i64 0, i64 0), i32 0, i32 0, i8** %2)
%16 = load i32, i32* @SQLITE_OK
%17 = icmp eq i32 %15, %16
br i1 %17, label %24, label %18
18: ; preds = %13
%19 = load i32, i32* @stderr
%20 = load i8*, i8** %2
%21 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %20)
%22 = load i8*, i8** %2
%23 = call i32 @sqlite3_free(i8* %22)
br label %24
24: ; preds = %13, %18, %8
%25 = phi i32 [ 1, %8 ], [ 1, %18 ], [ 0, %13 ]
%26 = load i32*, i32** %1
%27 = call i32 @sqlite3_close(i32* %26)
ret i32 %25
}