// File: /workspace/github_cpp_makefile_star2_O2/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 0x5d50
movq %rax, %r15
orl $-0x1, (%rax)
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 0x15c52
movq 0x20(%r14), %rax
movl (%rax), %eax
movl %eax, 0x12(%r15)
addq $0x16, %r15
jmp 0x15c56
addq $0x12, %r15
xorl %r13d, %r13d
movslq 0x1c(%r14), %rax
cmpq %rax, %r13
jge 0x15d83
movq 0x50(%r14), %rax
movq %r13, 0x10(%rsp)
shlq $0x5, %r13
movl (%rax,%r13), %eax
movl %eax, (%r15)
addq $0x4, %r15
xorl %ebp, %ebp
movl 0x28(%rbx), %eax
cmpq %rax, %rbp
jae 0x15d66
movq 0x78(%rbx), %rax
cmpl $0x0, (%rax,%rbp,4)
jne 0x15cce
movq 0x50(%r14), %rax
movq 0x8(%rax,%r13), %rax
cmpq $0x0, (%rax,%rbp,8)
je 0x15cba
leaq (%rax,%rbp,8), %rdi
callq 0x9410
movl (%rax), %eax
movl %eax, (%r15)
addq $0x4, %r15
jmp 0x15cce
xorl %eax, %eax
cmpl $0x4, %eax
je 0x15ccb
movb $-0x1, (%r15,%rax)
incq %rax
jmp 0x15cbc
addq %rax, %r15
movq 0x78(%rbx), %rax
cmpl $0x1, (%rax,%rbp,4)
jne 0x15d5e
movq 0x50(%r14), %rax
movq 0x8(%rax,%r13), %rax
cmpq $0x0, (%rax,%rbp,8)
je 0x15d33
leaq (%rax,%rbp,8), %rdi
callq 0x9398
movq 0x48(%rbx), %rcx
xorl %r12d, %r12d
movl $0x0, %edi
testq %rbp, %rbp
je 0x15d0a
movl -0x4(%rcx,%rbp,4), %edi
movq (%rax), %rsi
movl (%rcx,%rbp,4), %edx
subl %edi, %edx
movq %r15, %rdi
callq 0x5350
movq 0x48(%rbx), %rcx
movl (%rcx,%rbp,4), %eax
testq %rbp, %rbp
je 0x15d2b
movl -0x4(%rcx,%rbp,4), %r12d
subl %r12d, %eax
addq %rax, %r15
jmp 0x15d5e
leal -0x1(%rbp), %eax
xorl %ecx, %ecx
movq 0x48(%rbx), %rsi
movl (%rsi,%rbp,4), %edx
testq %rbp, %rbp
je 0x15d49
movl (%rsi,%rax,4), %esi
jmp 0x15d4b
xorl %esi, %esi
subl %esi, %edx
cmpl %edx, %ecx
jae 0x15d5b
movb $-0x1, (%r15,%rcx)
incq %rcx
jmp 0x15d38
addq %rcx, %r15
incq %rbp
jmp 0x15c80
movq 0x20(%r14), %rax
movq 0x10(%rsp), %r13
movl 0x4(%rax,%r13,4), %eax
incq %r13
movl %eax, (%r15)
addq $0x4, %r15
jmp 0x15c59
movq (%rbx), %rax
movq 0x48(%rax), %rdi
movl 0xc(%rsp), %esi
callq 0x5e0a
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq