// File: /workspace/github_cpp_makefile_star2_O3/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 0x19412
movq %rax, %r14
movq 0x50(%rax), %r12
cmpq 0x58(%rax), %r12
je 0x1a931
xorl %ebx, %ebx
leaq 0x8(%r12), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x9aa6
testb %al, %al
jne 0x1a89d
movq %r13, %rdi
movq %r15, %rsi
callq 0x9996
testb %al, %al
je 0x1a891
cmpl %ebp, (%r12)
jge 0x1a89d
incl %ebx
addq $0x20, %r12
cmpq 0x58(%r14), %r12
jne 0x1a868
movl %ebx, %r13d
cmpq 0x58(%r14), %r12
je 0x1a936
cmpl %ebp, (%r12)
movq (%rsp), %rbx
jne 0x1a93a
cmpb $0x1, 0x68(%r14)
je 0x1a968
movq 0x20(%r14), %rax
movl 0x4(%rax,%r13,4), %esi
movq %rbx, %rdi
callq 0x19412
movq %rax, %r12
movq 0x20(%rax), %rax
movl (%rax), %esi
cmpl $-0x1, %esi
jne 0x1a8cc
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 0x1c7e2
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1984c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x1984c
movq 0x50(%r12), %r15
movl (%r15), %ebp
addq $0x8, %r15
movl 0x18(%r12), %ecx
jmp 0x1a84b
xorl %r13d, %r13d
jmp 0x1a93a
movq (%rsp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1984c
cmpb $0x0, 0x68(%r14)
jne 0x1a959
movq 0x20(%r14), %rax
movl (%rax,%r13,4), %ecx
jmp 0x1a84b
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 0x1d508
addq $-0x4, 0x28(%r14)
decl 0x1c(%r14)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1984c
movl 0x18(%r14), %esi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x19cbe
nop