// File: /workspace/github_cpp_makefile_star2_O1/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 0x828(%rdx), %rax
movq %rax, 0x40(%rdi)
movq %rdx, 0x28(%rsp)
movq 0x830(%rdx), %rax
movq %rax, 0x48(%rdi)
addq $0x18, %rdi
movq %rcx, 0x30(%rsp)
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 0x21551
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 0x214d7
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, %r14
jmp 0x214da
xorl %r14d, %r14d
movq %r14, 0xa0(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x21822
movl %eax, %r15d
testq %r14, %r14
je 0x214fe
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
testl %r15d, %r15d
jne 0x2177f
movl 0xc(%rsp), %eax
imulq $0x38, %rax, %rcx
cmpl $0x0, 0x2c(%r12,%rcx)
jne 0x2153f
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x21530
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x2153f
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x1d780
movl 0xc(%rsp), %eax
incl %eax
movl %eax, 0xc(%rsp)
cmpl %ebp, %eax
jb 0x21496
movq 0x18(%rsp), %rax
cmpq 0x10(%rsp), %rax
movq 0x30(%rsp), %r13
je 0x216ea
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 0x326b2(%rip), %rdx     # 0x53c58
movq %rdx, (%rax)
movups %xmm0, 0x50(%rax)
movq %rcx, 0x60(%rax)
movq %rax, 0x758(%rbx)
movq 0x18(%rax), %rdx
leaq 0x2063f(%rip), %rcx     # 0x41c02
movl $0x18, %r8d
xorl %esi, %esi
callq 0x55e0
movq 0x758(%rbx), %rax
movq 0x30(%rax), %rcx
cmpq %rcx, 0x38(%rax)
je 0x215e5
movq %rcx, 0x38(%rax)
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %r12
cmpq %r12, %r15
je 0x21632
leaq 0xc(%rsp), %r14
movl (%r15), %eax
movl %eax, 0xc(%rsp)
movq 0x758(%rbx), %rdi
movq 0x38(%rdi), %rsi
cmpq 0x40(%rdi), %rsi
je 0x2161d
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rdi)
jmp 0x21629
addq $0x30, %rdi
movq %r14, %rdx
callq 0x1d780
addq $0x4, %r15
cmpq %r12, %r15
jne 0x215f9
movq 0x758(%rbx), %rax
movq %rbx, 0x48(%rax)
movq %rbx, %rdi
callq 0x218a4
movl 0x778(%rbx), %esi
cmpl $-0x1, %esi
je 0x21658
movq %rbx, %rdi
callq 0x21942
movq 0x758(%rbx), %rsi
addq $0x30, %rsi
leaq 0x38(%rsp), %rdi
callq 0x1cc60
leaq 0x60(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x2059e(%rip), %rsi     # 0x41c1b
leaq 0x20599(%rip), %rdx     # 0x41c1d
leaq 0x50(%rsp), %rdi
callq 0xaccc
leaq 0x38(%rsp), %rsi
leaq 0x50(%rsp), %rdx
movq %rbx, %rdi
callq 0x21a1e
movl %eax, 0x778(%rbx)
movq 0x50(%rsp), %rdi
cmpq %r14, %rdi
je 0x216bd
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x216d4
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 0x21720
movq 0x40(%rbx), %r14
leaq 0x1bfef(%rip), %rdx     # 0x3d6ee
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x186c1
movq %r14, %rdi
movq %rax, %rsi
callq 0x183c4
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
testb %al, %al
je 0x21784
movq 0x40(%rbx), %r14
leaq 0x1bfc3(%rip), %rdx     # 0x3d6ee
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x186c1
leaq 0x9fa4(%rbx), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x183ec
movq %rbx, %rdi
callq 0x213bc
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 0x21762
movl %ecx, 0x9fac(%rbx)
xorl %ebp, %ebp
jmp 0x21784
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2179b
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 0x217ce
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x53a0
jmp 0x217ce
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x21803
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
jmp 0x21803
jmp 0x217ed
jmp 0x217ed
jmp 0x217ed
movq %rax, %rbx
jmp 0x21803
movq %rax, %rbx
testq %r14, %r14
je 0x21803
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2181a
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
movq %rbx, %rdi
callq 0x56e0