// File: 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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq (%rax), %rcx
movq 0x48(%rcx), %rdi
movl 0x74(%rax), %esi
movq -0x10(%rbp), %rax
movl 0x18(%rax), %edx
leaq -0x14(%rbp), %rcx
callq 0x71d0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x6c(%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movw %ax, %cx
movq -0x20(%rbp), %rax
movw %cx, (%rax)
movq -0x20(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x37782
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d6f0
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0x37a80
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d7a0
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x28(%rbp)
movq -0x38(%rbp), %rcx
movl -0x28(%rbp), %eax
cmpl 0x28(%rcx), %eax
jae 0x37a48
movq -0x38(%rbp), %rdi
addq $0x78, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x3cfb0
cmpl $0x0, (%rax)
jne 0x37889
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d7a0
movq %rax, %rdi
addq $0x8, %rdi
movl -0x28(%rbp), %esi
callq 0xc8f0
movq %rax, %rdi
callq 0xc920
testb $0x1, %al
jne 0x3781e
jmp 0x3784b
movl $0x0, -0x2c(%rbp)
cmpl $0x4, -0x2c(%rbp)
jae 0x37849
movq -0x20(%rbp), %rax
movb $-0x1, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x37825
jmp 0x37887
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d7a0
movq %rax, %rdi
addq $0x8, %rdi
movl -0x28(%rbp), %esi
callq 0xc8f0
movq %rax, %rdi
callq 0x10b40
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
jmp 0x37889
movq -0x38(%rbp), %rdi
addq $0x78, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x3cfb0
cmpl $0x1, (%rax)
jne 0x37a38
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d7a0
movq %rax, %rdi
addq $0x8, %rdi
movl -0x28(%rbp), %esi
callq 0xc8f0
movq %rax, %rdi
callq 0xc920
testb $0x1, %al
jne 0x378d2
jmp 0x37951
movl $0x0, -0x30(%rbp)
movq -0x38(%rbp), %rdi
movl -0x30(%rbp), %eax
movl %eax, -0x40(%rbp)
addq $0x48, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x3cf40
movl (%rax), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x37903
xorl %eax, %eax
movl %eax, -0x44(%rbp)
jmp 0x3791f
movq -0x38(%rbp), %rdi
addq $0x48, %rdi
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x3cf40
movl (%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x40(%rbp), %eax
movl -0x3c(%rbp), %ecx
movl -0x44(%rbp), %edx
subl %edx, %ecx
cmpl %ecx, %eax
jae 0x3794c
movq -0x20(%rbp), %rax
movb $-0x1, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x378d9
jmp 0x37a36
movq -0x20(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rdi
addq $0x50, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d7a0
movq %rax, %rdi
addq $0x8, %rdi
movl -0x28(%rbp), %esi
callq 0xc8f0
movq %rax, %rdi
callq 0x10a50
movq -0x38(%rbp), %rdi
movq (%rax), %rax
movq %rax, -0x50(%rbp)
addq $0x48, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x3cf40
movl (%rax), %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x379ac
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x379c8
movq -0x38(%rbp), %rdi
addq $0x48, %rdi
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x3cf40
movl (%rax), %eax
movl %eax, -0x5c(%rbp)
movq -0x50(%rbp), %rsi
movq -0x58(%rbp), %rdi
movl -0x48(%rbp), %eax
movl -0x5c(%rbp), %ecx
subl %ecx, %eax
movl %eax, %eax
movl %eax, %edx
callq 0x63f0
movq -0x38(%rbp), %rdi
addq $0x48, %rdi
movl -0x28(%rbp), %eax
movl %eax, %esi
callq 0x3cf40
movl (%rax), %eax
movl %eax, -0x60(%rbp)
cmpl $0x0, -0x28(%rbp)
jne 0x37a05
xorl %eax, %eax
movl %eax, -0x64(%rbp)
jmp 0x37a21
movq -0x38(%rbp), %rdi
addq $0x48, %rdi
movl -0x28(%rbp), %eax
subl $0x1, %eax
movl %eax, %eax
movl %eax, %esi
callq 0x3cf40
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl -0x60(%rbp), %ecx
movl -0x64(%rbp), %eax
subl %eax, %ecx
movq -0x20(%rbp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
jmp 0x37a38
jmp 0x37a3a
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x377c5
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x3d6f0
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
addq $0x4, %rax
movq %rax, -0x20(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x37789
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq 0x48(%rax), %rdi
movl -0x14(%rbp), %esi
callq 0x7300
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)