// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movq %rdi, %r14
movl $0x70, %edi
callq 0x5390
movq %rax, %r15
movq %rax, %rdi
callq 0x1cce0
movq 0x20(%r15), %rax
cmpq %rax, 0x28(%r15)
je 0x19c0b
movq %rax, 0x28(%r15)
movq 0x38(%r15), %rax
cmpq %rax, 0x40(%r15)
je 0x19c19
movq %rax, 0x40(%r15)
movq 0x50(%r15), %rbx
movq %r15, %r12
movq 0x58(%r15), %r15
cmpq %rbx, %r15
movq %r12, 0x48(%rsp)
je 0x19c4e
movq %rbx, %r12
leaq 0x8(%r12), %rdi
callq 0xa564
addq $0x20, %r12
cmpq %r15, %r12
jne 0x19c31
movq 0x48(%rsp), %r12
movq %rbx, 0x58(%r12)
leaq 0x20(%r12), %rax
movq %rax, 0x8(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r12)
movl %ebp, 0x18(%r12)
movq (%r14), %rax
movq 0x48(%rax), %rdi
movl 0x74(%r14), %esi
movl %ebp, %edx
callq 0x6768
movq %rax, %r15
movl 0x4(%rax), %eax
movl %eax, (%r12)
movl 0x8(%r15), %eax
movl %eax, 0x4(%r12)
movl 0xc(%r15), %eax
movl %eax, 0x6c(%r12)
movzwl 0x10(%r15), %eax
movl %eax, 0x1c(%r12)
testl %eax, %eax
movq %r12, %rbx
movq %r15, 0x40(%rsp)
je 0x19ccd
movl 0x12(%r15), %eax
movl %eax, 0x68(%rsp)
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x19cef
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
movq 0x8(%rsp), %r15
jmp 0x19d01
movl $0xffffffff, 0x68(%rsp) # imm = 0xFFFFFFFF
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x19d14
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0x19d23
leaq 0x68(%rsp), %rdx
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x1d2b4
movq (%r15), %rax
cmpl $-0x1, (%rax)
movq 0x40(%rsp), %r15
je 0x19d23
movb $0x0, 0x68(%rbx)
jmp 0x19d23
leaq 0x68(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x1d2b4
cmpl $0x0, 0x1c(%rbx)
jle 0x19fa8
addq $0x50, %rbx
movq %rbx, 0x50(%rsp)
leaq 0x70(%rsp), %rbp
movq %r15, %r12
addq $0x1a, %r12
xorl %r13d, %r13d
movq %r14, 0x58(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, (%rbp)
movq $0x0, 0x10(%rbp)
movzwl 0x6c(%r14), %eax
movl %r13d, %ecx
movq %rcx, 0x60(%rsp)
imulq %rcx, %rax
movl 0x16(%r15,%rax), %eax
movl %eax, 0x68(%rsp)
cmpl $0x0, 0x28(%r14)
je 0x19f40
xorl %r15d, %r15d
movq %r13, 0x10(%rsp)
movq 0x78(%r14), %rax
cmpl $0x0, (%rax,%r15,4)
jne 0x19e2b
movzwl 0x6c(%r14), %eax
movq 0x60(%rsp), %rbx
imulq %rax, %rbx
addq %r12, %rbx
movq 0x48(%r14), %rcx
movq %r13, %rdx
movl (%rcx,%r15,4), %r13d
imulq %rdx, %rax
addq %r12, %rax
addq %r13, %rax
xorl %ecx, %ecx
cmpb $-0x1, (%rax,%rcx)
jne 0x19de9
incq %rcx
cmpq $0x4, %rcx
jne 0x19dbd
movq $0x0, 0x30(%rsp)
movq %rbp, %rdi
leaq 0x30(%rsp), %rsi
callq 0xa1bc
movq 0x30(%rsp), %rdi
jmp 0x19e1b
movl $0x10, %edi
callq 0x5390
leaq 0x39c7e(%rip), %rcx     # 0x53a78
movq %rcx, (%rax)
movl (%rbx,%r13), %ecx
movl %ecx, 0x8(%rax)
movq %rax, 0x28(%rsp)
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
callq 0xa1bc
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
movq 0x10(%rsp), %r13
je 0x19e2b
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x78(%r14), %rax
cmpl $0x1, (%rax,%r15,4)
jne 0x19f30
movq 0x48(%r14), %rbx
movl (%rbx,%r15,4), %eax
leal -0x1(%r15), %ecx
movzwl 0x6c(%r14), %edx
imull %r13d, %edx
addq %r12, %rdx
addq %rax, %rdx
xorl %esi, %esi
testq %r15, %r15
je 0x19e61
movl (%rbx,%rcx,4), %edi
jmp 0x19e63
xorl %edi, %edi
movl %eax, %r8d
subl %edi, %r8d
cmpl %r8d, %esi
jae 0x19ea1
cmpb $-0x1, (%rdx,%rsi)
leaq 0x1(%rsi), %rsi
je 0x19e57
movq $0x0, 0x18(%rsp)
movq %rbp, %rdi
leaq 0x18(%rsp), %rsi
callq 0xa1bc
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
jne 0x19f2a
jmp 0x19f30
movq %r14, %rax
movq %rbp, %r14
movzwl 0x6c(%rax), %r13d
leaq -0x7(%r13), %rdi
callq 0x5040
movq %rax, %rbp
testq %r15, %r15
je 0x19ec4
movl -0x4(%rbx,%r15,4), %eax
jmp 0x19ec6
xorl %eax, %eax
movq 0x10(%rsp), %rsi
imull %r13d, %esi
movl (%rbx,%r15,4), %edx
addq %r12, %rsi
addq %rdx, %rsi
subl %eax, %edx
movq %rbp, %rdi
callq 0x5310
movb $0x0, -0x8(%rbp,%r13)
movl $0x10, %edi
callq 0x5390
leaq 0x39b56(%rip), %rcx     # 0x53a50
movq %rcx, (%rax)
movq %rbp, 0x8(%rax)
movq %rax, 0x20(%rsp)
movq %r14, %rbp
movq %r14, %rdi
leaq 0x20(%rsp), %rsi
callq 0xa1bc
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
movq 0x58(%rsp), %r14
movq 0x10(%rsp), %r13
je 0x19f30
movq (%rdi), %rax
callq *0x8(%rax)
incq %r15
movl 0x28(%r14), %eax
cmpq %rax, %r15
jb 0x19d86
incq %r13
movzwl 0x6c(%r14), %eax
movl %r13d, %ecx
imulq %rax, %rcx
movq 0x40(%rsp), %r15
movl 0x12(%r15,%rcx), %eax
movl %eax, 0x3c(%rsp)
movq 0x48(%rsp), %rbx
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x19f78
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0x19f87
movq 0x8(%rsp), %rdi
leaq 0x3c(%rsp), %rdx
callq 0x1d2b4
movq 0x50(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x1cdce
movq %rbp, %rdi
callq 0xa564
cmpl 0x1c(%rbx), %r13d
jl 0x19d4a
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movl $0x70, %esi
movq %r15, %rdi
callq 0x53a0
jmp 0x1a019
jmp 0x19fe7
jmp 0x19fe7
movq %rax, %rbx
movq 0x30(%rsp), %rdi
jmp 0x19ffe
movq %rax, %rbx
movq 0x28(%rsp), %rdi
jmp 0x19ffe
movq %rax, %rbx
jmp 0x1a011
movq %rax, %rbx
movq 0x18(%rsp), %rdi
jmp 0x19ffe
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x1a011
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x1a011
movq %rax, %rbx
movq %r14, %rbp
movq %rbp, %rdi
callq 0xa564
movq %rbx, %rdi
callq 0x56e0
nop