// File: /workspace/github_cpp_makefile_star2_O2/Konano[P]UselessDatabase/Index.cpp
// Function: Index::convert_buf_to_BtreeNode(int)
BtreeNode* Index::convert_buf_to_BtreeNode(int index) {
    BtreeNode* ans = new BtreeNode();
    ans->child.clear();
    ans->child_ptr.clear();
    ans->record.clear();
    ans->left_page = nullptr;
    ans->right_page = nullptr;
    
    ans->index = index;

    BufType buf = table->bpm->getPage(fileID, index);

    ans->left_page_index = *(uint32_t *)(buf + 4);
    ans->right_page_index = *(uint32_t *)(buf + 8);
    ans->fa_index = *(uint32_t *)(buf + 12);
    ans->record_cnt = *(uint16_t *)(buf + 16);

    if (ans->record_cnt != 0) {
        ans->child.push_back(*(uint32_t *)(buf + 18)); 
        if (ans->child[0] != -1) ans->is_leaf = false;
    }
    else ans->child.push_back(-1);

    for (int i = 0; i < ans->record_cnt; i++) {
        BtreeRecord temp;
        temp.record_id = *(uint32_t *)(buf + 22 + i * record_size);
        for (uint j = 0; j < this->key_num; j++) {
            if (this->ty[j] == enumType::INT) {
                bool flag = true;
                for (uint k = 0; k < 4; k++) {
                    if (*(uint8_t*)(buf + 22 + i * record_size + 4 + this->offset[j] + k) != 255) {
                        flag = false;
                        break;
                    }
                }
                if(flag) temp.key.push_back(Any());
                else temp.key.push_back(Any(*(int*)(buf + 22 + i * record_size + 4 + this->offset[j])));
            }
            if (this->ty[j] == enumType::CHAR) {
                bool flag = true;
                for (uint k = 0; k < this->offset[j] - (j == 0 ? 0 : this->offset[j - 1]); k++) {
                    if (*(uint8_t*)(buf + 22 + i * record_size + 4 + this->offset[j] + k) != 255) {
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    char* str = new char[record_size - 8 + 1];
                    memcpy(str, buf + 22 + i * record_size + 4 + this->offset[j], this->offset[j] - (j == 0 ? 0 : this->offset[j - 1]));
                    str[record_size - 8] = '\0';
                    temp.key.push_back(Any(str));
                }
                else{
                    temp.key.push_back(Any());
                }
            }
        }
        ans->child.push_back(*(uint32_t *)(buf + 22 + (i + 1) * record_size - 4));
        ans->record.push_back(temp);
    }
    return ans;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movl %esi, %ebx
movq %rdi, %r14
pushq $0x70
popq %rdi
callq 0x53e0
movq %rax, %r15
movq %rax, %r12
movq %rax, %rdi
callq 0x1803a
movq 0x20(%r15), %rax
cmpq %rax, 0x28(%r15)
je 0x158a6
movq %rax, 0x28(%r15)
movq 0x38(%r15), %rax
cmpq %rax, 0x40(%r15)
je 0x158b4
movq %rax, 0x40(%r15)
movq %r12, %rdi
addq $0x20, %r12
addq $0x50, %rdi
movq %rdi, 0x50(%rsp)
callq 0x180ca
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r15)
movl %ebx, 0x18(%r15)
movq (%r14), %rax
movq 0x48(%rax), %rdi
movl 0x74(%r14), %esi
movl %ebx, %edx
callq 0x5c8e
movq %rax, %rbx
movl 0x4(%rax), %eax
movl %eax, (%r15)
movl 0x8(%rbx), %eax
movl %eax, 0x4(%r15)
movl 0xc(%rbx), %eax
movl %eax, 0x6c(%r15)
movzwl 0x10(%rbx), %eax
movl %eax, 0x1c(%r15)
testl %eax, %eax
movq %r12, 0x60(%rsp)
je 0x15931
movl 0x12(%rbx), %eax
leaq 0x68(%rsp), %rsi
movl %eax, (%rsi)
movq %r12, %rdi
callq 0x18774
movq (%r12), %rax
cmpl $-0x1, (%rax)
je 0x15941
movb $0x0, 0x68(%r15)
jmp 0x15941
leaq 0x68(%rsp), %rsi
orl $-0x1, (%rsi)
movq %r12, %rdi
callq 0x18774
movq %r15, 0x38(%rsp)
leaq 0x70(%rsp), %r13
movq %rbx, %rax
addq $0x1a, %rax
movq %rax, 0x48(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x10(%rsp), %r15
movq %r14, 0x40(%rsp)
movq %rbx, 0x58(%rsp)
movq 0x38(%rsp), %rax
movq 0x8(%rsp), %rcx
cmpl 0x1c(%rax), %ecx
jge 0x15b72
andq $0x0, 0x10(%r13)
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movzwl 0x6c(%r14), %eax
movl %ecx, %ecx
imulq %rax, %rcx
movl 0x16(%rbx,%rcx), %eax
movl %eax, 0x68(%rsp)
xorl %ebx, %ebx
movl 0x28(%r14), %eax
cmpq %rax, %rbx
jae 0x15b25
movq 0x78(%r14), %rax
cmpl $0x0, (%rax,%rbx,4)
jne 0x15a23
movzwl 0x6c(%r14), %eax
imull 0x8(%rsp), %eax
addq 0x48(%rsp), %rax
movq 0x48(%r14), %rcx
movl (%rcx,%rbx,4), %esi
addq %rax, %rsi
xorl %eax, %eax
cmpq $0x4, %rax
je 0x15a00
cmpb $-0x1, (%rsi,%rax)
leaq 0x1(%rax), %rax
je 0x159d6
movq %r15, %rdi
callq 0x8948
movq %r13, %rdi
movq %r15, %rsi
callq 0x8ea0
movq 0x10(%rsp), %rdi
jmp 0x15a18
andq $0x0, 0x30(%rsp)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
callq 0x8ea0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x15a23
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x78(%r14), %rax
cmpl $0x1, (%rax,%rbx,4)
jne 0x15b1d
movq 0x48(%r14), %rbp
movl (%rbp,%rbx,4), %eax
leal -0x1(%rbx), %ecx
movzwl 0x6c(%r14), %r12d
movl %r12d, %r14d
imull 0x8(%rsp), %r14d
addq 0x48(%rsp), %r14
movq %rax, %rdx
addq %r14, %rdx
xorl %esi, %esi
testq %rbx, %rbx
je 0x15a62
movl (%rbp,%rcx,4), %edi
jmp 0x15a64
xorl %edi, %edi
movl %eax, %r8d
subl %edi, %r8d
cmpq %r8, %rsi
jae 0x15aa8
cmpb $-0x1, (%rdx,%rsi)
leaq 0x1(%rsi), %rsi
je 0x15a57
andq $0x0, 0x18(%rsp)
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x8ea0
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
movq 0x40(%rsp), %r14
leaq 0x10(%rsp), %r15
je 0x15b1d
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x15b1d
movq %r13, %r15
leaq -0x7(%r12), %rdi
callq 0x5040
movq %rax, %r13
movq %rax, 0x28(%rsp)
testq %rbx, %rbx
je 0x15ac8
movl -0x4(%rbp,%rbx,4), %eax
jmp 0x15aca
xorl %eax, %eax
movl (%rbp,%rbx,4), %edx
addq %rdx, %r14
subl %eax, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x5350
movb $0x0, -0x8(%r13,%r12)
leaq 0x20(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x8592
movq %r15, %r13
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
callq 0x8ea0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x15b13
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x40(%rsp), %r14
leaq 0x10(%rsp), %r15
incq %rbx
jmp 0x159a4
movq 0x8(%rsp), %rcx
incl %ecx
movzwl 0x6c(%r14), %eax
movq %rcx, 0x8(%rsp)
imulq %rcx, %rax
movq 0x58(%rsp), %rbx
movl 0x12(%rbx,%rax), %eax
movl %eax, 0x28(%rsp)
movq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x18774
movq 0x50(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x180d2
movq %r13, %rdi
callq 0x9268
jmp 0x1596f
movq 0x38(%rsp), %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
pushq $0x70
popq %rsi
movq %r15, %rdi
callq 0x53f0
jmp 0x15be3
jmp 0x15ba7
jmp 0x15ba7
movq %rax, %r14
movq 0x10(%rsp), %rdi
jmp 0x15bc8
movq %rax, %r14
jmp 0x15bdb
movq %rax, %r14
movq 0x30(%rsp), %rdi
jmp 0x15bc8
movq %rax, %r14
movq 0x18(%rsp), %rdi
jmp 0x15bc8
movq %rax, %r14
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x15bdb
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x15bdb
movq %rax, %r14
movq %r15, %r13
movq %r13, %rdi
callq 0x9268
movq %r14, %rdi
callq 0x56f0
nop