// File: /workspace/github_cpp_makefile_star2_O3/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 0x1c61a
movq 0x20(%r15), %rax
cmpq %rax, 0x28(%r15)
je 0x1944b
movq %rax, 0x28(%r15)
movq 0x38(%r15), %rax
cmpq %rax, 0x40(%r15)
je 0x19459
movq %rax, 0x40(%r15)
movq 0x50(%r15), %rbx
movq %r15, %r12
movq 0x58(%r15), %r15
cmpq %rbx, %r15
movq %r12, 0x38(%rsp)
je 0x1948e
movq %rbx, %r12
leaq 0x8(%r12), %rdi
callq 0xa37e
addq $0x20, %r12
cmpq %r15, %r12
jne 0x19471
movq 0x38(%rsp), %r12
movq %rbx, 0x58(%r12)
leaq 0x20(%r12), %r15
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 0x6722
movl 0x4(%rax), %ecx
movl %ecx, (%r12)
movl 0x8(%rax), %ecx
movl %ecx, 0x4(%r12)
movl 0xc(%rax), %ecx
movl %ecx, 0x6c(%r12)
movzwl 0x10(%rax), %ecx
movl %ecx, 0x1c(%r12)
testl %ecx, %ecx
movq %r12, %rbx
movq %rax, 0x40(%rsp)
movq %r15, 0x70(%rsp)
je 0x19501
movl 0x12(%rax), %eax
movl %eax, 0x50(%rsp)
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x19523
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0x19530
movl $0xffffffff, 0x50(%rsp) # imm = 0xFFFFFFFF
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x1953e
movl $0xffffffff, (%rsi)     # imm = 0xFFFFFFFF
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0x1954b
leaq 0x50(%rsp), %rdx
movq %r15, %rdi
callq 0x1cbbc
movq (%r15), %rax
cmpl $-0x1, (%rax)
je 0x1954b
movb $0x0, 0x68(%rbx)
jmp 0x1954b
leaq 0x50(%rsp), %rdx
movq %r15, %rdi
callq 0x1cbbc
cmpl $0x0, 0x1c(%rbx)
movq 0x40(%rsp), %r15
jle 0x197d0
movq %rbx, %rax
addq $0x50, %rax
movq %rax, 0x78(%rsp)
leaq 0x58(%rsp), %r13
movq %r15, %rax
addq $0x1a, %rax
movq %rax, 0x48(%rsp)
xorl %r12d, %r12d
xorps %xmm0, %xmm0
movups %xmm0, (%r13)
movq $0x0, 0x10(%r13)
movzwl 0x6c(%r14), %eax
movq %r12, 0x8(%rsp)
movl %r12d, %ecx
movq %rcx, 0x80(%rsp)
imulq %rax, %rcx
movl 0x16(%r15,%rcx), %ecx
movl %ecx, 0x50(%rsp)
cmpl $0x0, 0x28(%r14)
je 0x1976e
xorl %r15d, %r15d
movq 0x78(%r14), %rax
cmpl $0x0, (%rax,%r15,4)
jne 0x19661
movzwl 0x6c(%r14), %eax
movq 0x80(%rsp), %rbx
imulq %rax, %rbx
movq 0x48(%rsp), %rdx
addq %rdx, %rbx
movq 0x48(%r14), %rcx
movl (%rcx,%r15,4), %r12d
imulq 0x8(%rsp), %rax
addq %rdx, %rax
addq %r12, %rax
xorl %ecx, %ecx
cmpb $-0x1, (%rax,%rcx)
jne 0x19624
incq %rcx
cmpq $0x4, %rcx
jne 0x195f8
movq $0x0, 0x28(%rsp)
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0x9f9a
movq 0x28(%rsp), %rdi
jmp 0x19656
movl $0x10, %edi
callq 0x5390
leaq 0x39443(%rip), %rcx     # 0x52a78
movq %rcx, (%rax)
movl (%rbx,%r12), %ecx
movl %ecx, 0x8(%rax)
movq %rax, 0x20(%rsp)
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x9f9a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x19661
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x78(%r14), %rax
cmpl $0x1, (%rax,%r15,4)
jne 0x1974f
movq 0x48(%r14), %r13
movl (%r13,%r15,4), %eax
leal -0x1(%r15), %ecx
movzwl 0x6c(%r14), %ebx
movl %ebx, %ebp
imull 0x8(%rsp), %ebp
addq 0x48(%rsp), %rbp
movq %rax, %rdx
addq %rbp, %rdx
xorl %esi, %esi
testq %r15, %r15
je 0x196a2
movl (%r13,%rcx,4), %edi
jmp 0x196a4
xorl %edi, %edi
movl %eax, %r8d
subl %edi, %r8d
cmpq %r8, %rsi
jae 0x196db
cmpb $-0x1, (%rdx,%rsi)
leaq 0x1(%rsi), %rsi
je 0x19696
movq $0x0, 0x10(%rsp)
leaq 0x58(%rsp), %r13
movq %r13, %rdi
leaq 0x10(%rsp), %rsi
callq 0x9f9a
movq 0x10(%rsp), %rdi
jmp 0x19744
leaq -0x7(%rbx), %rdi
callq 0x5040
movq %rax, %r12
testq %r15, %r15
je 0x196f3
movl -0x4(%r13,%r15,4), %eax
jmp 0x196f5
xorl %eax, %eax
movl (%r13,%r15,4), %edx
addq %rdx, %rbp
subl %eax, %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x5310
movb $0x0, -0x8(%r12,%rbx)
movl $0x10, %edi
callq 0x5390
leaq 0x3932f(%rip), %rcx     # 0x52a50
movq %rcx, (%rax)
movq %r12, 0x8(%rax)
movq %rax, 0x18(%rsp)
leaq 0x58(%rsp), %r13
movq %r13, %rdi
leaq 0x18(%rsp), %rsi
callq 0x9f9a
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1974f
movq (%rdi), %rax
callq *0x8(%rax)
incq %r15
movl 0x28(%r14), %eax
cmpq %rax, %r15
jb 0x195ba
movzwl 0x6c(%r14), %eax
movq 0x38(%rsp), %rbx
movq 0x40(%rsp), %r15
movq 0x8(%rsp), %rcx
incq %rcx
movq %rcx, %r12
movl %ecx, %ecx
movl %eax, %eax
imulq %rcx, %rax
movl 0x12(%r15,%rax), %eax
movl %eax, 0x34(%rsp)
movq 0x28(%rbx), %rsi
cmpq 0x30(%rbx), %rsi
je 0x197a0
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x28(%rbx)
jmp 0x197af
movq 0x70(%rsp), %rdi
leaq 0x34(%rsp), %rdx
callq 0x1cbbc
movq 0x78(%rsp), %rdi
leaq 0x50(%rsp), %rsi
callq 0x1c6ac
movq %r13, %rdi
callq 0xa37e
cmpl 0x1c(%rbx), %r12d
jl 0x1957a
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
movl $0x70, %esi
movq %r15, %rdi
callq 0x53a0
jmp 0x19843
jmp 0x1980f
jmp 0x1980f
movq %rax, %r14
movq 0x28(%rsp), %rdi
jmp 0x19826
movq %rax, %r14
movq 0x20(%rsp), %rdi
jmp 0x19826
movq %rax, %r14
jmp 0x1983b
movq %rax, %r14
movq 0x10(%rsp), %rdi
jmp 0x19826
movq %rax, %r14
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x1983b
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x1983b
movq %rax, %r14
leaq 0x58(%rsp), %r13
movq %r13, %rdi
callq 0xa37e
movq %r14, %rdi
callq 0x56e0
nop