// File: /workspace/github_cpp_makefile_star2_O3/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, %r14d
movq %rdx, %r12
movq %rsi, %r13
movq %rdi, %rbx
movq %rsi, (%rdi)
leaq 0x30(%rdi), %rbp
movq %rbp, %rdi
movq %rcx, 0x10(%rsp)
movq %rcx, %rsi
callq 0x1c59a
leaq 0x48(%rbx), %rax
movq %rax, (%rsp)
xorl %eax, %eax
movq %rax, 0x58(%rbx)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x48(%rbx)
leaq 0x78(%rbx), %rcx
movq %rcx, 0x28(%rsp)
movdqu %xmm0, 0x78(%rbx)
movq %rax, 0x88(%rbx)
movl %r14d, 0x90(%rbx)
leaq 0x8(%rbx), %rdi
movq %r12, %rsi
callq 0x5360
movq 0x38(%r13), %rdi
movq 0x40(%r13), %r14
leaq 0x18(%r13), %rsi
leaq 0x23a07(%rip), %rcx     # 0x3c6ee
movq %r12, %rdx
movq %rbp, 0x30(%rsp)
callq 0x18003
movq %r14, %rdi
movq %rax, %rsi
callq 0x17c64
movl $0x1, 0x60(%rbx)
movl $0xffffffff, 0x68(%rbx) # imm = 0xFFFFFFFF
movw $0x8, 0x6c(%rbx)
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x18d21
movq %rax, 0x38(%rbx)
movq 0x48(%rbx), %rax
cmpq %rax, 0x50(%rbx)
je 0x18d2f
movq %rax, 0x50(%rbx)
movq 0x78(%rbx), %rax
cmpq %rax, 0x80(%rbx)
je 0x18d43
movq %rax, 0x80(%rbx)
movq 0x10(%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r15
movq %r15, %rcx
subq %r14, %rcx
shrq $0x2, %rcx
movq %r15, %rax
movl %ecx, 0x28(%rbx)
subq %r14, %rax
movq %r13, 0x20(%rsp)
je 0x18df9
addq $0x58, %r13
leaq 0xc(%rsp), %r12
movl (%r14), %eax
movl %eax, 0xc(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x18d93
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x18d9e
movq %rbp, %rdi
movq %r12, %rdx
callq 0x1d0aa
movl 0xc(%rsp), %eax
imulq $0x38, %rax, %rax
leaq (%rax,%r13), %rdx
addq $0x24, %rdx
movq 0x80(%rbx), %rsi
cmpq 0x88(%rbx), %rsi
je 0x18dcf
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x80(%rbx)
jmp 0x18dd9
movq 0x28(%rsp), %rdi
callq 0x1d186
addq $0x4, %r14
cmpq %r15, %r14
jne 0x18d76
movq 0x10(%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %r15
movq %r15, %rax
subq %r14, %rax
movq 0x20(%rsp), %r13
cmpq %r14, %r15
je 0x18ecc
addq $0x58, %r13
movl $0x1, %r12d
xorl %r15d, %r15d
leaq 0x2799a(%rip), %rbp     # 0x407b0
movl $0x0, %eax
cmpl $0x1, %r12d
je 0x18e30
leal -0x2(%r12), %eax
movq (%rsp), %rcx
movq (%rcx), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x1c(%rsp)
movq 0x50(%rbx), %rsi
cmpq 0x58(%rbx), %rsi
je 0x18e4a
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x50(%rbx)
jmp 0x18e60
movq (%rsp), %rdi
leaq 0x1c(%rsp), %rdx
callq 0x1ca80
movq 0x10(%rsp), %rax
movq (%rax), %r14
movl (%r14,%r15,4), %eax
imulq $0x38, %rax, %rax
movl 0x24(%r13,%rax), %ecx
cmpq $0x4, %rcx
ja 0x18e9b
movslq (%rbp,%rcx,4), %rcx
addq %rbp, %rcx
jmpq *%rcx
movl $0x4, %eax
jmp 0x18ea0
movl $0x10, %eax
jmp 0x18ea0
addq %r13, %rax
movzbl 0x28(%rax), %eax
jmp 0x18ea0
movl $0x8, %eax
jmp 0x18ea0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq (%rsp), %rcx
movq (%rcx), %rcx
addl %eax, (%rcx,%r15,4)
movl %r12d, %r15d
movq 0x10(%rsp), %rax
movq 0x8(%rax), %rax
subq %r14, %rax
sarq $0x2, %rax
incl %r12d
cmpq %r15, %rax
ja 0x18e16
jmp 0x18ed0
sarq $0x2, %rax
testq %rax, %rax
movq 0x20(%rsp), %r15
je 0x18fb4
leaq 0x58(%r15), %rcx
movq (%rsp), %rdx
movq (%rdx), %rdx
xorl %esi, %esi
leaq 0x278d2(%rip), %rdi     # 0x407c4
movl (%r14,%rsi,4), %r8d
imulq $0x38, %r8, %r8
movl 0x24(%rcx,%r8), %r9d
cmpq $0x4, %r9
ja 0x18f31
movslq (%rdi,%r9,4), %r9
addq %rdi, %r9
jmpq *%r9
movl $0x4, %r8d
jmp 0x18f37
movl $0x10, %r8d
jmp 0x18f37
addq %rcx, %r8
movzbl 0x28(%r8), %r8d
jmp 0x18f37
movl $0x8, %r8d
jmp 0x18f37
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
subl %r8d, (%rdx,%rsi,4)
incq %rsi
movl %esi, %r8d
cmpq %r8, %rax
ja 0x18ef2
testq %rax, %rax
je 0x18fb4
movzwl 0x6c(%rbx), %esi
xorl %edx, %edx
leaq 0x27880(%rip), %rdi     # 0x407d8
movl (%r14,%rdx,4), %r8d
imulq $0x38, %r8, %r8
movl 0x24(%rcx,%r8), %r9d
cmpq $0x4, %r9
ja 0x18f94
movslq (%rdi,%r9,4), %r9
addq %rdi, %r9
jmpq *%r9
movw $0x4, %r8w
jmp 0x18f99
movw $0x10, %r8w
jmp 0x18f99
addq %rcx, %r8
movzbl 0x28(%r8), %r8d
jmp 0x18f99
movw $0x8, %r8w
jmp 0x18f99
movw $0xffff, %r8w           # imm = 0xFFFF
movswl %r8w, %r8d
addl %esi, %r8d
movl %r8d, %esi
incq %rdx
movl %edx, %r8d
cmpq %r8, %rax
ja 0x18f58
movw %si, 0x6c(%rbx)
jmp 0x18fb8
movzwl 0x6c(%rbx), %esi
movw $0x1fee, %ax            # imm = 0x1FEE
xorl %edx, %edx
divw %si
movzwl %ax, %eax
movl %eax, 0x70(%rbx)
movq %rbx, %rdi
callq 0x19088
movq 0x48(%r15), %rdi
movl 0x74(%rbx), %esi
leaq 0x18(%rsp), %rcx
xorl %edx, %edx
callq 0x67e4
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rax)
movw $0x0, 0x10(%rax)
movq 0x48(%r15), %rdi
movl 0x18(%rsp), %esi
callq 0x689e
movl $0x0, 0x64(%rbx)
movq (%rbx), %rax
movq 0x40(%rax), %rdi
movl 0x74(%rbx), %esi
callq 0x17c0a
movl $0xffffffff, 0x74(%rbx) # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1902f
jmp 0x1902f
jmp 0x1902f
movq %rax, %r12
movq 0x28(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1904e
movq 0x88(%rbx), %rsi
subq %rdi, %rsi
callq 0x53a0
movq (%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x19066
movq 0x58(%rbx), %rsi
subq %rdi, %rsi
callq 0x53a0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1907f
movq 0x40(%rbx), %rsi
subq %rdi, %rsi
callq 0x53a0
movq %r12, %rdi
callq 0x56e0
nop