// File: 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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movl -0x18(%rbp), %esi
callq 0x36fd0
movq %rax, -0x20(%rbp)
movl $0x0, -0x24(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x3de50
movq -0x20(%rbp), %rdi
addq $0x50, %rdi
callq 0x3d460
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
addq $0x50, %rdi
callq 0x3d490
movq %rax, -0x40(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3d4c0
testb $0x1, %al
jne 0x3944a
jmp 0x394b9
leaq -0x30(%rbp), %rdi
callq 0x3de70
movq %rax, %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
callq 0xc710
testb $0x1, %al
jne 0x39469
jmp 0x3946b
jmp 0x394b9
leaq -0x30(%rbp), %rdi
callq 0x3de70
movq %rax, %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
callq 0xc500
testb $0x1, %al
jne 0x3948a
jmp 0x3949c
leaq -0x30(%rbp), %rdi
callq 0x3de70
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jl 0x3949c
jmp 0x394b9
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
callq 0x3d920
movq %rax, -0x48(%rbp)
jmp 0x39426
movq -0x20(%rbp), %rdi
addq $0x50, %rdi
callq 0x3d490
movq %rax, -0x50(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3d4c0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x71(%rbp)
jne 0x394e5
jmp 0x394f9
leaq -0x30(%rbp), %rdi
callq 0x3de70
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
sete %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x39505
jmp 0x3966c
movq -0x20(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x39575
movq -0x20(%rbp), %rax
addq $0x50, %rax
movq %rax, -0x80(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3d9d0
movq -0x80(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x3d960
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
callq 0x3df10
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x1c(%rax)
movq -0x20(%rbp), %rsi
callq 0x376a0
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x37e20
jmp 0x3966a
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
movl -0x24(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
callq 0x3d6f0
movq -0x70(%rbp), %rdi
movl (%rax), %esi
callq 0x36fd0
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d6f0
cmpl $-0x1, (%rax)
je 0x395d2
movq -0x68(%rbp), %rdi
addq $0x20, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d6f0
movq -0x70(%rbp), %rdi
movl (%rax), %esi
callq 0x36fd0
movq %rax, -0x68(%rbp)
jmp 0x3959a
movq -0x68(%rbp), %rdi
addq $0x50, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d7a0
movq %rax, -0x90(%rbp)
movq -0x20(%rbp), %rdi
addq $0x50, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d7a0
movq -0x90(%rbp), %rsi
movq %rax, %rdi
callq 0x3dd10
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x376a0
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x376a0
movq -0x68(%rbp), %rdi
addq $0x50, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d7a0
addq $0x8, %rax
movq %rax, -0x88(%rbp)
movq -0x68(%rbp), %rdi
addq $0x50, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x3d7a0
movq -0x70(%rbp), %rdi
movq -0x88(%rbp), %rsi
movl (%rax), %edx
movq -0x68(%rbp), %rax
movl 0x18(%rax), %ecx
callq 0x393d0
jmp 0x396c2
movq -0x70(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x376a0
movq -0x20(%rbp), %rax
testb $0x1, 0x68(%rax)
jne 0x396c0
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x94(%rbp)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d6f0
movq -0x70(%rbp), %rdi
movq -0xa0(%rbp), %rsi
movl -0x94(%rbp), %edx
movl (%rax), %ecx
callq 0x393d0
jmp 0x396c2
addq $0xa0, %rsp
popq %rbp
retq
nopl (%rax,%rax)