// File: eiskalteschatten[P]developersnotebook/src/db/SqliteSchema.cpp
// Function: SqliteSchema::setup_db()
void SqliteSchema::setup_db() {
    try {
        SqliteConnectionManager connection_manager;
        char *error_message = 0;
        int connection;

        for (unsigned int i = 0; i < SqliteSchema::all_tables.size(); i++) {
            SqliteSchema::TableSchema table = SqliteSchema::all_tables[i];
            std::vector<SqliteSchema::ColumnSchema> table_columns = table.columns;

            std::string create_sql = "CREATE TABLE IF NOT EXISTS " +
                                     table.table_name +
                                     "(id INTEGER PRIMARY KEY AUTOINCREMENT,";

            std::string insert_sql_columns = "id, ";
            std::string insert_sql_values  = "1, ";

            for (unsigned int c = 0; c < table_columns.size(); c++) {
                create_sql += table_columns[c].column_name + " ";
                create_sql += table_columns[c].type + " ";
                create_sql += table_columns[c].null_status;

                if (table.create_first_row) {
                    insert_sql_columns += table_columns[c].column_name;
                    insert_sql_values  += table_columns[c].default_value;
                }

                if ((c + 1) < table_columns.size()) {
                    create_sql         += ",";

                    if (table.create_first_row) {
                        insert_sql_columns += ",";
                        insert_sql_values  += ",";
                    }
                }
            }

            create_sql += ");";

            connection = sqlite3_exec(connection_manager.get_db(), create_sql.c_str(), NULL, 0, &error_message);

            if(connection != SQLITE_OK) {
                fprintf(stderr, "SQL error: %s\n", error_message);
                sqlite3_free(error_message);
            }

            if (table.create_first_row) {
                std::string insert_sql = "INSERT OR IGNORE INTO " + table.table_name +
                                         " (" + insert_sql_columns + ")" +
                                         " VALUES (" + insert_sql_values + ");";

                connection = sqlite3_exec(connection_manager.get_db(), insert_sql.c_str(), NULL, 0, &error_message);

                if(connection != SQLITE_OK) {
                    fprintf(stderr, "SQL error: %s\n", error_message);
                    sqlite3_free(error_message);
                }
            }
        }
    }
    catch(const std::exception& e) {
        fprintf(stderr, "An exception occured while trying to set up the database: %s\n", e.what());
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x290, %rsp            # imm = 0x290
leaq -0x8(%rbp), %rdi
callq 0x1cc70
jmp 0x1cd36
movq $0x0, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq %rax, -0x240(%rbp)
leaq 0x59b0a(%rip), %rdi     # 0x76860
callq 0x1d7d0
movq %rax, %rcx
movq -0x240(%rbp), %rax
cmpq %rcx, %rax
jae 0x1d46a
movl -0x28(%rbp), %eax
movl %eax, %esi
leaq 0x59ae6(%rip), %rdi     # 0x76860
callq 0x1d7f0
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x1d630
jmp 0x1cd8d
leaq -0x48(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x1d810
jmp 0x1cd9c
leaq 0x369c4(%rip), %rsi     # 0x53767
leaq -0xc0(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x110c0
jmp 0x1cdb5
leaq 0x369c7(%rip), %rdx     # 0x53783
leaq -0xa0(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x10eb0
jmp 0x1cdd1
leaq -0xc0(%rbp), %rdi
callq 0xb430
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x248(%rbp)
callq 0xaf80
movq -0x248(%rbp), %rdx
leaq 0x369ac(%rip), %rsi     # 0x537aa
leaq -0xe0(%rbp), %rdi
callq 0x10f00
jmp 0x1ce0c
leaq -0xe1(%rbp), %rdi
callq 0xb410
leaq -0x109(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0xaf80
movq -0x250(%rbp), %rdx
leaq 0x36976(%rip), %rsi     # 0x537af
leaq -0x108(%rbp), %rdi
callq 0x10f00
jmp 0x1ce47
leaq -0x109(%rbp), %rdi
callq 0xb410
movl $0x0, -0x110(%rbp)
movl -0x110(%rbp), %eax
movq %rax, -0x258(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x1d900
movq %rax, %rcx
movq -0x258(%rbp), %rax
cmpq %rcx, %rax
jae 0x1d10a
movl -0x110(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x1d920
movq %rax, %rsi
leaq 0x36910(%rip), %rdx     # 0x537b1
leaq -0x130(%rbp), %rdi
callq 0x10fb0
jmp 0x1ceaf
leaq -0xa0(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xa140
jmp 0x1cec4
leaq -0x130(%rbp), %rdi
callq 0xb430
movl -0x110(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x1d920
movq %rax, %rsi
addq $0x20, %rsi
leaq 0x368c2(%rip), %rdx     # 0x537b1
leaq -0x150(%rbp), %rdi
callq 0x10fb0
jmp 0x1cefd
leaq -0xa0(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xa140
jmp 0x1cf12
leaq -0x150(%rbp), %rdi
callq 0xb430
movl -0x110(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x1d920
movq %rax, %rsi
addq $0x40, %rsi
leaq -0xa0(%rbp), %rdi
callq 0xa140
jmp 0x1cf44
testb $0x1, -0x30(%rbp)
je 0x1d081
movl -0x110(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x1d920
movq %rax, %rsi
leaq -0xe0(%rbp), %rdi
callq 0xa140
jmp 0x1cf70
movl -0x110(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x1d920
movq %rax, %rsi
addq $0x60, %rsi
leaq -0x108(%rbp), %rdi
callq 0xa140
jmp 0x1cf96
jmp 0x1d081
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d47e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d475
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d45f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d456
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xb430
jmp 0x1d456
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0xe1(%rbp), %rdi
callq 0xb410
jmp 0x1d44a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x109(%rbp), %rdi
callq 0xb410
jmp 0x1d43e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d432
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x130(%rbp), %rdi
callq 0xb430
jmp 0x1d432
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x150(%rbp), %rdi
callq 0xb430
jmp 0x1d432
movl -0x110(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
movq %rax, -0x260(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x1d900
movq %rax, %rcx
movq -0x260(%rbp), %rax
cmpq %rcx, %rax
jae 0x1d0f4
leaq 0x36af2(%rip), %rsi     # 0x53ba4
leaq -0xa0(%rbp), %rdi
callq 0xa240
jmp 0x1d0c0
testb $0x1, -0x30(%rbp)
je 0x1d0f2
leaq 0x36ad7(%rip), %rsi     # 0x53ba4
leaq -0xe0(%rbp), %rdi
callq 0xa240
jmp 0x1d0db
leaq 0x36ac2(%rip), %rsi     # 0x53ba4
leaq -0x108(%rbp), %rdi
callq 0xa240
jmp 0x1d0f0
jmp 0x1d0f2
jmp 0x1d0f4
jmp 0x1d0f6
movl -0x110(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x110(%rbp)
jmp 0x1ce5d
leaq 0x366a2(%rip), %rsi     # 0x537b3
leaq -0xa0(%rbp), %rdi
callq 0xa240
jmp 0x1d11f
leaq -0x8(%rbp), %rdi
callq 0x1d940
movq %rax, -0x268(%rbp)
jmp 0x1d131
leaq -0xa0(%rbp), %rdi
callq 0xa1d0
movq -0x268(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x20(%rbp), %r8
movq %rcx, %rdx
callq 0xa0e0
movl %eax, -0x26c(%rbp)
jmp 0x1d15f
movl -0x26c(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1d197
movq 0x57e0b(%rip), %rax     # 0x74f80
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x36633(%rip), %rsi     # 0x537b6
xorl %eax, %eax
callq 0xa320
movq -0x20(%rbp), %rdi
callq 0xb360
jmp 0x1d195
jmp 0x1d197
testb $0x1, -0x30(%rbp)
je 0x1d3ee
leaq 0x3661d(%rip), %rsi     # 0x537c5
leaq -0x230(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x110c0
jmp 0x1d1ba
leaq 0x36622(%rip), %rdx     # 0x537e3
leaq -0x210(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x10eb0
jmp 0x1d1d6
leaq -0x1f0(%rbp), %rdi
leaq -0x210(%rbp), %rsi
leaq -0xe0(%rbp), %rdx
callq 0x14a70
jmp 0x1d1f2
leaq 0x3723d(%rip), %rdx     # 0x54436
leaq -0x1d0(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
callq 0x10eb0
jmp 0x1d20e
leaq 0x365c7(%rip), %rdx     # 0x537dc
leaq -0x1b0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x10eb0
jmp 0x1d22a
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
leaq -0x108(%rbp), %rdx
callq 0x14a70
jmp 0x1d246
leaq 0x36566(%rip), %rdx     # 0x537b3
leaq -0x170(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x10eb0
jmp 0x1d262
leaq -0x190(%rbp), %rdi
callq 0xb430
leaq -0x1b0(%rbp), %rdi
callq 0xb430
leaq -0x1d0(%rbp), %rdi
callq 0xb430
leaq -0x1f0(%rbp), %rdi
callq 0xb430
leaq -0x210(%rbp), %rdi
callq 0xb430
leaq -0x230(%rbp), %rdi
callq 0xb430
leaq -0x8(%rbp), %rdi
callq 0x1d940
movq %rax, -0x278(%rbp)
jmp 0x1d2bc
leaq -0x170(%rbp), %rdi
callq 0xa1d0
movq -0x278(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq -0x20(%rbp), %r8
movq %rcx, %rdx
callq 0xa0e0
movl %eax, -0x27c(%rbp)
jmp 0x1d2ea
movl -0x27c(%rbp), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
je 0x1d3e2
movq 0x57c7c(%rip), %rax     # 0x74f80
movq (%rax), %rdi
movq -0x20(%rbp), %rdx
leaq 0x364a4(%rip), %rsi     # 0x537b6
xorl %eax, %eax
callq 0xa320
movq -0x20(%rbp), %rdi
callq 0xb360
jmp 0x1d324
jmp 0x1d3e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d3ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d3ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d3a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d396
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
jmp 0x1d38a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x190(%rbp), %rdi
callq 0xb430
leaq -0x1b0(%rbp), %rdi
callq 0xb430
leaq -0x1d0(%rbp), %rdi
callq 0xb430
leaq -0x1f0(%rbp), %rdi
callq 0xb430
leaq -0x210(%rbp), %rdi
callq 0xb430
leaq -0x230(%rbp), %rdi
callq 0xb430
jmp 0x1d432
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x10(%rbp)
movl %eax, -0x14(%rbp)
leaq -0x170(%rbp), %rdi
callq 0xb430
jmp 0x1d432
leaq -0x170(%rbp), %rdi
callq 0xb430
leaq -0x108(%rbp), %rdi
callq 0xb430
leaq -0xe0(%rbp), %rdi
callq 0xb430
leaq -0xa0(%rbp), %rdi
callq 0xb430
leaq -0x80(%rbp), %rdi
callq 0x1d960
leaq -0x68(%rbp), %rdi
callq 0x1d600
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x1cd45
leaq -0x108(%rbp), %rdi
callq 0xb430
leaq -0xe0(%rbp), %rdi
callq 0xb430
leaq -0xa0(%rbp), %rdi
callq 0xb430
leaq -0x80(%rbp), %rdi
callq 0x1d960
leaq -0x68(%rbp), %rdi
callq 0x1d600
jmp 0x1d475
leaq -0x8(%rbp), %rdi
callq 0x1ccf0
jmp 0x1d4d5
leaq -0x8(%rbp), %rdi
callq 0x1ccf0
movl -0x14(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x1d4de
movq -0x10(%rbp), %rdi
callq 0xa0b0
movq %rax, -0x238(%rbp)
movq 0x57adf(%rip), %rax     # 0x74f80
movq (%rax), %rax
movq %rax, -0x288(%rbp)
movq -0x238(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movq -0x288(%rbp), %rdi
movq %rax, %rdx
leaq 0x3631d(%rip), %rsi     # 0x537e6
movb $0x0, %al
callq 0xa320
callq 0xac00
addq $0x290, %rsp            # imm = 0x290
popq %rbp
retq
movq -0x10(%rbp), %rdi
callq 0xaa00
nopw (%rax,%rax)