// File: /workspace/github_cpp_makefile_star2_O3/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 %rcx, %r13
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, %rsi
callq 0x5360
xorl %eax, %eax
movl %eax, 0x54(%rbx)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl %eax, 0xc(%rsp)
testl %ebp, %ebp
je 0x2104e
movq %r13, 0x30(%rsp)
leaq 0x70(%rsp), %r13
movl %eax, %eax
imulq $0x38, %rax, %rax
movups (%r12,%rax), %xmm0
movups 0x10(%r12,%rax), %xmm1
movups 0x20(%r12,%rax), %xmm2
movaps %xmm2, 0x90(%rsp)
movaps %xmm1, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movq 0x30(%r12,%rax), %rdi
testq %rdi, %rdi
je 0x20e3d
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, %r14
jmp 0x20e40
xorl %r14d, %r14d
movq %r14, 0xa0(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x21186
movl %eax, %r15d
testq %r14, %r14
je 0x20e64
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
testl %r15d, %r15d
jne 0x210e3
movl 0xc(%rsp), %eax
imulq $0x38, %rax, %rcx
cmpl $0x0, 0x2c(%r12,%rcx)
jne 0x20ea5
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x20e96
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x20ea5
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x1d0aa
movl 0xc(%rsp), %eax
incl %eax
movl %eax, 0xc(%rsp)
cmpl %ebp, %eax
jb 0x20dfc
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
movq 0x30(%rsp), %r13
je 0x2104e
movl $0x68, %edi
callq 0x5390
movl $0x0, 0x8(%rax)
leaq 0x10(%rax), %rdi
movq %rax, %rcx
addq $0x20, %rcx
movq %rcx, 0x10(%rax)
xorl %ecx, %ecx
movq %rcx, 0x18(%rax)
movb $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movq %rcx, 0x40(%rax)
movq %rbx, 0x48(%rax)
leaq 0x31d4c(%rip), %rdx     # 0x52c58
movq %rdx, (%rax)
movups %xmm0, 0x50(%rax)
movq %rcx, 0x60(%rax)
movq %rax, 0x758(%rbx)
leaq 0x1fd0d(%rip), %rcx     # 0x40c32
movl $0x18, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x55e0
movq 0x758(%rbx), %rax
movq 0x30(%rax), %rcx
cmpq %rcx, 0x38(%rax)
je 0x20f49
movq %rcx, 0x38(%rax)
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x20f9d
leaq 0xc(%rsp), %r14
movl (%r15), %eax
movl %eax, 0xc(%rsp)
movq 0x758(%rbx), %rdi
movq 0x38(%rdi), %rsi
cmpq 0x40(%rdi), %rsi
je 0x20f81
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rdi)
jmp 0x20f8d
addq $0x30, %rdi
movq %r14, %rdx
callq 0x1d0aa
addq $0x4, %r15
cmpq %r12, %r15
jne 0x20f5d
movq 0x758(%rbx), %rax
movq %rbx, 0x48(%rax)
movq %rbx, %rdi
callq 0x21208
movl 0x778(%rbx), %esi
cmpl $-0x1, %esi
je 0x20fbc
movq %rbx, %rdi
callq 0x2139c
movq 0x758(%rbx), %rsi
addq $0x30, %rsi
leaq 0x38(%rsp), %rdi
callq 0x1c59a
leaq 0x60(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1fc6a(%rip), %rsi     # 0x40c4b
leaq 0x1fc65(%rip), %rdx     # 0x40c4d
leaq 0x50(%rsp), %rdi
callq 0xa960
leaq 0x38(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x21478
movl %eax, 0x778(%rbx)
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
je 0x21021
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x21038
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
movq 0x758(%rbx), %rax
movq 0x38(%rax), %rcx
subq 0x30(%rax), %rcx
shrq $0x2, %rcx
movl %ecx, 0x8(%rax)
cmpb $0x0, 0xe0(%rsp)
je 0x21084
movq 0x40(%rbx), %r14
leaq 0x1b68b(%rip), %rdx     # 0x3c6ee
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x17f62
movq %r14, %rdi
movq %rax, %rsi
callq 0x17c64
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
testb %al, %al
je 0x210e8
movq 0x40(%rbx), %r14
leaq 0x1b65f(%rip), %rdx     # 0x3c6ee
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x17f62
leaq 0x9fa4(%rbx), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x17c8c
movq %rbx, %rdi
callq 0x20d2a
movl %eax, 0x9fa8(%rbx)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl $0x1, %edx
incl %ecx
addl %eax, %edx
movl %ecx, %esi
shrl $0x3, %esi
addl %edx, %esi
cmpl $0x2001, %esi           # imm = 0x2001
jb 0x210c6
movl %ecx, 0x9fac(%rbx)
xorl %ebp, %ebp
jmp 0x210e8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x210ff
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
movl %ebp, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
je 0x21132
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x53a0
jmp 0x21132
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x21167
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
jmp 0x21167
jmp 0x21151
jmp 0x21151
jmp 0x21151
movq %rax, %rbx
jmp 0x21167
movq %rax, %rbx
testq %r14, %r14
je 0x21167
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2117e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
movq %rbx, %rdi
callq 0x56e0