// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
movl $0x850, %eax            # imm = 0x850
xorps %xmm0, %xmm0
movb $0x0, -0x8(%rbx,%rax)
movups %xmm0, (%rbx,%rax)
movups %xmm0, 0x10(%rbx,%rax)
movups %xmm0, 0x20(%rbx,%rax)
movups %xmm0, 0x30(%rbx,%rax)
movups %xmm0, 0x40(%rbx,%rax)
movups %xmm0, 0x50(%rbx,%rax)
movups %xmm0, 0x60(%rbx,%rax)
movq $0x0, 0x70(%rbx,%rax)
subq $-0x80, %rax
cmpq $0x8850, %rax           # imm = 0x8850
jne 0x6dda
movl $0x0, 0x9048(%rbx)
movl $0x220, %edi            # imm = 0x220
callq 0x5390
movq %rax, %r15
movq %rax, %rdi
callq 0x17b3c
movq %r15, 0x828(%rbx)
movl $0x110030, %edi         # imm = 0x110030
callq 0x5390
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x661a
movq %r12, 0x830(%rbx)
leaq 0x20(%rbx), %rdi
movq $0x0, 0x840(%rbx)
movl $0x804, %edx            # imm = 0x804
xorl %esi, %esi
callq 0x5240
testb %bpl, %bpl
je 0x6f03
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5360
movq %rbx, %rdi
callq 0x17ec5
movq %rax, %r15
leaq 0x39e64(%rip), %rdi     # 0x40d00
xorl %esi, %esi
callq 0x5670
cmpl $-0x1, %eax
jne 0x6eb9
leaq 0x39e51(%rip), %rdi     # 0x40d00
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5200
movq %r15, %rdi
xorl %esi, %esi
callq 0x5670
cmpl $-0x1, %eax
jne 0x6ed5
movq %r15, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5200
movq %rbx, %rdi
callq 0x6cf6
movq 0x828(%rbx), %r15
leaq 0x357fa(%rip), %rsi     # 0x3c6e5
movq %r14, %rdi
callq 0x17efc
movq %r15, %rdi
movq %rax, %rsi
callq 0x17c64
jmp 0x6fdf
leaq 0x357ce(%rip), %rsi     # 0x3c6d8
movq %r14, %rdi
callq 0x17efc
movq %rax, %rdi
callq 0x17e14
movq %rax, %r15
movq %rax, %rdi
callq 0x51f0
movq %rax, %r12
movl $0x28, %edi
callq 0x5390
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x4ba69(%rip), %rcx     # 0x529b0
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x4baa8(%rip), %rdx     # 0x52a00
movq %rdx, 0x10(%rax)
movq %r15, 0x18(%rax)
addq %r15, %r12
testq %r15, %r15
cmoveq %r15, %r12
movq %r12, 0x20(%rax)
leaq 0x10(%rsp), %rsi
movq %rcx, (%rsi)
movq %rax, 0x8(%rsi)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, (%rdx)
movaps %xmm0, 0x10(%rdx)
movq %rsp, %rdi
movl $0x1, %ecx
callq 0x9604
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x6b92
movq %rsp, %rdi
callq 0xd118
leaq 0x8(%rsp), %rdi
movzbl -0x8(%rdi), %esi
callq 0xd1ba
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x6fd0
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x6fdf
callq 0x9dec
movq 0x828(%rbx), %r15
leaq 0x356f8(%rip), %rsi     # 0x3c6e5
movq %r14, %rdi
callq 0x17efc
leaq 0x838(%rbx), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x17c8c
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7050
movq %rax, %r14
movq %rsp, %rdi
callq 0x907c
jmp 0x7026
movq %rax, %r14
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x703f
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x707e
callq 0x9dec
jmp 0x707e
movq %rax, %rdi
callq 0x6925
movq %rax, %r14
movl $0x110030, %esi         # imm = 0x110030
movq %r12, %rdi
jmp 0x7070
movq %rax, %r14
movl $0x220, %esi            # imm = 0x220
movq %r15, %rdi
callq 0x53a0
jmp 0x707e
jmp 0x707b
jmp 0x707b
movq %rax, %r14
movl $0x87c8, %r15d          # imm = 0x87C8
leaq (%rbx,%r15), %rdi
callq 0x9750
addq $-0x80, %r15
cmpq $0x7c8, %r15            # imm = 0x7C8
jne 0x7084
movq %r14, %rdi
callq 0x56e0