// File: /workspace/github_cpp_makefile_star2_O1/Konano[P]UselessDatabase/Index.cpp
// Function: Index::removeRecord(Anys*, int, int)
void Index::removeRecord(Anys* info, int record_id, int now_index) {
    //cout << "remove" << now->index << " "  << now->record_cnt << " " << record_id << endl;

    BtreeNode* now = Index::convert_buf_to_BtreeNode(now_index);

    int i = 0;
    vector<BtreeRecord>::iterator it;
    for (it = now->record.begin(); it!=now->record.end(); it++)
    {
        if (it->key > *info) {
            break;
        }
        if (it->key == *info && it->record_id >= record_id) {
            break;
        }
        i ++;
    }
    if (it != now->record.end() && it->record_id == record_id) {
        if (now->is_leaf) {
            now->record.erase(it);
            now->child.pop_back();
            now->record_cnt--;
            Index::convert_BtreeNode_to_buf(now);
            overflow_downstream(now->index);
        }
        else {
            BtreeNode* follow_node = Index::convert_buf_to_BtreeNode(now->child[i + 1]);
            while (follow_node->child[0] != -1)follow_node = Index::convert_buf_to_BtreeNode(follow_node->child[0]);
            now->record[i] = follow_node->record[0];
            Index::convert_BtreeNode_to_buf(now);
            Index::convert_BtreeNode_to_buf(follow_node);
            Index::removeRecord(&follow_node->record[0].key, follow_node->record[0].record_id, follow_node->index);
        }
    }
    else {
        Index::convert_BtreeNode_to_buf(now);
        if (!now->is_leaf) Index::removeRecord(info, record_id, now->child[i]);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, %ebp
movq %rsi, %r15
movq %rdi, %rbx
movq %rdi, (%rsp)
movq %rbx, %rdi
movl %ecx, %esi
callq 0x19bd2
movq %rax, %r14
movq 0x50(%rax), %r12
cmpq 0x58(%rax), %r12
je 0x1b05e
xorl %ebx, %ebx
leaq 0x8(%r12), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x9be2
testb %al, %al
jne 0x1b055
movq %r13, %rdi
movq %r15, %rsi
callq 0x9abe
testb %al, %al
je 0x1b049
cmpl %ebp, (%r12)
jge 0x1b055
incl %ebx
addq $0x20, %r12
cmpq 0x58(%r14), %r12
jne 0x1b020
movl %ebx, %r13d
movq (%rsp), %rbx
jmp 0x1b061
xorl %r13d, %r13d
cmpq 0x58(%r14), %r12
je 0x1b06d
cmpl %ebp, (%r12)
je 0x1b090
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a022
cmpb $0x0, 0x68(%r14)
jne 0x1b105
movq 0x20(%r14), %rax
movl (%rax,%r13,4), %ecx
jmp 0x1b007
cmpb $0x1, 0x68(%r14)
je 0x1b114
movq 0x20(%r14), %rax
movl 0x4(%rax,%r13,4), %esi
movq %rbx, %rdi
callq 0x19bd2
movq %rax, %r12
movq 0x20(%rax), %rax
movl (%rax), %esi
cmpl $-0x1, %esi
jne 0x1b0a0
movq 0x50(%r12), %rsi
movq 0x50(%r14), %rax
shlq $0x5, %r13
movl (%rsi), %ecx
leaq (%rax,%r13), %rdi
addq $0x8, %rdi
movl %ecx, -0x8(%rdi)
addq $0x8, %rsi
callq 0x1cefe
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a022
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1a022
movq 0x50(%r12), %r15
movl (%r15), %ebp
addq $0x8, %r15
movl 0x18(%r12), %ecx
jmp 0x1b007
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
addq $0x50, %rdi
movq %r12, %rsi
callq 0x1dbf8
addq $-0x4, 0x28(%r14)
decl 0x1c(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1a022
movl 0x18(%r14), %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x1a49a
nop