// File: /workspace/github_cpp_makefile_star2_O2/Konano[P]UselessDatabase/Index.cpp
// Function: Index::Index(Table*, char const*, std::vector<unsigned int, std::allocator<unsigned int>>, int)
Index::Index(Table* table, const char* name, vector<uint> key, int btree_max_per_node) : table(table), key(key), btree_max_per_node(btree_max_per_node) {
    strcpy(this->name, name);
    table->fm->createFile(dirPath(table->db->name, table->name, name, "usid"));
    page_num = 1;
    next_del_page = -1;
    record_size = 8;
    this->key.clear();
    this->offset.clear();
    this->ty.clear();
    this->key_num = key.size();
    for (auto i : key) {
        this->key.push_back(i);
        this->ty.push_back(table->col_ty[i].ty);
    }
    for (uint i = 0; i < key.size(); i++) {
        this->offset.push_back(i == 0 ? 0 : this->offset[i - 1]);
        this->offset[i] += table->col_ty[key[i]].size();
    }
    for (uint i = 0; i < key.size(); i++) this->offset[i] -= table->col_ty[key[i]].size();
    for (uint i = 0; i < key.size(); i++)
        record_size += table->col_ty[key[i]].size();
    max_recond_num = (PAGE_SIZE - 18) / record_size;

    open();

    int index;
    BufType buf = table->bpm->getPage(fileID, 0, index);
    *(uint32_t *)(buf+0) = -1;
    *(uint32_t *)(buf+4) = -1;
    *(uint32_t *)(buf+8) = -1;
    *(uint32_t *)(buf+12) = -1;
    *(uint16_t *)(buf+16) = 0;
    table->bpm->markDirty(index);
    
    root_page = 0;
    close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r8d, %r12d
movq %rcx, %rbp
movq %rdx, %r13
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, (%rdi)
addq $0x30, %rdi
movq %rdi, 0x28(%rsp)
movq %rcx, %rsi
callq 0x17f70
leaq 0x48(%rbx), %r14
pxor %xmm0, %xmm0
andq $0x0, 0x58(%rbx)
movdqu %xmm0, 0x48(%rbx)
andq $0x0, 0x88(%rbx)
leaq 0x78(%rbx), %rax
movq %rax, 0x20(%rsp)
movdqu %xmm0, 0x78(%rbx)
movl %r12d, 0x90(%rbx)
leaq 0x8(%rbx), %rdi
movq %r13, %rsi
callq 0x53b0
movq 0x38(%r15), %rdi
movq 0x40(%r15), %r12
leaq 0x18(%r15), %rsi
leaq 0x1e321(%rip), %rcx     # 0x336ee
movq %r13, %rdx
callq 0x149e5
movq %r12, %rdi
movq %rax, %rsi
callq 0x146c2
movl $0x1, 0x60(%rbx)
orl $-0x1, 0x68(%rbx)
movw $0x8, 0x6c(%rbx)
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x153ff
movq %rax, 0x38(%rbx)
movq 0x48(%rbx), %rax
cmpq %rax, 0x50(%rbx)
je 0x1540d
movq %rax, 0x50(%rbx)
movq %r15, 0x18(%rsp)
movq 0x78(%rbx), %rax
cmpq %rax, 0x80(%rbx)
je 0x15426
movq %rax, 0x80(%rbx)
movq (%rbp), %r15
movq 0x8(%rbp), %r12
movq %r12, %rax
subq %r15, %rax
shrq $0x2, %rax
movq %rbx, 0x30(%rsp)
movl %eax, 0x28(%rbx)
movq 0x18(%rsp), %rax
leaq 0x58(%rax), %rbx
leaq 0xc(%rsp), %r13
cmpq %r12, %r15
je 0x15487
movl (%r15), %eax
movl %eax, 0xc(%rsp)
movq 0x28(%rsp), %rdi
movq %r13, %rsi
callq 0x17fbe
movl 0xc(%rsp), %eax
imulq $0x38, %rax, %rax
leaq (%rbx,%rax), %rsi
addq $0x24, %rsi
movq 0x20(%rsp), %rdi
callq 0x17fdc
addq $0x4, %r15
jmp 0x1544e
xorl %eax, %eax
leaq 0x14(%rsp), %r13
movl %eax, %r15d
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r15, %rdx
jbe 0x154eb
testq %r15, %r15
je 0x154b9
leal -0x1(%r15), %eax
movq (%r14), %rcx
movl (%rcx,%rax,4), %eax
jmp 0x154bb
xorl %eax, %eax
movl %eax, 0x14(%rsp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x185ce
movq (%rbp), %rax
movl (%rax,%r15,4), %eax
imulq $0x38, %rax, %rdi
addq %rbx, %rdi
callq 0x17ffa
movq (%r14), %rcx
addl %eax, (%rcx,%r15,4)
leal 0x1(%r15), %eax
jmp 0x1548e
xorl %edx, %edx
movq 0x30(%rsp), %r12
movl %edx, %r15d
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x2, %rdx
cmpq %r15, %rdx
jbe 0x15529
movl (%rax,%r15,4), %eax
imulq $0x38, %rax, %rdi
addq %rbx, %rdi
callq 0x17ffa
movq (%r14), %rcx
subl %eax, (%rcx,%r15,4)
leal 0x1(%r15), %edx
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
jmp 0x154f2
xorl %edx, %edx
movl %edx, %r15d
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %r15, %rcx
jbe 0x1555e
movl (%rax,%r15,4), %eax
imulq $0x38, %rax, %rdi
addq %rbx, %rdi
callq 0x17ffa
addw %ax, 0x6c(%r12)
leal 0x1(%r15), %edx
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
jmp 0x1552b
movw $0x1fee, %ax            # imm = 0x1FEE
xorl %edx, %edx
divw 0x6c(%r12)
movzwl %ax, %eax
movl %eax, 0x70(%r12)
movq %r12, %rdi
callq 0x155f8
movq 0x18(%rsp), %rbx
movq 0x48(%rbx), %rdi
movl 0x74(%r12), %esi
leaq 0x10(%rsp), %rcx
xorl %edx, %edx
callq 0x5d50
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rax)
andw $0x0, 0x10(%rax)
movq 0x48(%rbx), %rdi
movl 0x10(%rsp), %esi
callq 0x5e0a
andl $0x0, 0x64(%r12)
movq %r12, %rdi
callq 0x15638
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x155d1
jmp 0x155d1
jmp 0x155d1
movq %rax, %r12
movq 0x20(%rsp), %rdi
callq 0x1859a
movq %r14, %rdi
callq 0x18566
movq 0x28(%rsp), %rdi
callq 0x18566
movq %r12, %rdi
callq 0x56f0