// File: Konano[P]UselessDatabase/Table.cpp
// Function: Table::createIndex(std::vector<unsigned int, std::allocator<unsigned int>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
uint Table::createIndex(vector<uint> col_id, std::string name) {
    //Calculate max per node

    int max_per_node = 25;

    index[index_num] = Index(this, name.c_str(), col_id, max_per_node);
    index[index_num].open();
    for (uint record_id = 0; record_id < record_num; record_id++) {
        BufType buf = bpm->getPage(main_file, record_id / record_onepg);
        if (exist(buf, record_id % record_onepg)) {
            BufType _buf = buf + (record_onepg - 1) / 8 + 1 + record_size * (record_id % record_onepg);
            Anys a;
            for (uint j = 0; j < col_id.size(); j++) {
                Any val;
                fetchWithOffset(_buf, col_ty[index[index_num].key[j]].ty, col_ty[index[index_num].key[j]].size(), val, genOffset(col_id[j]));
                a.push_back(val);
            }
            index[index_num].insertRecord(&a, record_id);
        }
    }
    return index_num++;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x180, %rsp            # imm = 0x180
movq %rdx, -0x148(%rbp)
movq %rdi, %rax
movq -0x148(%rbp), %rdi
movq %rsi, -0x140(%rbp)
movq %rax, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x138(%rbp)
movl $0x19, -0x1c(%rbp)
callq 0x6210
movq -0x140(%rbp), %rsi
movq %rax, -0x130(%rbp)
leaq -0xd0(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x3d100
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
movq -0x128(%rbp), %rcx
movl -0x1c(%rbp), %r8d
leaq -0xb8(%rbp), %rdi
callq 0x365f0
jmp 0x4924e
movq -0x138(%rbp), %rax
movq %rax, %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movl 0x798(%rax), %eax
imulq $0x98, %rax, %rax
addq %rax, %rdi
leaq -0xb8(%rbp), %rsi
callq 0x52b40
leaq -0xb8(%rbp), %rdi
callq 0xea70
leaq -0xd0(%rbp), %rdi
callq 0xee40
movq -0x138(%rbp), %rax
movq %rax, %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movl 0x798(%rax), %eax
imulq $0x98, %rax, %rax
addq %rax, %rdi
callq 0x36ad0
movl $0x0, -0xe0(%rbp)
movq -0x138(%rbp), %rcx
movl -0xe0(%rbp), %eax
cmpl 0x9fa0(%rcx), %eax
jae 0x49622
movq -0x138(%rbp), %rcx
movq 0x48(%rcx), %rdi
movl 0x9fa4(%rcx), %esi
movl -0xe0(%rbp), %eax
xorl %edx, %edx
divl 0x9fac(%rcx)
movl %eax, %edx
callq 0x70b0
movq -0x138(%rbp), %rcx
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x158(%rbp)
movl -0xe0(%rbp), %eax
xorl %edx, %edx
divl 0x9fac(%rcx)
movq -0x158(%rbp), %rax
shrl $0x3, %edx
movl %edx, %edx
movzbl (%rax,%rdx), %eax
movl %eax, -0x14c(%rbp)
movl -0xe0(%rbp), %eax
xorl %edx, %edx
divl 0x9fac(%rcx)
movl -0x14c(%rbp), %eax
movl %edx, %ecx
andl $0x7, %ecx
movl $0x1, %edx
shll %cl, %edx
movl %edx, %ecx
andl %ecx, %eax
cmpl $0x0, %eax
je 0x4960c
movq -0x138(%rbp), %rsi
movq -0xe8(%rbp), %rax
movl 0x9fac(%rsi), %ecx
subl $0x1, %ecx
shrl $0x3, %ecx
movl %ecx, %ecx
addq %rcx, %rax
addq $0x1, %rax
movq %rax, -0x160(%rbp)
movl 0x9fa8(%rsi), %ecx
movl -0xe0(%rbp), %eax
xorl %edx, %edx
divl 0x9fac(%rsi)
movq -0x160(%rbp), %rax
imull %edx, %ecx
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0xf0(%rbp)
leaq -0x108(%rbp), %rdi
callq 0xc310
movl $0x0, -0x10c(%rbp)
movq -0x140(%rbp), %rdi
movl -0x10c(%rbp), %eax
movq %rax, -0x168(%rbp)
callq 0x3d1f0
movq %rax, %rcx
movq -0x168(%rbp), %rax
cmpq %rcx, %rax
jae 0x495c0
leaq -0x118(%rbp), %rdi
callq 0xd240
jmp 0x49413
movq -0x138(%rbp), %rax
movl 0x798(%rax), %ecx
imulq $0x98, %rcx, %rcx
leaq 0x7d0(%rax,%rcx), %rdi
movl -0x10c(%rbp), %eax
movl %eax, %esi
callq 0x3cf40
movq %rax, %rcx
movq -0x138(%rbp), %rax
movl (%rcx), %ecx
imulq $0x38, %rcx, %rcx
movl 0x7c(%rax,%rcx), %ecx
movl %ecx, -0x170(%rbp)
movl 0x798(%rax), %ecx
imulq $0x98, %rcx, %rcx
leaq 0x7d0(%rax,%rcx), %rdi
movl -0x10c(%rbp), %eax
movl %eax, %esi
callq 0x3cf40
movq %rax, %rcx
movq -0x138(%rbp), %rax
movl (%rcx), %ecx
imulq $0x38, %rcx, %rcx
leaq 0x58(%rax,%rcx), %rdi
callq 0x3d3d0
movl %eax, -0x16c(%rbp)
jmp 0x4949a
movq -0x140(%rbp), %rdi
movl -0x10c(%rbp), %eax
movl %eax, %esi
callq 0x3cf40
movq -0x138(%rbp), %rdi
movl (%rax), %esi
callq 0x4b830
movl %eax, -0x174(%rbp)
jmp 0x494c4
movl -0x174(%rbp), %r9d
movl -0x16c(%rbp), %ecx
movl -0x170(%rbp), %edx
movq -0x138(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x118(%rbp), %r8
callq 0x49800
jmp 0x494f3
leaq -0x120(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0xca00
jmp 0x49508
leaq -0x108(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0xc330
jmp 0x4951d
leaq -0x120(%rbp), %rdi
callq 0xc3c0
leaq -0x118(%rbp), %rdi
callq 0xc3c0
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x493d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0xee40
jmp 0x49643
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x495fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
jmp 0x495b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xd8(%rbp)
movl %eax, -0xdc(%rbp)
leaq -0x120(%rbp), %rdi
callq 0xc3c0
leaq -0x118(%rbp), %rdi
callq 0xc3c0
jmp 0x495fe
movq -0x138(%rbp), %rax
movl 0x798(%rax), %ecx
imulq $0x98, %rcx, %rcx
leaq 0x7a0(%rax,%rcx), %rdi
movl -0xe0(%rbp), %edx
leaq -0x108(%rbp), %rsi
callq 0x390e0
jmp 0x495f0
leaq -0x108(%rbp), %rdi
callq 0xc430
jmp 0x4960c
leaq -0x108(%rbp), %rdi
callq 0xc430
jmp 0x49643
jmp 0x4960e
movl -0xe0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xe0(%rbp)
jmp 0x492c3
movq -0x138(%rbp), %rcx
movl 0x798(%rcx), %eax
movl %eax, %edx
addl $0x1, %edx
movl %edx, 0x798(%rcx)
addq $0x180, %rsp            # imm = 0x180
popq %rbp
retq
movq -0xd8(%rbp), %rdi
callq 0x6890
nop