// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1b8, %rsp            # imm = 0x1B8
leaq 0x10(%rsp), %rdi
callq 0xf86c
leaq 0x8(%rsp), %rax
andq $0x0, (%rax)
leaq 0x98(%rsp), %r14
leaq 0x178(%rsp), %r13
leaq 0x78(%rsp), %rbx
leaq 0x12c6d(%rip), %r12     # 0x22581
leaq 0x12fc9(%rip), %r15     # 0x228e4
xorl %ecx, %ecx
movl %ecx, %ecx
movq 0x23d32(%rip), %rax     # 0x33658
movq 0x23d23(%rip), %rsi     # 0x33650
subq %rsi, %rax
sarq $0x6, %rax
cmpq %rcx, %rax
jbe 0xfcc2
movq %rcx, 0x30(%rsp)
movq %rcx, %rax
shlq $0x6, %rax
addq %rax, %rsi
movq %r14, %rdi
callq 0xfebc
leaq 0x18(%rsp), %rdi
leaq 0xb8(%rsp), %rsi
callq 0xff56
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
leaq 0x12bc2(%rip), %rsi     # 0x22537
movq %r14, %rdx
callq 0xb117
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x12bc9(%rip), %rdx     # 0x22553
callq 0xb059
movq %rbp, %rdi
callq 0x9120
movq %rbp, %rdi
leaq 0x12bd9(%rip), %rsi     # 0x2257a
leaq 0x58(%rsp), %r14
movq %r14, %rdx
callq 0xb078
movq %r14, %rdi
leaq 0x12bc7(%rip), %rsi     # 0x2257f
movq %rbx, %rdx
callq 0xb078
pushq $0x1
popq %rax
movl %eax, %r14d
leal -0x1(%r14), %ebp
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rax
subq %rsi, %rax
sarq $0x7, %rax
cmpq %rbp, %rax
jbe 0xfac9
shlq $0x7, %rbp
addq %rbp, %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0xb0b3
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8bc0
movq %rbx, %rdi
callq 0x9120
movq 0x18(%rsp), %rax
leaq (%rax,%rbp), %rsi
addq $0x20, %rsi
movq %rbx, %rdi
movq %r12, %rdx
callq 0xb0b3
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8bc0
movq %rbx, %rdi
callq 0x9120
movq 0x18(%rsp), %rax
leaq (%rax,%rbp), %rsi
addq $0x40, %rsi
movq %r13, %rdi
callq 0x8bc0
cmpb $0x1, 0xd0(%rsp)
jne 0xfa7c
movq 0x18(%rsp), %rsi
addq %rbp, %rsi
leaq 0x38(%rsp), %rdi
callq 0x8bc0
movq 0x18(%rsp), %rax
leaq (%rax,%rbp), %rsi
addq $0x60, %rsi
leaq 0x58(%rsp), %rdi
callq 0x8bc0
movl %r14d, %eax
movq 0x20(%rsp), %rcx
subq 0x18(%rsp), %rcx
sarq $0x7, %rcx
cmpq %rax, %rcx
jbe 0xfac1
movq %r13, %rdi
movq %r15, %rsi
callq 0x8830
cmpb $0x1, 0xd0(%rsp)
jne 0xfac1
leaq 0x38(%rsp), %rdi
movq %r15, %rsi
callq 0x8830
leaq 0x58(%rsp), %rdi
movq %r15, %rsi
callq 0x8830
incl %r14d
jmp 0xf9c6
movq %r13, %rdi
leaq 0x12ab0(%rip), %rsi     # 0x22583
callq 0x8830
movq 0x10(%rsp), %rdi
movq 0x178(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x8(%rsp), %r8
callq 0x80c0
testl %eax, %eax
jne 0xfc6a
cmpb $0x1, 0xd0(%rsp)
leaq 0x98(%rsp), %r14
jne 0xfc30
leaq 0xd8(%rsp), %rbp
movq %rbp, %rdi
leaq 0x12a72(%rip), %rsi     # 0x22595
movq %r14, %rdx
callq 0xb117
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x12a73(%rip), %rdx     # 0x225b3
callq 0xb059
leaq 0x118(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
leaq 0x38(%rsp), %rdx
callq 0xbabb
leaq 0x138(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x13606(%rip), %rdx     # 0x23178
callq 0xb059
leaq 0x158(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
leaq 0x12a20(%rip), %rdx     # 0x225ac
callq 0xb059
leaq 0x198(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
leaq 0x58(%rsp), %rdx
callq 0xbabb
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x129cd(%rip), %rdx     # 0x22583
callq 0xb059
movq %r14, %rdi
callq 0x9120
leaq 0x158(%rsp), %rdi
callq 0x9120
leaq 0x138(%rsp), %rdi
callq 0x9120
leaq 0x118(%rsp), %rdi
callq 0x9120
leaq 0xf8(%rsp), %rdi
callq 0x9120
leaq 0xd8(%rsp), %rdi
callq 0x9120
movq 0x10(%rsp), %rdi
movq 0x78(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
leaq 0x8(%rsp), %r8
callq 0x80c0
testl %eax, %eax
jne 0xfc96
movq %rbx, %rdi
callq 0x9120
leaq 0x98(%rsp), %r14
leaq 0x58(%rsp), %rdi
callq 0x9120
leaq 0x38(%rsp), %rdi
callq 0x9120
movq %r13, %rdi
callq 0x9120
leaq 0x18(%rsp), %rdi
callq 0xffaa
movq %r14, %rdi
callq 0xfea6
movq 0x30(%rsp), %rcx
incl %ecx
jmp 0xf91d
movq 0x2231f(%rip), %rax     # 0x31f90
movq (%rax), %rdi
movq 0x8(%rsp), %rdx
leaq 0x12906(%rip), %rsi     # 0x22586
xorl %eax, %eax
callq 0x8250
movq 0x8(%rsp), %rdi
callq 0x9060
jmp 0xfafb
movq 0x222f3(%rip), %rax     # 0x31f90
movq (%rax), %rdi
movq 0x8(%rsp), %rdx
leaq 0x128da(%rip), %rsi     # 0x22586
xorl %eax, %eax
callq 0x8250
movq 0x8(%rsp), %rdi
callq 0x9060
jmp 0xfc20
leaq 0x10(%rsp), %rdi
callq 0xf8c0
addq $0x1b8, %rsp            # imm = 0x1B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfe00
movq %rdx, %rbx
movq %rax, %r14
leaq 0x198(%rsp), %rdi
callq 0x9120
jmp 0xfd19
jmp 0xfdb8
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfd5d
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfd3b
movq %rdx, %rbx
movq %rax, %r14
leaq 0x158(%rsp), %rdi
callq 0x9120
jmp 0xfd2e
movq %rdx, %rbx
movq %rax, %r14
leaq 0x138(%rsp), %rdi
callq 0x9120
leaq 0x118(%rsp), %rdi
callq 0x9120
jmp 0xfd50
movq %rdx, %rbx
movq %rax, %r14
leaq 0xf8(%rsp), %rdi
callq 0x9120
leaq 0xd8(%rsp), %rdi
jmp 0xfdad
jmp 0xfda2
movq %rdx, %rbx
movq %rax, %r14
leaq 0x38(%rsp), %rdi
jmp 0xfdda
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfde9
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfdc8
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfdf6
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfddf
movq %rdx, %rbx
movq %rax, %r14
jmp 0xfdd2
jmp 0xfdb8
jmp 0xfda2
movq %rdx, %rbx
movq %rax, %r14
leaq 0x78(%rsp), %rdi
callq 0x9120
jmp 0xfdbe
jmp 0xfdb8
jmp 0xfdb8
movq %rdx, %rbx
movq %rax, %r14
leaq 0x58(%rsp), %rdi
callq 0x9120
leaq 0x38(%rsp), %rdi
callq 0x9120
leaq 0x178(%rsp), %rdi
callq 0x9120
leaq 0x18(%rsp), %rdi
callq 0xffaa
leaq 0x98(%rsp), %rdi
callq 0xfea6
leaq 0x10(%rsp), %rdi
callq 0xf8c0
movq %r14, %rdi
cmpl $0x1, %ebx
jne 0xfe3e
callq 0x8090
movq 0x2217c(%rip), %rcx     # 0x31f90
movq (%rcx), %rbx
movq (%rax), %rcx
movq %rax, %rdi
callq *0x10(%rcx)
leaq 0x1278f(%rip), %rsi     # 0x225b6
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x8250
callq 0x89d0
jmp 0xfccc
callq 0x87f0
nop