// File: /workspace/github_cpp_makefile_star2_O2/Konano[P]UselessDatabase/Table.cpp
// Function: Table::createTable(unsigned int, Database*, char const*, unsigned int, Type*, bool)
int Table::createTable(uint table_id, Database* db, const char* name, uint col_num, Type* col_ty, bool create) {
    this->table_id = table_id;
    this->db = db;
    this->fm = db->fm;
    this->bpm = db->bpm;
    strcpy(this->name, name);
    this->col_num = 0;
    vector<uint> tempvec;
    for (uint i = 0; i < col_num; i++) {
        if (this->createColumn(col_ty[i])) return -1;
        if (col_ty[i].key == enumKeyType::Primary)tempvec.push_back(i);
    }

    if(tempvec.size() != 0){
        p_key = new PrimaryKey(this);
        p_key->name = "default primary key name";
        p_key->v.clear();
        for (auto i: tempvec)p_key->v.push_back(i);
        p_key->table = this;
        updateColumns();
        int old = p_key_index;
        if(old != -1)removeIndex(old);
        p_key_index = createIndex(p_key->v, "pk");
        p_key->v_size = p_key->v.size();
    }

    if (create) {
        if (fm->createFile(dirPath(db->name, name, "usid")) == false)
            return -2;
    }
    fm->openFile(dirPath(db->name, name, "usid"), main_file);
    record_size = calDataSize();
    record_onepg = 0;
    while ((record_onepg + 1) * record_size + (record_onepg - 1 + 1) / 8 + 1 <= PAGE_SIZE) record_onepg++;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %r9, %r12
movl %r8d, %ebp
movq %rdi, %rbx
movl %esi, 0x50(%rdi)
movq %rdx, 0x38(%rdi)
movq %rdx, 0x28(%rsp)
movups 0x828(%rdx), %xmm0
movups %xmm0, 0x40(%rdi)
addq $0x18, %rdi
movq %rcx, 0x30(%rsp)
movq %rcx, %rsi
callq 0x53b0
andl $0x0, 0x54(%rbx)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r13
andq $0x0, 0x10(%r13)
movaps %xmm0, (%r13)
xorl %eax, %eax
leaq 0x50(%rsp), %r14
movl %eax, 0xc(%rsp)
cmpl %ebp, %eax
jae 0x1b885
movl %eax, %eax
imulq $0x38, %rax, %rax
movups (%r12,%rax), %xmm0
movups 0x10(%r12,%rax), %xmm1
movups 0x20(%r12,%rax), %xmm2
movaps %xmm2, 0x70(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x30(%r12,%rax), %rdi
testq %rdi, %rdi
je 0x1b829
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x1b82b
xorl %eax, %eax
movq %rax, 0x80(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1bae2
movl %eax, %r15d
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1b854
movq (%rdi), %rax
callq *0x8(%rax)
testl %r15d, %r15d
jne 0x1b942
movl 0xc(%rsp), %eax
imulq $0x38, %rax, %rcx
cmpl $0x0, 0x2c(%r12,%rcx)
jne 0x1b87e
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
callq 0x17fbe
movl 0xc(%rsp), %eax
incl %eax
jmp 0x1b7e5
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
movq 0x30(%rsp), %r13
movq 0x28(%rsp), %rbp
je 0x1b9e5
pushq $0x68
popq %rdi
callq 0x53e0
andl $0x0, 0x8(%rax)
movq %rax, %rcx
addq $0x20, %rcx
movq %rcx, 0x10(%rax)
andq $0x0, 0x18(%rax)
leaq 0x10(%rax), %rdi
movb $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
andq $0x0, 0x40(%rax)
movq %rbx, 0x48(%rax)
leaq 0x34406(%rip), %rcx     # 0x4fce0
movq %rcx, (%rax)
movups %xmm0, 0x50(%rax)
andq $0x0, 0x60(%rax)
movq %rax, 0x758(%rbx)
leaq 0x1c726(%rip), %rsi     # 0x3801a
callq 0x5790
movq 0x758(%rbx), %rax
movq 0x30(%rax), %rcx
cmpq %rcx, 0x38(%rax)
je 0x1b90e
movq %rcx, 0x38(%rax)
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
leaq 0xc(%rsp), %r14
cmpq %r12, %r15
je 0x1b949
movl (%r15), %eax
movl %eax, 0xc(%rsp)
movq 0x758(%rbx), %rdi
addq $0x30, %rdi
movq %r14, %rsi
callq 0x17fbe
addq $0x4, %r15
jmp 0x1b91d
pushq $-0x1
jmp 0x1ba6f
movq 0x758(%rbx), %rax
movq %rbx, 0x48(%rax)
movq %rbx, %rdi
callq 0x1bb26
movl 0x778(%rbx), %esi
cmpl $-0x1, %esi
je 0x1b96f
movq %rbx, %rdi
callq 0x1bbb4
movq 0x758(%rbx), %rsi
addq $0x30, %rsi
leaq 0x38(%rsp), %rdi
callq 0x17f70
leaq 0x1c6a8(%rip), %rsi     # 0x38033
leaq 0x88(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x84b8
leaq 0x38(%rsp), %rsi
leaq 0x88(%rsp), %rdx
movq %rbx, %rdi
callq 0x1bc0e
movl %eax, 0x778(%rbx)
leaq 0x88(%rsp), %rdi
callq 0x5200
leaq 0x38(%rsp), %rdi
callq 0x18566
movq 0x758(%rbx), %rax
movq 0x38(%rax), %rcx
subq 0x30(%rax), %rcx
shrq $0x2, %rcx
movl %ecx, 0x8(%rax)
cmpb $0x0, 0xe0(%rsp)
je 0x1ba14
movq 0x40(%rbx), %r14
leaq 0x17cf4(%rip), %rdx     # 0x336ee
movq %rbp, %rdi
movq %r13, %rsi
callq 0x14944
movq %r14, %rdi
movq %rax, %rsi
callq 0x146c2
testb %al, %al
je 0x1ba6d
movq 0x40(%rbx), %r14
leaq 0x17ccf(%rip), %rdx     # 0x336ee
movq %rbp, %rdi
movq %r13, %rsi
callq 0x14944
leaq 0x9fa4(%rbx), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x146ea
movq %rbx, %rdi
callq 0x1b74a
movl %eax, 0x9fa8(%rbx)
pushq $-0x1
popq %rcx
pushq $0x1
popq %rdx
incl %ecx
addl %eax, %edx
movl %ecx, %esi
shrl $0x3, %esi
addl %edx, %esi
cmpl $0x2001, %esi           # imm = 0x2001
jb 0x1ba50
movl %ecx, 0x9fac(%rbx)
xorl %ebx, %ebx
jmp 0x1ba70
pushq $-0x2
popq %rbx
leaq 0x10(%rsp), %rdi
callq 0x18566
movl %ebx, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x5200
jmp 0x1baa3
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x18566
jmp 0x1bad0
jmp 0x1bab5
jmp 0x1bab5
jmp 0x1bab5
movq %rax, %rbx
jmp 0x1bad0
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1bad0
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x10(%rsp), %rdi
callq 0x18566
movq %rbx, %rdi
callq 0x56f0