#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*/ printf(char *, char const *);
int /*<<< orphan*/ sql_error(int /*<<< orphan*/ *);
int /*<<< orphan*/ sql_exec(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
int sqlite3_open(char const *, int /*<<< orphan*/ **);
int initDataBase(const char *filename, sqlite3 **db) {
  int rc = sqlite3_open(filename, &(*db));
  if (rc != SQLITE_OK) {
    sql_error(*db);
    sqlite3_close(*db);
    return rc;
  }
  sql_exec(*db, "create table essid (essid_id integer primary key "
                "autoincrement, essid text, prio integer default 64);");
  sql_exec(*db, "create table passwd (passwd_id integer primary key "
                "autoincrement, passwd text);");
  sql_exec(*db, "create table pmk (pmk_id integer primary key autoincrement, "
                "passwd_id int, essid_id int, pmk blob);");
  sql_exec(*db,
           "create table workbench (wb_id integer primary key autoincrement, "
           "essid_id integer, passwd_id integer, lockid integer default 0);");
  sql_exec(*db, "create index lock_lockid on workbench (lockid);");
  sql_exec(*db, "create index pmk_pw on pmk (passwd_id);");
  sql_exec(*db, "create unique index essid_u on essid (essid);");
  sql_exec(*db, "create unique index passwd_u on passwd (passwd);");
  sql_exec(*db, "create unique index ep_u on pmk (essid_id,passwd_id);");
  sql_exec(*db, "create unique index wb_u on workbench (essid_id,passwd_id);");
  sql_exec(*db, "CREATE TRIGGER delete_essid DELETE ON essid BEGIN DELETE FROM "
                "pmk WHERE pmk.essid_id = OLD.essid_id; DELETE FROM workbench "
                "WHERE workbench.essid_id = OLD.essid_id; END;");
  sql_exec(*db, "CREATE TRIGGER delete_passwd DELETE ON passwd BEGIN DELETE "
                "FROM pmk WHERE pmk.passwd_id = OLD.passwd_id; DELETE FROM "
                "workbench WHERE workbench.passwd_id = OLD.passwd_id; END;");
  sqlite3_close(*db);
  printf("Database <%s> successfully created\n", filename);
  return 0;
}


x86 assembly (clang, -O0):
<initDataBase>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <sqlite3_open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%eax
je     11a5 <initDataBase+0x55>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1060 <sql_error@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1070 <sqlite3_close@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    12ac <initDataBase+0x15c>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xe4d(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xea0(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xedd(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xf2e(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xf9c(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xfb9(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xfce(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0xfe9(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0x1007(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0x102a(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0x1053(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
lea    0x10e9(%rip),%rsi
call   1040 <sql_exec@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1070 <sqlite3_close@plt>
mov    -0x10(%rbp),%rsi
lea    0x117c(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<initDataBase>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
call   1030 <sqlite3_open@plt>
mov    %eax,%ebp
mov    0x2e80(%rip),%rax
mov    (%rbx),%rdi
cmp    (%rax),%ebp
jne    123f <initDataBase+0xef>
lea    0xe86(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0xedd(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0xf1e(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0xf73(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0xfe5(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0x1006(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0x101f(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0x103e(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0x1060(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0x1087(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0x10b4(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
lea    0x114e(%rip),%rsi
call   1040 <sql_exec@plt>
mov    (%rbx),%rdi
call   1070 <sqlite3_close@plt>
lea    0x11e9(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
xor    %ebp,%ebp
jmp    124c <initDataBase+0xfc>
call   1060 <sql_error@plt>
mov    (%rbx),%rdi
call   1070 <sqlite3_close@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@.str = [102 x i8] c"create table essid (essid_id integer primary key autoincrement, essid text, prio integer default 64);\00"
@.str.1 = [80 x i8] c"create table passwd (passwd_id integer primary key autoincrement, passwd text);\00"
@.str.2 = [100 x i8] c"create table pmk (pmk_id integer primary key autoincrement, passwd_id int, essid_id int, pmk blob);\00"
@.str.3 = [129 x i8] c"create table workbench (wb_id integer primary key autoincrement, essid_id integer, passwd_id integer, lockid integer default 0);\00"
@.str.4 = [48 x i8] c"create index lock_lockid on workbench (lockid);\00"
@.str.5 = [40 x i8] c"create index pmk_pw on pmk (passwd_id);\00"
@.str.6 = [46 x i8] c"create unique index essid_u on essid (essid);\00"
@.str.7 = [49 x i8] c"create unique index passwd_u on passwd (passwd);\00"
@.str.8 = [54 x i8] c"create unique index ep_u on pmk (essid_id,passwd_id);\00"
@.str.9 = [60 x i8] c"create unique index wb_u on workbench (essid_id,passwd_id);\00"
@.str.10 = [169 x i8] c"CREATE TRIGGER delete_essid DELETE ON essid BEGIN DELETE FROM pmk WHERE pmk.essid_id = OLD.essid_id; DELETE FROM workbench WHERE workbench.essid_id = OLD.essid_id; END;\00"
@.str.11 = [175 x i8] c"CREATE TRIGGER delete_passwd DELETE ON passwd BEGIN DELETE FROM pmk WHERE pmk.passwd_id = OLD.passwd_id; DELETE FROM workbench WHERE workbench.passwd_id = OLD.passwd_id; END;\00"
@.str.12 = [36 x i8] c"Database <%s> successfully created\0A\00"
define i32 @initDataBase(i8* %0, i32** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32**
%6 = alloca i32
store i8* %0, i8** %4
store i32** %1, i32*** %5
%7 = load i8*, i8** %4
%8 = load i32**, i32*** %5
%9 = call i32 @sqlite3_open(i8* %7, i32** %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = load i32, i32* @SQLITE_OK
%12 = icmp ne i32 %10, %11
br i1 %12, label %13, label %21
13: ; preds = %2
%14 = load i32**, i32*** %5
%15 = load i32*, i32** %14
%16 = call i32 @sql_error(i32* %15)
%17 = load i32**, i32*** %5
%18 = load i32*, i32** %17
%19 = call i32 @sqlite3_close(i32* %18)
%20 = load i32, i32* %6
store i32 %20, i32* %3
br label %63
21: ; preds = %2
%22 = load i32**, i32*** %5
%23 = load i32*, i32** %22
%24 = call i32 @sql_exec(i32* %23, i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0))
%25 = load i32**, i32*** %5
%26 = load i32*, i32** %25
%27 = call i32 @sql_exec(i32* %26, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32**, i32*** %5
%29 = load i32*, i32** %28
%30 = call i32 @sql_exec(i32* %29, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.2, i64 0, i64 0))
%31 = load i32**, i32*** %5
%32 = load i32*, i32** %31
%33 = call i32 @sql_exec(i32* %32, i8* getelementptr inbounds ([129 x i8], [129 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32**, i32*** %5
%35 = load i32*, i32** %34
%36 = call i32 @sql_exec(i32* %35, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%37 = load i32**, i32*** %5
%38 = load i32*, i32** %37
%39 = call i32 @sql_exec(i32* %38, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%40 = load i32**, i32*** %5
%41 = load i32*, i32** %40
%42 = call i32 @sql_exec(i32* %41, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
%43 = load i32**, i32*** %5
%44 = load i32*, i32** %43
%45 = call i32 @sql_exec(i32* %44, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32**, i32*** %5
%47 = load i32*, i32** %46
%48 = call i32 @sql_exec(i32* %47, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0))
%49 = load i32**, i32*** %5
%50 = load i32*, i32** %49
%51 = call i32 @sql_exec(i32* %50, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0))
%52 = load i32**, i32*** %5
%53 = load i32*, i32** %52
%54 = call i32 @sql_exec(i32* %53, i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str.10, i64 0, i64 0))
%55 = load i32**, i32*** %5
%56 = load i32*, i32** %55
%57 = call i32 @sql_exec(i32* %56, i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str.11, i64 0, i64 0))
%58 = load i32**, i32*** %5
%59 = load i32*, i32** %58
%60 = call i32 @sqlite3_close(i32* %59)
%61 = load i8*, i8** %4
%62 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i8* %61)
store i32 0, i32* %3
br label %63
63: ; preds = %21, %13
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@.str = [102 x i8] c"create table essid (essid_id integer primary key autoincrement, essid text, prio integer default 64);\00"
@.str.1 = [80 x i8] c"create table passwd (passwd_id integer primary key autoincrement, passwd text);\00"
@.str.2 = [100 x i8] c"create table pmk (pmk_id integer primary key autoincrement, passwd_id int, essid_id int, pmk blob);\00"
@.str.3 = [129 x i8] c"create table workbench (wb_id integer primary key autoincrement, essid_id integer, passwd_id integer, lockid integer default 0);\00"
@.str.4 = [48 x i8] c"create index lock_lockid on workbench (lockid);\00"
@.str.5 = [40 x i8] c"create index pmk_pw on pmk (passwd_id);\00"
@.str.6 = [46 x i8] c"create unique index essid_u on essid (essid);\00"
@.str.7 = [49 x i8] c"create unique index passwd_u on passwd (passwd);\00"
@.str.8 = [54 x i8] c"create unique index ep_u on pmk (essid_id,passwd_id);\00"
@.str.9 = [60 x i8] c"create unique index wb_u on workbench (essid_id,passwd_id);\00"
@.str.10 = [169 x i8] c"CREATE TRIGGER delete_essid DELETE ON essid BEGIN DELETE FROM pmk WHERE pmk.essid_id = OLD.essid_id; DELETE FROM workbench WHERE workbench.essid_id = OLD.essid_id; END;\00"
@.str.11 = [175 x i8] c"CREATE TRIGGER delete_passwd DELETE ON passwd BEGIN DELETE FROM pmk WHERE pmk.passwd_id = OLD.passwd_id; DELETE FROM workbench WHERE workbench.passwd_id = OLD.passwd_id; END;\00"
@.str.12 = [36 x i8] c"Database <%s> successfully created\0A\00"
define i32 @initDataBase(i8* %0, i32** %1) {
%3 = tail call i32 @sqlite3_open(i8* %0, i32** %1)
%4 = load i32, i32* @SQLITE_OK
%5 = icmp eq i32 %3, %4
%6 = load i32*, i32** %1
br i1 %5, label %11, label %7
7: ; preds = %2
%8 = tail call i32 @sql_error(i32* %6)
%9 = load i32*, i32** %1
%10 = tail call i32 @sqlite3_close(i32* %9)
br label %38
11: ; preds = %2
%12 = tail call i32 @sql_exec(i32* %6, i8* getelementptr inbounds ([102 x i8], [102 x i8]* @.str, i64 0, i64 0))
%13 = load i32*, i32** %1
%14 = tail call i32 @sql_exec(i32* %13, i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.1, i64 0, i64 0))
%15 = load i32*, i32** %1
%16 = tail call i32 @sql_exec(i32* %15, i8* getelementptr inbounds ([100 x i8], [100 x i8]* @.str.2, i64 0, i64 0))
%17 = load i32*, i32** %1
%18 = tail call i32 @sql_exec(i32* %17, i8* getelementptr inbounds ([129 x i8], [129 x i8]* @.str.3, i64 0, i64 0))
%19 = load i32*, i32** %1
%20 = tail call i32 @sql_exec(i32* %19, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
%21 = load i32*, i32** %1
%22 = tail call i32 @sql_exec(i32* %21, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0))
%23 = load i32*, i32** %1
%24 = tail call i32 @sql_exec(i32* %23, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.6, i64 0, i64 0))
%25 = load i32*, i32** %1
%26 = tail call i32 @sql_exec(i32* %25, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.7, i64 0, i64 0))
%27 = load i32*, i32** %1
%28 = tail call i32 @sql_exec(i32* %27, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0))
%29 = load i32*, i32** %1
%30 = tail call i32 @sql_exec(i32* %29, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.9, i64 0, i64 0))
%31 = load i32*, i32** %1
%32 = tail call i32 @sql_exec(i32* %31, i8* getelementptr inbounds ([169 x i8], [169 x i8]* @.str.10, i64 0, i64 0))
%33 = load i32*, i32** %1
%34 = tail call i32 @sql_exec(i32* %33, i8* getelementptr inbounds ([175 x i8], [175 x i8]* @.str.11, i64 0, i64 0))
%35 = load i32*, i32** %1
%36 = tail call i32 @sqlite3_close(i32* %35)
%37 = tail call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.12, i64 0, i64 0), i8* %0)
br label %38
38: ; preds = %11, %7
%39 = phi i32 [ %3, %7 ], [ 0, %11 ]
ret i32 %39
}