// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x18, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rdi), %rax
movq 0x48(%rax), %rdi
movl 0x74(%rbx), %esi
movl 0x18(%r14), %edx
leaq 0xc(%rsp), %rcx
callq 0x6834
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 0x1a08b
movq 0x20(%r14), %rax
movl (%rax), %eax
movl %eax, 0x12(%r15)
addq $0x16, %r15
jmp 0x1a08f
addq $0x12, %r15
cmpl $0x0, 0x1c(%r14)
jle 0x1a1df
xorl %r13d, %r13d
movq 0x50(%r14), %rax
movq %r13, 0x10(%rsp)
shlq $0x5, %r13
movl (%rax,%r13), %eax
movl %eax, (%r15)
addq $0x4, %r15
cmpl $0x0, 0x28(%rbx)
je 0x1a1ba
xorl %r12d, %r12d
movq 0x78(%rbx), %rax
cmpl $0x0, (%rax,%r12,4)
jne 0x1a107
movq 0x50(%r14), %rax
movq 0x8(%rax,%r13), %rax
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x1a0fc
leaq 0x395c2(%rip), %rsi     # 0x536a8
leaq 0x395e3(%rip), %rdx     # 0x536d0
xorl %ecx, %ecx
callq 0x5430
movl 0x8(%rax), %eax
movl %eax, (%r15)
jmp 0x1a103
movl $0xffffffff, (%r15)     # imm = 0xFFFFFFFF
addq $0x4, %r15
movq 0x78(%rbx), %rax
cmpl $0x1, (%rax,%r12,4)
jne 0x1a1ab
movq 0x50(%r14), %rax
movq 0x8(%rax,%r13), %rax
movq (%rax,%r12,8), %rdi
testq %rdi, %rdi
je 0x1a17d
xorl %ebp, %ebp
leaq 0x39577(%rip), %rsi     # 0x536a8
leaq 0x39580(%rip), %rdx     # 0x536b8
xorl %ecx, %ecx
callq 0x5430
movq 0x48(%rbx), %rcx
movl $0x0, %edi
testq %r12, %r12
je 0x1a152
movl -0x4(%rcx,%r12,4), %edi
movq 0x8(%rax), %rsi
movl (%rcx,%r12,4), %edx
subl %edi, %edx
movq %r15, %rdi
callq 0x5310
movq 0x48(%rbx), %rcx
movl (%rcx,%r12,4), %eax
testq %r12, %r12
je 0x1a176
movl -0x4(%rcx,%r12,4), %ebp
subl %ebp, %eax
addq %rax, %r15
jmp 0x1a1ab
leal -0x1(%r12), %eax
xorl %ecx, %ecx
movq 0x48(%rbx), %rsi
movl (%rsi,%r12,4), %edx
testq %r12, %r12
je 0x1a196
movl (%rsi,%rax,4), %esi
jmp 0x1a198
xorl %esi, %esi
subl %esi, %edx
cmpl %edx, %ecx
jae 0x1a1a8
movb $-0x1, (%r15,%rcx)
incq %rcx
jmp 0x1a184
addq %rcx, %r15
incq %r12
movl 0x28(%rbx), %eax
cmpq %rax, %r12
jb 0x1a0c2
movq 0x20(%r14), %rax
movq 0x10(%rsp), %r13
movl 0x4(%rax,%r13,4), %eax
incq %r13
movl %eax, (%r15)
addq $0x4, %r15
movslq 0x1c(%r14), %rax
cmpq %rax, %r13
jl 0x1a09d
movq (%rbx), %rax
movq 0x48(%rax), %rdi
movl 0xc(%rsp), %esi
callq 0x68ee
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq