// File: /workspace/github_cpp_makefile_star2_O1/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 %rcx, %rbp
movq %rdx, %r12
movq %rsi, %r15
movq %rdi, %rbx
movq %rsi, (%rdi)
addq $0x30, %rdi
movq %rdi, 0x30(%rsp)
movq %rcx, %rsi
callq 0x1cc60
leaq 0x48(%rbx), %rax
movq %rax, 0x8(%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(%r15), %rdi
movq 0x40(%r15), %r14
leaq 0x18(%r15), %rsi
leaq 0x2422a(%rip), %rcx     # 0x3d6ee
movq %r12, %rdx
callq 0x1876d
movq %r14, %rdi
movq %rax, %rsi
callq 0x183c4
movl $0x1, 0x60(%rbx)
movl $0xffffffff, 0x68(%rbx) # imm = 0xFFFFFFFF
movw $0x8, 0x6c(%rbx)
movq 0x30(%rbx), %rax
cmpq %rax, 0x38(%rbx)
je 0x194f9
movq %rax, 0x38(%rbx)
movq 0x48(%rbx), %rax
cmpq %rax, 0x50(%rbx)
je 0x19507
movq %rax, 0x50(%rbx)
movq %r15, 0x18(%rsp)
movq 0x78(%rbx), %rax
cmpq %rax, 0x80(%rbx)
je 0x19520
movq %rax, 0x80(%rbx)
movq (%rbp), %r14
movq 0x8(%rbp), %r15
movq %r15, %rax
subq %r14, %rax
shrq $0x2, %rax
movl %eax, 0x28(%rbx)
cmpq %r14, %r15
je 0x195b6
movq 0x18(%rsp), %rax
leaq 0x58(%rax), %r13
leaq 0x14(%rsp), %r12
movl (%r14), %eax
movl %eax, 0x14(%rsp)
movq 0x38(%rbx), %rsi
cmpq 0x40(%rbx), %rsi
je 0x19565
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rbx)
jmp 0x19572
movq 0x30(%rsp), %rdi
movq %r12, %rdx
callq 0x1d780
movl 0x14(%rsp), %eax
imulq $0x38, %rax, %rax
leaq (%rax,%r13), %rdx
addq $0x24, %rdx
movq 0x80(%rbx), %rsi
cmpq 0x88(%rbx), %rsi
je 0x195a3
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x80(%rbx)
jmp 0x195ad
movq 0x28(%rsp), %rdi
callq 0x1d85c
addq $0x4, %r14
cmpq %r15, %r14
jne 0x19548
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
je 0x19692
movq 0x18(%rsp), %rax
leaq 0x58(%rax), %r14
movl $0x1, %r13d
xorl %r12d, %r12d
leaq 0x281e0(%rip), %r15     # 0x417c0
movl $0x0, %eax
cmpl $0x1, %r13d
je 0x195fa
leal -0x2(%r13), %eax
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
movl (%rcx,%rax,4), %eax
movl %eax, 0x24(%rsp)
movq 0x50(%rbx), %rsi
cmpq 0x58(%rbx), %rsi
je 0x19614
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x50(%rbx)
jmp 0x19623
movq 0x8(%rsp), %rdi
leaq 0x24(%rsp), %rdx
callq 0x1d178
movq (%rbp), %rax
movl (%rax,%r12,4), %eax
imulq $0x38, %rax, %rax
movl 0x24(%r14,%rax), %ecx
cmpq $0x4, %rcx
ja 0x19661
movslq (%r15,%rcx,4), %rcx
addq %r15, %rcx
jmpq *%rcx
movl $0x4, %eax
jmp 0x19666
movl $0x10, %eax
jmp 0x19666
addq %r14, %rax
movzbl 0x28(%rax), %eax
jmp 0x19666
movl $0x8, %eax
jmp 0x19666
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
addl %eax, (%rcx,%r12,4)
movl %r13d, %r12d
movq (%rbp), %rax
movq 0x8(%rbp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
incl %r13d
cmpq %r12, %rcx
ja 0x195e0
jmp 0x19696
sarq $0x2, %rcx
testq %rcx, %rcx
movq 0x18(%rsp), %r14
je 0x19774
leaq 0x58(%r14), %rdx
movq 0x8(%rsp), %rsi
movq (%rsi), %rsi
xorl %edi, %edi
leaq 0x2811b(%rip), %r8      # 0x417d4
movl (%rax,%rdi,4), %r9d
imulq $0x38, %r9, %r9
movl 0x24(%rdx,%r9), %r10d
cmpq $0x4, %r10
ja 0x196f8
movslq (%r8,%r10,4), %r10
addq %r8, %r10
jmpq *%r10
movl $0x4, %r9d
jmp 0x196fe
movl $0x10, %r9d
jmp 0x196fe
addq %rdx, %r9
movzbl 0x28(%r9), %r9d
jmp 0x196fe
movl $0x8, %r9d
jmp 0x196fe
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
subl %r9d, (%rsi,%rdi,4)
incq %rdi
movl %edi, %r9d
cmpq %r9, %rcx
ja 0x196b9
movzwl 0x6c(%rbx), %esi
xorl %edi, %edi
leaq 0x280ce(%rip), %r8      # 0x417e8
movl (%rax,%rdi,4), %r9d
imulq $0x38, %r9, %r9
movl 0x24(%rdx,%r9), %r10d
cmpq $0x4, %r10
ja 0x19756
movslq (%r8,%r10,4), %r10
addq %r8, %r10
jmpq *%r10
movw $0x4, %r9w
jmp 0x1975b
movw $0x10, %r9w
jmp 0x1975b
addq %rdx, %r9
movzbl 0x28(%r9), %r9d
jmp 0x1975b
movw $0x8, %r9w
jmp 0x1975b
movw $0xffff, %r9w           # imm = 0xFFFF
movswl %r9w, %r9d
addl %esi, %r9d
movl %r9d, %esi
incq %rdi
movl %edi, %r9d
cmpq %r9, %rcx
ja 0x1971a
movw %si, 0x6c(%rbx)
movw $0x1fee, %ax            # imm = 0x1FEE
xorl %edx, %edx
divw 0x6c(%rbx)
movzwl %ax, %eax
movl %eax, 0x70(%rbx)
movq %rbx, %rdi
callq 0x19846
movq 0x48(%r14), %rdi
movl 0x74(%rbx), %esi
leaq 0x20(%rsp), %rcx
xorl %edx, %edx
callq 0x6834
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, (%rax)
movw $0x0, 0x10(%rax)
movq 0x48(%r14), %rdi
movl 0x20(%rsp), %esi
callq 0x68ee
movl $0x0, 0x64(%rbx)
movq (%rbx), %rax
movq 0x40(%rax), %rdi
movl 0x74(%rbx), %esi
callq 0x1836a
movl $0xffffffff, 0x74(%rbx) # imm = 0xFFFFFFFF
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x197ec
jmp 0x197ec
jmp 0x197ec
movq %rax, %r12
movq 0x28(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1980b
movq 0x88(%rbx), %rsi
subq %rdi, %rsi
callq 0x53a0
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x19824
movq 0x58(%rbx), %rsi
subq %rdi, %rsi
callq 0x53a0
movq 0x30(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x1983d
movq 0x40(%rbx), %rsi
subq %rdi, %rsi
callq 0x53a0
movq %r12, %rdi
callq 0x56e0
nop