// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x18, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, %r15
movq %rdi, %r13
movq %rdi, 0x10(%rsp)
movq %r13, %rdi
movl %ecx, %esi
callq 0x1586c
movq %rax, %r14
movq 0x50(%rax), %r12
xorl %ebp, %ebp
xorl %ebx, %ebx
cmpq 0x58(%r14), %r12
je 0x16947
leaq 0x8(%r12), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x8700
testb %al, %al
jne 0x16947
movq %r13, %rdi
movq %r15, %rsi
callq 0x85ea
testb %al, %al
je 0x16939
movl 0xc(%rsp), %eax
cmpl %eax, (%r12)
jge 0x16947
addq $0x20, %r12
addq $-0x20, %rbx
addq $0x4, %rbp
jmp 0x16906
cmpq 0x58(%r14), %r12
je 0x16957
movl 0xc(%rsp), %eax
cmpl %eax, (%r12)
je 0x1697a
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
callq 0x15bec
cmpb $0x0, 0x68(%r14)
jne 0x169e5
movq 0x20(%r14), %rax
movl (%rax,%rbp), %ecx
jmp 0x168f1
cmpb $0x1, 0x68(%r14)
movq 0x10(%rsp), %r13
je 0x169f4
movq 0x20(%r14), %rax
movl 0x4(%rax,%rbp), %esi
movq %r13, %rdi
callq 0x1586c
movq %rax, %r12
movq 0x20(%rax), %rax
movl (%rax), %esi
cmpl $-0x1, %esi
jne 0x1698e
movq 0x50(%r12), %rsi
movq 0x50(%r14), %rdi
subq %rbx, %rdi
callq 0x1821c
movq %r13, %rdi
movq %r14, %rsi
callq 0x15bec
movq %r13, %rdi
movq %r12, %rsi
callq 0x15bec
movq 0x50(%r12), %r15
movl (%r15), %eax
movl %eax, 0xc(%rsp)
addq $0x8, %r15
movl 0x18(%r12), %ecx
jmp 0x168f1
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
addq $0x50, %rdi
movq %r12, %rsi
callq 0x18140
addq $-0x4, 0x28(%r14)
decl 0x1c(%r14)
movq %r13, %rdi
movq %r14, %rsi
callq 0x15bec
movl 0x18(%r14), %esi
movq %r13, %rdi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x15fa4
nop