#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int SQLITE_OK;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sqlite3_close(int /*<<< orphan*/ *);
char *sqlite3_errmsg(int /*<<< orphan*/ *);
int /*<<< orphan*/ sqlite3_exec(int /*<<< orphan*/ *, char *,
                                int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                char **);
int /*<<< orphan*/ sqlite3_free(char **);
int sqlite3_open(char const *, int /*<<< orphan*/ **);
int /*<<< orphan*/ stderr;
int init_database(const char *filename) {
  sqlite3 *db = NULL;
  char *errmsg = NULL;
  int rc = sqlite3_open(filename, &db);
  if (rc != SQLITE_OK) {
    fprintf(stderr, "ERROR, failed to open database: %s\n", sqlite3_errmsg(db));
    sqlite3_close(db);
    return EXIT_FAILURE;
  }
  sqlite3_exec(db,
               "create table messages (message_id integer primary key "
               "autoincrement, source text, sub_source text, type integer, "
               "date_time text, read integer);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n", "message");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(db,
               "create table client (client_id integer primary key "
               "autoincrement, state integer, date_time text, username text);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n", "client");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(db,
               "create table clients_actions (client_id integer foreign key, "
               "command text, parameters text, data integer, date_time text);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n",
            "clients_actions");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(db,
               "create table response_type (reponse_type_id integer primary "
               "key autoincrement, description text);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n",
            "response_type");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(db,
               "create table responses (reponses_id integer primary key "
               "autoincrement, response_type_id integer foreign key, date_time "
               "text, attack_id integer foreign key);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n",
            "responses");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(
      db,
      "create table attack (attack_id integer primary key autoincrement, "
      "source_name text, date_time text, victim_id integer);",
      NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n", "attack");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(
      db,
      "create table sensor (sensor_id integer primary key autoincrement, state "
      "integer, date_time, text, mac_addr text, username text);",
      NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n", "sensor");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(db,
               "create table invalid_frames (sensor_id integer foreign key, "
               "fail_count integer, invalid_protocol integer);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n",
            "invalid_frames");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(db,
               "create table frames (frame_id integer primary key "
               "autoincrement, sourceID integer, frame_type integer, "
               "frame_subtype integer, protected integer, addr_1 text, addr_2 "
               "text, addr_3 text, addr_4 text, to_dest integer, from_dest "
               "integer, retry integer, frag_num integer, seq_num integer);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n", "frames");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_exec(db,
               "create table banlist (banlist_id integer primary key "
               "autoincrement, mac_addr text, is_AP integer, ban_creation_time "
               "text, ban_length_sec integer, is_active integer);",
               NULL, NULL, &errmsg);
  if (errmsg != NULL) {
    fprintf(stderr, "ERROR creating '%s' table in the database.\n", "banlist");
    sqlite3_free(&errmsg);
  }
  errmsg = NULL;
  ;
  sqlite3_close(db);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<init_database>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <sqlite3_open@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    0x2e52(%rip),%rcx
cmp    (%rcx),%eax
je     11df <init_database+0x7f>
mov    0x2e33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <sqlite3_errmsg@plt>
mov    -0x28(%rbp),%edi
mov    %rax,%rdx
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1070 <sqlite3_close@plt>
mov    0x2dfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1532 <init_database+0x3d2>
mov    -0x18(%rbp),%rdi
lea    0xe3a(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     122a <init_database+0xca>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
lea    0xe9f(%rip),%rsi
lea    0xec4(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xeab(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     127d <init_database+0x11d>
mov    0x2d79(%rip),%rax
mov    (%rax),%edi
lea    0xe4c(%rip),%rsi
lea    0xeea(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xed0(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     12d0 <init_database+0x170>
mov    0x2d26(%rip),%rax
mov    (%rax),%edi
lea    0xdf9(%rip),%rsi
lea    0xf19(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xf08(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     1323 <init_database+0x1c3>
mov    0x2cd3(%rip),%rax
mov    (%rax),%edi
lea    0xda6(%rip),%rsi
lea    0xf38(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xf25(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     1376 <init_database+0x216>
mov    0x2c80(%rip),%rax
mov    (%rax),%edi
lea    0xd53(%rip),%rsi
lea    0xf90(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xf79(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     13c9 <init_database+0x269>
mov    0x2c2d(%rip),%rax
mov    (%rax),%edi
lea    0xd00(%rip),%rsi
lea    0xfbf(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xfa5(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     141c <init_database+0x2bc>
mov    0x2bda(%rip),%rax
mov    (%rax),%edi
lea    0xcad(%rip),%rsi
lea    0xff4(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xfda(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     146f <init_database+0x30f>
mov    0x2b87(%rip),%rax
mov    (%rax),%edi
lea    0xc5a(%rip),%rsi
lea    0x1013(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0x1001(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     14c2 <init_database+0x362>
mov    0x2b34(%rip),%rax
mov    (%rax),%edi
lea    0xc07(%rip),%rsi
lea    0xfc8(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    0x10ca(%rip),%rsi
xor    %eax,%eax
mov    %eax,%ecx
lea    -0x20(%rbp),%r8
mov    %rcx,%rdx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,-0x20(%rbp)
je     1515 <init_database+0x3b5>
mov    0x2ae1(%rip),%rax
mov    (%rax),%edi
lea    0xbb4(%rip),%rsi
lea    0x113e(%rip),%rdx
call   1060 <fprintf@plt>
lea    -0x20(%rbp),%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <sqlite3_close@plt>
mov    0x2a9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_database>:
push   %rbx
sub    $0x10,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0x8(%rsp),%rsi
call   1040 <sqlite3_open@plt>
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
jne    1486 <init_database+0x326>
mov    0x8(%rsp),%rdi
lea    0xe89(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     11d2 <init_database+0x72>
mov    0x2e23(%rip),%rax
mov    (%rax),%edi
lea    0xef6(%rip),%rsi
lea    0xf1b(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0xf02(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     121d <init_database+0xbd>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xeab(%rip),%rsi
lea    0xf49(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0xf2f(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     1268 <init_database+0x108>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xe60(%rip),%rsi
lea    0xf80(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0xf6f(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     12b3 <init_database+0x153>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xe15(%rip),%rsi
lea    0xfa7(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0xf94(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     12fe <init_database+0x19e>
mov    0x2cf7(%rip),%rax
mov    (%rax),%edi
lea    0xdca(%rip),%rsi
lea    0x1007(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0xff0(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     1349 <init_database+0x1e9>
mov    0x2cac(%rip),%rax
mov    (%rax),%edi
lea    0xd7f(%rip),%rsi
lea    0x103e(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0x1024(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     1394 <init_database+0x234>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
lea    0xd34(%rip),%rsi
lea    0x107b(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0x1061(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     13df <init_database+0x27f>
mov    0x2c16(%rip),%rax
mov    (%rax),%edi
lea    0xce9(%rip),%rsi
lea    0x10a2(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0x1090(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     142a <init_database+0x2ca>
mov    0x2bcb(%rip),%rax
mov    (%rax),%edi
lea    0xc9e(%rip),%rsi
lea    0x105f(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x8(%rsp),%rdi
lea    0x1161(%rip),%rsi
mov    %rsp,%r8
xor    %edx,%edx
xor    %ecx,%ecx
call   1030 <sqlite3_exec@plt>
cmpq   $0x0,(%rsp)
je     1475 <init_database+0x315>
mov    0x2b80(%rip),%rax
mov    (%rax),%edi
lea    0xc53(%rip),%rsi
lea    0x11dd(%rip),%rdx
call   1060 <fprintf@plt>
mov    %rsp,%rdi
call   1080 <sqlite3_free@plt>
movq   $0x0,(%rsp)
mov    0x2b44(%rip),%rbx
jmp    14b1 <init_database+0x351>
mov    0x2b4b(%rip),%rax
mov    (%rax),%ebx
mov    0x8(%rsp),%rdi
call   1050 <sqlite3_errmsg@plt>
lea    0xb60(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1060 <fprintf@plt>
mov    0x2b1f(%rip),%rbx
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_close@plt>
mov    (%rbx),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"ERROR, failed to open database: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [144 x i8] c"create table messages (message_id integer primary key autoincrement, source text, sub_source text, type integer, date_time text, read integer);\00"
@.str.2 = [44 x i8] c"ERROR creating '%s' table in the database.\0A\00"
@.str.3 = [8 x i8] c"message\00"
@.str.4 = [113 x i8] c"create table client (client_id integer primary key autoincrement, state integer, date_time text, username text);\00"
@.str.5 = [7 x i8] c"client\00"
@.str.6 = [123 x i8] c"create table clients_actions (client_id integer foreign key, command text, parameters text, data integer, date_time text);\00"
@.str.7 = [16 x i8] c"clients_actions\00"
@.str.8 = [98 x i8] c"create table response_type (reponse_type_id integer primary key autoincrement, description text);\00"
@.str.9 = [14 x i8] c"response_type\00"
@.str.10 = [157 x i8] c"create table responses (reponses_id integer primary key autoincrement, response_type_id integer foreign key, date_time text, attack_id integer foreign key);\00"
@.str.11 = [10 x i8] c"responses\00"
@.str.12 = [120 x i8] c"create table attack (attack_id integer primary key autoincrement, source_name text, date_time text, victim_id integer);\00"
@.str.13 = [7 x i8] c"attack\00"
@.str.14 = [129 x i8] c"create table sensor (sensor_id integer primary key autoincrement, state integer, date_time, text, mac_addr text, username text);\00"
@.str.15 = [7 x i8] c"sensor\00"
@.str.16 = [107 x i8] c"create table invalid_frames (sensor_id integer foreign key, fail_count integer, invalid_protocol integer);\00"
@.str.17 = [15 x i8] c"invalid_frames\00"
@.str.18 = [284 x i8] c"create table frames (frame_id integer primary key autoincrement, sourceID integer, frame_type integer, frame_subtype integer, protected integer, addr_1 text, addr_2 text, addr_3 text, addr_4 text, to_dest integer, from_dest integer, retry integer, frag_num integer, seq_num integer);\00"
@.str.19 = [7 x i8] c"frames\00"
@.str.20 = [166 x i8] c"create table banlist (banlist_id integer primary key autoincrement, mac_addr text, is_AP integer, ban_creation_time text, ban_length_sec integer, is_active integer);\00"
@.str.21 = [8 x i8] c"banlist\00"
@EXIT_SUCCESS = global i32 0
define i32 @init_database(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
store i32* null, i32** %4
store i8* null, i8** %5
%7 = load i8*, i8** %3
%8 = call i32 @sqlite3_open(i8* %7, i32** %4)
store i32 %8, i32* %6
%9 = load i32, i32* %6
%10 = load i32, i32* @SQLITE_OK
%11 = icmp ne i32 %9, %10
br i1 %11, label %12, label %20
12: ; preds = %1
%13 = load i32, i32* @stderr
%14 = load i32*, i32** %4
%15 = call i8* @sqlite3_errmsg(i32* %14)
%16 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = load i32*, i32** %4
%18 = call i32 @sqlite3_close(i32* %17)
%19 = load i32, i32* @EXIT_FAILURE
store i32 %19, i32* %2
br label %114
20: ; preds = %1
%21 = load i32*, i32** %4
%22 = call i32 @sqlite3_exec(i32* %21, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32* null, i32* null, i8** %5)
%23 = load i8*, i8** %5
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %29
25: ; preds = %20
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%28 = call i32 @sqlite3_free(i8** %5)
br label %29
29: ; preds = %25, %20
store i8* null, i8** %5
%30 = load i32*, i32** %4
%31 = call i32 @sqlite3_exec(i32* %30, i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.4, i64 0, i64 0), i32* null, i32* null, i8** %5)
%32 = load i8*, i8** %5
%33 = icmp ne i8* %32, null
br i1 %33, label %34, label %38
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%37 = call i32 @sqlite3_free(i8** %5)
br label %38
38: ; preds = %34, %29
store i8* null, i8** %5
%39 = load i32*, i32** %4
%40 = call i32 @sqlite3_exec(i32* %39, i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str.6, i64 0, i64 0), i32* null, i32* null, i8** %5)
%41 = load i8*, i8** %5
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %47
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%46 = call i32 @sqlite3_free(i8** %5)
br label %47
47: ; preds = %43, %38
store i8* null, i8** %5
%48 = load i32*, i32** %4
%49 = call i32 @sqlite3_exec(i32* %48, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.8, i64 0, i64 0), i32* null, i32* null, i8** %5)
%50 = load i8*, i8** %5
%51 = icmp ne i8* %50, null
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = call i32 @fprintf(i32 %53, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%55 = call i32 @sqlite3_free(i8** %5)
br label %56
56: ; preds = %52, %47
store i8* null, i8** %5
%57 = load i32*, i32** %4
%58 = call i32 @sqlite3_exec(i32* %57, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.10, i64 0, i64 0), i32* null, i32* null, i8** %5)
%59 = load i8*, i8** %5
%60 = icmp ne i8* %59, null
br i1 %60, label %61, label %65
61: ; preds = %56
%62 = load i32, i32* @stderr
%63 = call i32 @fprintf(i32 %62, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%64 = call i32 @sqlite3_free(i8** %5)
br label %65
65: ; preds = %61, %56
store i8* null, i8** %5
%66 = load i32*, i32** %4
%67 = call i32 @sqlite3_exec(i32* %66, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.12, i64 0, i64 0), i32* null, i32* null, i8** %5)
%68 = load i8*, i8** %5
%69 = icmp ne i8* %68, null
br i1 %69, label %70, label %74
70: ; preds = %65
%71 = load i32, i32* @stderr
%72 = call i32 @fprintf(i32 %71, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%73 = call i32 @sqlite3_free(i8** %5)
br label %74
74: ; preds = %70, %65
store i8* null, i8** %5
%75 = load i32*, i32** %4
%76 = call i32 @sqlite3_exec(i32* %75, i8* getelementptr inbounds ([129 x i8], [129 x i8]* @.str.14, i64 0, i64 0), i32* null, i32* null, i8** %5)
%77 = load i8*, i8** %5
%78 = icmp ne i8* %77, null
br i1 %78, label %79, label %83
79: ; preds = %74
%80 = load i32, i32* @stderr
%81 = call i32 @fprintf(i32 %80, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%82 = call i32 @sqlite3_free(i8** %5)
br label %83
83: ; preds = %79, %74
store i8* null, i8** %5
%84 = load i32*, i32** %4
%85 = call i32 @sqlite3_exec(i32* %84, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.16, i64 0, i64 0), i32* null, i32* null, i8** %5)
%86 = load i8*, i8** %5
%87 = icmp ne i8* %86, null
br i1 %87, label %88, label %92
88: ; preds = %83
%89 = load i32, i32* @stderr
%90 = call i32 @fprintf(i32 %89, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.17, i64 0, i64 0))
%91 = call i32 @sqlite3_free(i8** %5)
br label %92
92: ; preds = %88, %83
store i8* null, i8** %5
%93 = load i32*, i32** %4
%94 = call i32 @sqlite3_exec(i32* %93, i8* getelementptr inbounds ([284 x i8], [284 x i8]* @.str.18, i64 0, i64 0), i32* null, i32* null, i8** %5)
%95 = load i8*, i8** %5
%96 = icmp ne i8* %95, null
br i1 %96, label %97, label %101
97: ; preds = %92
%98 = load i32, i32* @stderr
%99 = call i32 @fprintf(i32 %98, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.19, i64 0, i64 0))
%100 = call i32 @sqlite3_free(i8** %5)
br label %101
101: ; preds = %97, %92
store i8* null, i8** %5
%102 = load i32*, i32** %4
%103 = call i32 @sqlite3_exec(i32* %102, i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str.20, i64 0, i64 0), i32* null, i32* null, i8** %5)
%104 = load i8*, i8** %5
%105 = icmp ne i8* %104, null
br i1 %105, label %106, label %110
106: ; preds = %101
%107 = load i32, i32* @stderr
%108 = call i32 @fprintf(i32 %107, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.21, i64 0, i64 0))
%109 = call i32 @sqlite3_free(i8** %5)
br label %110
110: ; preds = %106, %101
store i8* null, i8** %5
%111 = load i32*, i32** %4
%112 = call i32 @sqlite3_close(i32* %111)
%113 = load i32, i32* @EXIT_SUCCESS
store i32 %113, i32* %2
br label %114
114: ; preds = %110, %12
%115 = load i32, i32* %2
ret i32 %115
}

LLVM IR (-O2):
@SQLITE_OK = global i32 0
@stderr = global i32 0
@.str = [36 x i8] c"ERROR, failed to open database: %s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [144 x i8] c"create table messages (message_id integer primary key autoincrement, source text, sub_source text, type integer, date_time text, read integer);\00"
@.str.2 = [44 x i8] c"ERROR creating '%s' table in the database.\0A\00"
@.str.3 = [8 x i8] c"message\00"
@.str.4 = [113 x i8] c"create table client (client_id integer primary key autoincrement, state integer, date_time text, username text);\00"
@.str.5 = [7 x i8] c"client\00"
@.str.6 = [123 x i8] c"create table clients_actions (client_id integer foreign key, command text, parameters text, data integer, date_time text);\00"
@.str.7 = [16 x i8] c"clients_actions\00"
@.str.8 = [98 x i8] c"create table response_type (reponse_type_id integer primary key autoincrement, description text);\00"
@.str.9 = [14 x i8] c"response_type\00"
@.str.10 = [157 x i8] c"create table responses (reponses_id integer primary key autoincrement, response_type_id integer foreign key, date_time text, attack_id integer foreign key);\00"
@.str.11 = [10 x i8] c"responses\00"
@.str.12 = [120 x i8] c"create table attack (attack_id integer primary key autoincrement, source_name text, date_time text, victim_id integer);\00"
@.str.13 = [7 x i8] c"attack\00"
@.str.14 = [129 x i8] c"create table sensor (sensor_id integer primary key autoincrement, state integer, date_time, text, mac_addr text, username text);\00"
@.str.15 = [7 x i8] c"sensor\00"
@.str.16 = [107 x i8] c"create table invalid_frames (sensor_id integer foreign key, fail_count integer, invalid_protocol integer);\00"
@.str.17 = [15 x i8] c"invalid_frames\00"
@.str.18 = [284 x i8] c"create table frames (frame_id integer primary key autoincrement, sourceID integer, frame_type integer, frame_subtype integer, protected integer, addr_1 text, addr_2 text, addr_3 text, addr_4 text, to_dest integer, from_dest integer, retry integer, frag_num integer, seq_num integer);\00"
@.str.19 = [7 x i8] c"frames\00"
@.str.20 = [166 x i8] c"create table banlist (banlist_id integer primary key autoincrement, mac_addr text, is_AP integer, ban_creation_time text, ban_length_sec integer, is_active integer);\00"
@.str.21 = [8 x i8] c"banlist\00"
@EXIT_SUCCESS = global i32 0
define i32 @init_database(i8* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = bitcast i32** %2 to i8*
store i32* null, i32** %2
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = call i32 @sqlite3_open(i8* %0, i32** %2)
%7 = load i32, i32* @SQLITE_OK
%8 = icmp eq i32 %6, %7
br i1 %8, label %14, label %9
9: ; preds = %1
%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 ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %105
14: ; preds = %1
%15 = load i32*, i32** %2
%16 = call i32 @sqlite3_exec(i32* %15, i8* getelementptr inbounds ([144 x i8], [144 x i8]* @.str.1, i64 0, i64 0), i32* null, i32* null, i8** %3)
%17 = load i8*, i8** %3
%18 = icmp eq i8* %17, null
br i1 %18, label %23, label %19
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%22 = call i32 @sqlite3_free(i8** %3)
br label %23
23: ; preds = %19, %14
store i8* null, i8** %3
%24 = load i32*, i32** %2
%25 = call i32 @sqlite3_exec(i32* %24, i8* getelementptr inbounds ([113 x i8], [113 x i8]* @.str.4, i64 0, i64 0), i32* null, i32* null, i8** %3)
%26 = load i8*, i8** %3
%27 = icmp eq i8* %26, null
br i1 %27, label %32, label %28
28: ; preds = %23
%29 = load i32, i32* @stderr
%30 = call i32 @fprintf(i32 %29, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @sqlite3_free(i8** %3)
br label %32
32: ; preds = %28, %23
store i8* null, i8** %3
%33 = load i32*, i32** %2
%34 = call i32 @sqlite3_exec(i32* %33, i8* getelementptr inbounds ([123 x i8], [123 x i8]* @.str.6, i64 0, i64 0), i32* null, i32* null, i8** %3)
%35 = load i8*, i8** %3
%36 = icmp eq i8* %35, null
br i1 %36, label %41, label %37
37: ; preds = %32
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%40 = call i32 @sqlite3_free(i8** %3)
br label %41
41: ; preds = %37, %32
store i8* null, i8** %3
%42 = load i32*, i32** %2
%43 = call i32 @sqlite3_exec(i32* %42, i8* getelementptr inbounds ([98 x i8], [98 x i8]* @.str.8, i64 0, i64 0), i32* null, i32* null, i8** %3)
%44 = load i8*, i8** %3
%45 = icmp eq i8* %44, null
br i1 %45, label %50, label %46
46: ; preds = %41
%47 = load i32, i32* @stderr
%48 = call i32 @fprintf(i32 %47, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.9, i64 0, i64 0))
%49 = call i32 @sqlite3_free(i8** %3)
br label %50
50: ; preds = %46, %41
store i8* null, i8** %3
%51 = load i32*, i32** %2
%52 = call i32 @sqlite3_exec(i32* %51, i8* getelementptr inbounds ([157 x i8], [157 x i8]* @.str.10, i64 0, i64 0), i32* null, i32* null, i8** %3)
%53 = load i8*, i8** %3
%54 = icmp eq i8* %53, null
br i1 %54, label %59, label %55
55: ; preds = %50
%56 = load i32, i32* @stderr
%57 = call i32 @fprintf(i32 %56, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.11, i64 0, i64 0))
%58 = call i32 @sqlite3_free(i8** %3)
br label %59
59: ; preds = %55, %50
store i8* null, i8** %3
%60 = load i32*, i32** %2
%61 = call i32 @sqlite3_exec(i32* %60, i8* getelementptr inbounds ([120 x i8], [120 x i8]* @.str.12, i64 0, i64 0), i32* null, i32* null, i8** %3)
%62 = load i8*, i8** %3
%63 = icmp eq i8* %62, null
br i1 %63, label %68, label %64
64: ; preds = %59
%65 = load i32, i32* @stderr
%66 = call i32 @fprintf(i32 %65, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%67 = call i32 @sqlite3_free(i8** %3)
br label %68
68: ; preds = %64, %59
store i8* null, i8** %3
%69 = load i32*, i32** %2
%70 = call i32 @sqlite3_exec(i32* %69, i8* getelementptr inbounds ([129 x i8], [129 x i8]* @.str.14, i64 0, i64 0), i32* null, i32* null, i8** %3)
%71 = load i8*, i8** %3
%72 = icmp eq i8* %71, null
br i1 %72, label %77, label %73
73: ; preds = %68
%74 = load i32, i32* @stderr
%75 = call i32 @fprintf(i32 %74, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.15, i64 0, i64 0))
%76 = call i32 @sqlite3_free(i8** %3)
br label %77
77: ; preds = %73, %68
store i8* null, i8** %3
%78 = load i32*, i32** %2
%79 = call i32 @sqlite3_exec(i32* %78, i8* getelementptr inbounds ([107 x i8], [107 x i8]* @.str.16, i64 0, i64 0), i32* null, i32* null, i8** %3)
%80 = load i8*, i8** %3
%81 = icmp eq i8* %80, null
br i1 %81, label %86, label %82
82: ; preds = %77
%83 = load i32, i32* @stderr
%84 = call i32 @fprintf(i32 %83, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.17, i64 0, i64 0))
%85 = call i32 @sqlite3_free(i8** %3)
br label %86
86: ; preds = %82, %77
store i8* null, i8** %3
%87 = load i32*, i32** %2
%88 = call i32 @sqlite3_exec(i32* %87, i8* getelementptr inbounds ([284 x i8], [284 x i8]* @.str.18, i64 0, i64 0), i32* null, i32* null, i8** %3)
%89 = load i8*, i8** %3
%90 = icmp eq i8* %89, null
br i1 %90, label %95, label %91
91: ; preds = %86
%92 = load i32, i32* @stderr
%93 = call i32 @fprintf(i32 %92, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.19, i64 0, i64 0))
%94 = call i32 @sqlite3_free(i8** %3)
br label %95
95: ; preds = %91, %86
store i8* null, i8** %3
%96 = load i32*, i32** %2
%97 = call i32 @sqlite3_exec(i32* %96, i8* getelementptr inbounds ([166 x i8], [166 x i8]* @.str.20, i64 0, i64 0), i32* null, i32* null, i8** %3)
%98 = load i8*, i8** %3
%99 = icmp eq i8* %98, null
br i1 %99, label %104, label %100
100: ; preds = %95
%101 = load i32, i32* @stderr
%102 = call i32 @fprintf(i32 %101, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.21, i64 0, i64 0))
%103 = call i32 @sqlite3_free(i8** %3)
br label %104
104: ; preds = %100, %95
store i8* null, i8** %3
br label %105
105: ; preds = %104, %9
%106 = phi i32* [ @EXIT_FAILURE, %9 ], [ @EXIT_SUCCESS, %104 ]
%107 = load i32*, i32** %2
%108 = call i32 @sqlite3_close(i32* %107)
%109 = load i32, i32* %106
ret i32 %109
}