// File: /workspace/github_c_makefile_star2_O0/antirez[P]stonky/stonky.c
// Function: dbInit
sqlite3 *dbInit(int createdb) {
    sqlite3 *db;
    int rt = sqlite3_open(DbFile, &db);
    if (rt != SQLITE_OK) {
        fprintf(stderr, "Cannot open database: %s\n", sqlite3_errmsg(db));
        sqlite3_close(db);
        return NULL;
    }

    if (createdb) {
        char *sql =
    "CREATE TABLE IF NOT EXISTS Lists(name TEXT COLLATE NOCASE);"
    "CREATE INDEX IF NOT EXISTS idx_lists_name ON Lists(name);"

    "CREATE TABLE IF NOT EXISTS ListStock(listid INT, "
                                          "symbol TEXT COLLATE NOCASE);"
    "CREATE INDEX IF NOT EXISTS idx_liststock_listid ON ListStock(listid);"
    "CREATE INDEX IF NOT EXISTS idx_liststock_ls ON ListStock(listid,symbol);"

    "CREATE TABLE IF NOT EXISTS StockPack(liststockid INT, "
                                          "quantity INT, "
                                          "avgprice REAL);"
    "CREATE INDEX IF NOT EXISTS idx_stockpack_lsid ON StockPack(liststockid);"
    "CREATE TABLE IF NOT EXISTS ProfitLoss(symbol TEXT COLLATE NOCASE, "
                                          "listid INT, "
                                          "selltime INT, "
                                          "quantity INT, "
                                          "buyprice REAL,"
                                          "sellprice REAL,"
                                          "csym TEXT);" /* Currency symbol. */
    "CREATE INDEX IF NOT EXISTS idx_profitloss_lsid ON ProfitLoss(listid);"
    "CREATE TABLE IF NOT EXISTS KeyValue(expire INT, "
                                        "key TEXT, "
                                        "value BLOB);"
    "CREATE UNIQUE INDEX IF NOT EXISTS idx_kv_key ON KeyValue(key);"
    "CREATE INDEX IF NOT EXISTS idx_ex_key ON KeyValue(expire);"
    ;

        char *errmsg;
        int rc = sqlite3_exec(db, sql, 0, 0, &errmsg);
        if (rc != SQLITE_OK) {
            fprintf(stderr, "SQL error [%d]: %s\n", rc, errmsg);
            sqlite3_free(errmsg);
            sqlite3_close(db);
            return NULL;
        }
    }
    return db;
}

// Assembly:
subq $0x48, %rsp
movl %edi, 0x3c(%rsp)
movq 0xd2b9(%rip), %rdi      # 0x1b248
leaq 0x30(%rsp), %rsi
callq 0x23e0
movl %eax, 0x2c(%rsp)
cmpl $0x0, 0x2c(%rsp)
je 0xdfeb
movq 0xd02d(%rip), %rax      # 0x1afd8
movq (%rax), %rax
movq %rax, 0x8(%rsp)
movq 0x30(%rsp), %rdi
callq 0x2220
movq 0x8(%rsp), %rdi
movq %rax, %rdx
leaq 0x7973(%rip), %rsi      # 0x1593f
movb $0x0, %al
callq 0x2340
movq 0x30(%rsp), %rdi
callq 0x2110
movq $0x0, 0x40(%rsp)
jmp 0xe070
cmpl $0x0, 0x3c(%rsp)
je 0xe066
leaq 0x7960(%rip), %rax      # 0x15959
movq %rax, 0x20(%rsp)
movq 0x30(%rsp), %rdi
movq 0x20(%rsp), %rsi
xorl %eax, %eax
movl %eax, %ecx
leaq 0x18(%rsp), %r8
movq %rcx, %rdx
callq 0x2300
movl %eax, 0x14(%rsp)
cmpl $0x0, 0x14(%rsp)
je 0xe064
movq 0xcfad(%rip), %rax      # 0x1afd8
movq (%rax), %rdi
movl 0x14(%rsp), %edx
movq 0x18(%rsp), %rcx
leaq 0x7c9a(%rip), %rsi      # 0x15cd8
movb $0x0, %al
callq 0x2340
movq 0x18(%rsp), %rdi
callq 0x22c0
movq 0x30(%rsp), %rdi
callq 0x2110
movq $0x0, 0x40(%rsp)
jmp 0xe070
jmp 0xe066
movq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
addq $0x48, %rsp
retq
nopw (%rax,%rax)