// File: /workspace/github_cpp_makefile_star2_O1/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 0x6e4a
movl $0x0, 0x9048(%rbx)
movl $0x220, %edi            # imm = 0x220
callq 0x5390
movq %rax, %r15
movq %rax, %rdi
callq 0x1829c
movq %r15, 0x828(%rbx)
movl $0x110030, %edi         # imm = 0x110030
callq 0x5390
movq %rax, %r12
movq %rax, %rdi
movq %r15, %rsi
callq 0x664a
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 0x6f73
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5360
movq %rbx, %rdi
callq 0x18625
movq %rax, %r15
leaq 0x3adc4(%rip), %rdi     # 0x41cd0
xorl %esi, %esi
callq 0x5670
cmpl $-0x1, %eax
jne 0x6f29
leaq 0x3adb1(%rip), %rdi     # 0x41cd0
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5200
movq %r15, %rdi
xorl %esi, %esi
callq 0x5670
cmpl $-0x1, %eax
jne 0x6f45
movq %r15, %rdi
movl $0x1ff, %esi            # imm = 0x1FF
callq 0x5200
movq %rbx, %rdi
callq 0x6d66
movq 0x828(%rbx), %r15
leaq 0x3678a(%rip), %rsi     # 0x3d6e5
movq %r14, %rdi
callq 0x1865c
movq %r15, %rdi
movq %rax, %rsi
callq 0x183c4
jmp 0x7001
leaq 0x3675e(%rip), %rsi     # 0x3d6d8
movq %r14, %rdi
callq 0x1865c
movq %rax, %rdi
callq 0x18574
leaq 0x10(%rsp), %rdi
movq %rax, %rsi
callq 0x9814
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rdx
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq %rsp, %rdi
leaq 0x10(%rsp), %rsi
movl $0x1, %ecx
callq 0x96c8
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x6c02
movq %rsp, %rdi
callq 0xd52a
leaq 0x8(%rsp), %rdi
movzbl -0x8(%rdi), %esi
callq 0xd5cc
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x6ff2
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x7001
callq 0xa012
movq 0x828(%rbx), %r15
leaq 0x366d6(%rip), %rsi     # 0x3d6e5
movq %r14, %rdi
callq 0x1865c
leaq 0x838(%rbx), %rdx
movq %r15, %rdi
movq %rax, %rsi
callq 0x183ec
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
jmp 0x7072
movq %rax, %r14
movq %rsp, %rdi
callq 0x915e
jmp 0x7048
movq %rax, %r14
movq 0x30(%rsp), %rax
testq %rax, %rax
je 0x7061
leaq 0x20(%rsp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x70a0
callq 0xa012
jmp 0x70a0
movq %rax, %rdi
callq 0x697a
movq %rax, %r14
movl $0x110030, %esi         # imm = 0x110030
movq %r12, %rdi
jmp 0x7092
movq %rax, %r14
movl $0x220, %esi            # imm = 0x220
movq %r15, %rdi
callq 0x53a0
jmp 0x70a0
jmp 0x709d
jmp 0x709d
movq %rax, %r14
movl $0x87c8, %r15d          # imm = 0x87C8
leaq (%rbx,%r15), %rdi
callq 0x987a
addq $-0x80, %r15
cmpq $0x7c8, %r15            # imm = 0x7C8
jne 0x70a6
movq %r14, %rdi
callq 0x56e0