// File: /workspace/github_cpp_makefile_star2_O3/Konano[P]UselessDatabase/Index.cpp
// Function: Index::convert_BtreeNode_to_buf(BtreeNode*)
void Index::convert_BtreeNode_to_buf(BtreeNode* node) {
    int _index;
    BufType buf = table->bpm->getPage(fileID, node->index, _index);

    *(uint32_t*) buf = -1; buf += 4; 
    *(uint32_t*) buf = node->left_page_index; buf += 4; 
    *(uint32_t*) buf = node->right_page_index; buf += 4; 
    *(uint32_t*) buf = node->fa_index; buf += 4;
    *(uint16_t*) buf = node->record_cnt; buf += 2; 

    if (node->record_cnt != 0) {
        *(uint32_t*) buf = node->child[0]; buf += 4;
    }
    for (int i = 0; i < node->record_cnt; i++) {
        *(uint32_t*) buf = node->record[i].record_id; buf += 4;
        for (uint j = 0; j < this->key_num; j++) {
            if (this->ty[j] == enumType::INT) {
                if(node->record[i].key[j].isNull()){
                    for (uint k = 0; k < 4; k++) {
                        *(uint8_t*)buf = 255;
                        buf += 1;
                    }
                }
                else {
                    *(uint32_t*)buf = *node->record[i].key[j].anyCast<int>();
                    buf += 4;
                }
            }
            if (this->ty[j] == enumType::CHAR) {
                if(node->record[i].key[j].isNull()){
                    for (uint k = 0; k < this->offset[j] - (j == 0 ? 0 : this->offset[j - 1]); k++) {
                        *(uint8_t*)buf = 255;
                        buf += 1;
                    }
                }
                else{
                    memcpy(buf, *node->record[i].key[j].anyCast<char*>(), this->offset[j] - (j == 0 ? 0 : this->offset[j - 1]));
                    buf += this->offset[j] - (j == 0 ? 0 : this->offset[j - 1]);
                }
            }
        }
        *(uint32_t*) buf = node->child[i + 1]; buf += 4;
    }
    table->bpm->markDirty(_index);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x48(%rax), %rdi
movl 0x74(%rbx), %esi
movl 0x18(%r14), %edx
leaq 0x4(%rsp), %rcx
callq 0x67e4
movq %rax, %r15
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movl (%r14), %eax
movl %eax, 0x4(%r15)
movl 0x4(%r14), %eax
movl %eax, 0x8(%r15)
movl 0x6c(%r14), %eax
movl %eax, 0xc(%r15)
movl 0x1c(%r14), %eax
movw %ax, 0x10(%r15)
testl %eax, %eax
je 0x19a10
movq 0x20(%r14), %rax
movl (%rax), %eax
movl %eax, 0x12(%r15)
cmpl $0x0, 0x1c(%r14)
jle 0x19a10
addq $0x16, %r15
xorl %ebp, %ebp
movq 0x50(%r14), %rax
movq %rbp, %r13
shlq $0x5, %r13
movl (%rax,%r13), %eax
movl %eax, (%r15)
addq $0x4, %r15
cmpl $0x0, 0x28(%rbx)
je 0x199f1
xorl %r12d, %r12d
movq 0x78(%rbx), %rax
movl (%rax,%r12,4), %eax
testl %eax, %eax
je 0x19950
cmpl $0x1, %eax
jne 0x199e2
movq 0x50(%r14), %rax
movq 0x8(%rax,%r13), %rax
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x19983
leaq 0x38dce(%rip), %rsi     # 0x526e0
leaq 0x38dd7(%rip), %rdx     # 0x526f0
xorl %ecx, %ecx
callq 0x5430
movq 0x8(%rax), %rsi
movq 0x48(%rbx), %rax
movl (%rax,%r12,4), %edx
testq %r12, %r12
je 0x199cb
subl -0x4(%rax,%r12,4), %edx
movq %r15, %rdi
callq 0x5310
movq 0x48(%rbx), %rax
movl -0x4(%rax,%r12,4), %ecx
jmp 0x199d9
movq 0x50(%r14), %rax
movq 0x8(%rax,%r13), %rax
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x199b3
leaq 0x38d77(%rip), %rsi     # 0x526e0
leaq 0x38d98(%rip), %rdx     # 0x52708
xorl %ecx, %ecx
callq 0x5430
movl 0x8(%rax), %eax
movl %eax, (%r15)
addq $0x4, %r15
jmp 0x199e2
leal -0x1(%r12), %eax
xorl %ecx, %ecx
movq 0x48(%rbx), %rsi
movl (%rsi,%r12,4), %edx
testq %r12, %r12
je 0x1999c
movl (%rsi,%rax,4), %esi
jmp 0x1999e
xorl %esi, %esi
subl %esi, %edx
cmpl %edx, %ecx
jae 0x199ae
movb $-0x1, (%r15,%rcx)
incq %rcx
jmp 0x1998a
addq %rcx, %r15
jmp 0x199e2
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
addq $0x4, %r15
movq 0x78(%rbx), %rax
movl (%rax,%r12,4), %eax
jmp 0x198f0
movq %r15, %rdi
callq 0x5310
movq 0x48(%rbx), %rax
xorl %ecx, %ecx
movl (%rax,%r12,4), %eax
subl %ecx, %eax
addq %rax, %r15
incq %r12
movl 0x28(%rbx), %eax
cmpq %rax, %r12
jb 0x198e4
movq 0x20(%r14), %rax
movl 0x4(%rax,%rbp,4), %eax
incq %rbp
movl %eax, (%r15)
addq $0x4, %r15
movslq 0x1c(%r14), %rax
cmpq %rax, %rbp
jl 0x198c1
movq (%rbx), %rax
movq 0x48(%rax), %rdi
movl 0x4(%rsp), %esi
callq 0x689e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop