// File: Konano[P]UselessDatabase/Database.cpp
// Function: Database::Database(char const*, bool)
Database::Database(const char* name, bool create) {
    fm = new FileManager();
    bpm = new BufPageManager(fm);
    memset(table, 0, sizeof(table));
    table_num = 0;
    mem = 0;
    if (create) {
        strcpy(this->name, name); 
        char* dbdir = dirPath(this->name);
        if (access("db", 0) == -1) {
            #ifdef WIN32
            mkdir("db");
            #elif __linux__
            mkdir("db", 0777);
            #endif
        }
        if (access(dbdir, 0) == -1) {
            #ifdef WIN32
            mkdir(dbdir);
            #elif __linux__
            mkdir(dbdir, 0777);
            #endif
        }
        update();
        fm->createFile(dirPath(name, ".storage"));
    } else {
        fromJson(json::parse(readFile(dirPath(name, "database.udb"))));
    }
    fm->openFile(dirPath(name, ".storage"), mem_file);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movb %dl, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
andb $0x1, %al
movb %al, -0x11(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x90(%rbp)
addq $0x848, %rax            # imm = 0x848
movq %rax, -0x88(%rbp)
movq %rax, %rcx
addq $0x8000, %rcx           # imm = 0x8000
movq %rcx, -0x80(%rbp)
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0xba30
movq -0x98(%rbp), %rax
movq -0x80(%rbp), %rcx
addq $0x80, %rax
cmpq %rcx, %rax
movq %rax, -0x78(%rbp)
jne 0x7974
movq -0x90(%rbp), %rax
movl $0x0, 0x9048(%rax)
movl $0x220, %edi            # imm = 0x220
callq 0x64a0
movq %rax, -0xa0(%rbp)
jmp 0x79c2
movq -0xa0(%rbp), %rdi
callq 0x34d20
jmp 0x79d0
movq -0x90(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rcx, 0x828(%rax)
movl $0x110030, %edi         # imm = 0x110030
callq 0x64a0
movq %rax, -0xa8(%rbp)
jmp 0x79f8
movq -0xa8(%rbp), %rdi
movq -0x90(%rbp), %rax
movq 0x828(%rax), %rsi
callq 0x6ea0
jmp 0x7a14
movq -0x90(%rbp), %rdi
movq -0xa8(%rbp), %rax
movq %rax, 0x830(%rdi)
addq $0x20, %rdi
xorl %esi, %esi
movl $0x800, %edx            # imm = 0x800
callq 0x62c0
movq -0x90(%rbp), %rax
movl $0x0, 0x820(%rax)
movq $0x0, 0x840(%rax)
testb $0x1, -0x11(%rbp)
je 0x7b7e
movq -0x90(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x6460
movq -0x90(%rbp), %rdi
callq 0x35150
movq %rax, -0xb0(%rbp)
jmp 0x7a84
movq -0xb0(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq 0x7c3b2(%rip), %rdi     # 0x83e48
xorl %esi, %esi
callq 0x6830
cmpl $-0x1, %eax
jne 0x7b0a
leaq 0x7c39f(%rip), %rdi     # 0x83e48
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x6280
jmp 0x7b0a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x7cad
movq -0xa0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x220, %esi            # imm = 0x220
callq 0x64b0
jmp 0x7cad
movq -0xa8(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
movl $0x110030, %esi         # imm = 0x110030
callq 0x64b0
jmp 0x7cad
movq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x6830
cmpl $-0x1, %eax
jne 0x7b28
movq -0x30(%rbp), %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x6280
movq -0x90(%rbp), %rdi
callq 0x7860
jmp 0x7b36
movq -0x90(%rbp), %rax
movq 0x828(%rax), %rax
movq %rax, -0xc0(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x76ed3(%rip), %rsi     # 0x7ea29
callq 0x351b0
movq %rax, -0xb8(%rbp)
jmp 0x7b64
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdi
callq 0x34e40
jmp 0x7b79
jmp 0x7c53
movq -0x10(%rbp), %rdi
leaq 0x76e93(%rip), %rsi     # 0x7ea1c
callq 0x351b0
movq %rax, -0xc8(%rbp)
jmp 0x7b97
movq -0xc8(%rbp), %rdi
callq 0x35050
movq %rax, -0xd0(%rbp)
jmp 0x7bac
movq -0xd0(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xbc20
jmp 0x7bbe
xorl %eax, %eax
movl %eax, %esi
leaq -0x70(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0xbc60
movq -0xd8(%rbp), %rdx
leaq -0x40(%rbp), %rdi
leaq -0x50(%rbp), %rsi
movl $0x1, %ecx
callq 0xba90
jmp 0x7bed
movq -0x90(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x76c0
jmp 0x7bff
leaq -0x40(%rbp), %rdi
callq 0xb110
leaq -0x70(%rbp), %rdi
callq 0xbca0
leaq -0x50(%rbp), %rdi
callq 0xbcc0
jmp 0x7c53
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x7c3f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xb110
leaq -0x70(%rbp), %rdi
callq 0xbca0
leaq -0x50(%rbp), %rdi
callq 0xbcc0
jmp 0x7cad
movq -0x90(%rbp), %rax
movq 0x828(%rax), %rax
movq %rax, -0xe8(%rbp)
movq -0x10(%rbp), %rdi
leaq 0x76db6(%rip), %rsi     # 0x7ea29
callq 0x351b0
movq %rax, -0xe0(%rbp)
jmp 0x7c81
movq -0xe0(%rbp), %rsi
movq -0xe8(%rbp), %rdi
movq -0x90(%rbp), %rdx
addq $0x838, %rdx            # imm = 0x838
callq 0x34e90
jmp 0x7ca4
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x88(%rbp), %rax
addq $0x8000, %rax           # imm = 0x8000
movq %rax, -0xf0(%rbp)
movq -0xf0(%rbp), %rdi
addq $-0x80, %rdi
movq %rdi, -0xf8(%rbp)
callq 0xbce0
movq -0x88(%rbp), %rcx
movq -0xf8(%rbp), %rax
cmpq %rcx, %rax
movq %rax, -0xf0(%rbp)
jne 0x7cc1
jmp 0x7cf4
movq -0x20(%rbp), %rdi
callq 0x6890
nopl (%rax)