// File: Konano[P]UselessDatabase/Index.cpp
// Function: Index::insertRecord(Anys*, int, int)
void Index::insertRecord(Anys* info, int record_id, int now_index) {

    BtreeNode* now = Index::convert_buf_to_BtreeNode(now_index);

    //BtreeNode *now = Index::convert_buf_to_BtreeNode(index);
    //cout << "insert" << now->index << " "  << now->record_cnt;
    //cout << " " << (*info)[0].anyCast<int>() << " " << record_id << endl;
    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 (now->is_leaf) {
        now->record.insert(it, BtreeRecord(record_id, *info));
        now->record_cnt++;
        now->child.push_back(-1);
        Index::convert_BtreeNode_to_buf(now);
        overflow_upstream(now->index);
        return;
    }
    else {
        Index::convert_BtreeNode_to_buf(now);
        Index::insertRecord(info, record_id, now->child[i]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xb0(%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 0x3918d
jmp 0x391fc
leaq -0x30(%rbp), %rdi
callq 0x3de70
movq %rax, %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
callq 0xc710
testb $0x1, %al
jne 0x391ac
jmp 0x391ae
jmp 0x391fc
leaq -0x30(%rbp), %rdi
callq 0x3de70
movq %rax, %rdi
addq $0x8, %rdi
movq -0x10(%rbp), %rsi
callq 0xc500
testb $0x1, %al
jne 0x391cd
jmp 0x391df
leaq -0x30(%rbp), %rdi
callq 0x3de70
movl (%rax), %eax
cmpl -0x14(%rbp), %eax
jle 0x391df
jmp 0x391fc
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 0x39169
movq -0x20(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x3932e
movq -0x20(%rbp), %rax
addq $0x50, %rax
movq %rax, -0xc8(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3d9d0
movl -0x14(%rbp), %eax
movl %eax, -0xbc(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x88(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0xc400
movl -0xbc(%rbp), %esi
movq -0xb8(%rbp), %rdx
leaq -0x70(%rbp), %rdi
callq 0x3ded0
jmp 0x3925e
movq -0xc8(%rbp), %rdi
movq -0x50(%rbp), %rsi
leaq -0x70(%rbp), %rdx
callq 0x3de90
movq %rax, -0xd0(%rbp)
jmp 0x3927b
movq -0xd0(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3d560
leaq -0x88(%rbp), %rdi
callq 0xc430
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x1c(%rax)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
movl $0xffffffff, -0xa4(%rbp) # imm = 0xFFFFFFFF
leaq -0xa4(%rbp), %rsi
callq 0x3d6c0
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x376a0
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rax
movl 0x18(%rax), %esi
callq 0x38ad0
jmp 0x3937e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0x39320
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3d560
leaq -0x88(%rbp), %rdi
callq 0xc430
jmp 0x39387
movq -0xb0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x376a0
movq -0x10(%rbp), %rax
movq %rax, -0xe0(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0xd4(%rbp)
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
movslq -0x24(%rbp), %rsi
callq 0x3d6f0
movq -0xb0(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movl -0xd4(%rbp), %edx
movl (%rax), %ecx
callq 0x39110
addq $0xe0, %rsp
popq %rbp
retq
movq -0x90(%rbp), %rdi
callq 0x6890
nopw %cs:(%rax,%rax)