// File: Konano[P]UselessDatabase/Index.cpp
// Function: Index::queryRecord(Anys*, int)
std::vector<int> Index::queryRecord(Anys* info, int now_index) {
    
    BtreeNode* now = Index::convert_buf_to_BtreeNode(now_index);

    //if((*info)[0].anyCast<int>()!=nullptr)printf("val %d\n",*(*info)[0].anyCast<int>());
    //else printf("\n");

    std::vector<int> v;

    //printf("%d\n",now->record_cnt);

    int l = -1, r = -1, i;
    for (i = 0; i < now->record_cnt; i++) {
        if (now->record[i].key == *info) {
            if (l == -1) l = i;
            r = i;
        }
        else if (now->record[i].key > *info) {
            break;
        }
    }

    if (now->record_cnt > btree_max_per_node) return v;
    
    if (l == -1 && now -> is_leaf) 
        return v;
    else if (l == -1) {
        //Index::convert_BtreeNode_to_buf(now);
        //printf("%d %d %d\n",index, now->child[i],now->record_cnt);
        return Index::queryRecord(info, now->child[i]);
    }

    for (int i = l; i <= r; i++) v.push_back(now -> record[i].record_id);

    if (now -> is_leaf) {
        return v;
    }
    else {
        for (int i = l; i <= r + 1; i++) {
            //Index::convert_BtreeNode_to_buf(now);
            std::vector<int> cv = Index::queryRecord(info, now->child[i]);
            for (uint j = 0; j < cv.size(); j++) v.push_back(cv[j]);
        }
        return v;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0xa0(%rbp)
movq %rdi, %rax
movq %rax, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x90(%rbp)
movl -0x1c(%rbp), %esi
callq 0x36fd0
movq %rax, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xd880
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x1c(%rcx), %eax
jge 0x37bf5
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x3d7a0
movq %rax, %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
callq 0xc500
movb %al, -0xa1(%rbp)
jmp 0x37b79
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x37b85
jmp 0x37bac
cmpl $-0x1, -0x44(%rbp)
jne 0x37ba4
movl -0x4c(%rbp), %eax
movl %eax, -0x44(%rbp)
jmp 0x37ba4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x37e0e
movl -0x4c(%rbp), %eax
movl %eax, -0x48(%rbp)
jmp 0x37be5
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x3d7a0
movq %rax, %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rsi
callq 0xc710
movb %al, -0xa2(%rbp)
jmp 0x37bd5
movb -0xa2(%rbp), %al
testb $0x1, %al
jne 0x37be1
jmp 0x37be3
jmp 0x37bf5
jmp 0x37be5
jmp 0x37be7
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x37b40
movq -0x90(%rbp), %rcx
movq -0x28(%rbp), %rax
movl 0x1c(%rax), %eax
cmpl 0x90(%rcx), %eax
jle 0x37c27
movq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3d7c0
movl $0x1, -0x60(%rbp)
jmp 0x37df5
cmpl $-0x1, -0x44(%rbp)
jne 0x37c53
movq -0x28(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x37c53
movq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3d7c0
movl $0x1, -0x60(%rbp)
jmp 0x37df5
cmpl $-0x1, -0x44(%rbp)
jne 0x37c9f
movq -0x18(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rdi
addq $0x20, %rdi
movslq -0x4c(%rbp), %rsi
callq 0x3d6f0
movq -0xa0(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0xb0(%rbp), %rdx
movl (%rax), %ecx
callq 0x37ae0
jmp 0x37c93
movl $0x1, -0x60(%rbp)
jmp 0x37df5
jmp 0x37ca1
movl -0x44(%rbp), %eax
movl %eax, -0x64(%rbp)
movl -0x64(%rbp), %eax
cmpl -0x48(%rbp), %eax
jg 0x37cdb
movq -0x28(%rbp), %rdi
addq $0x50, %rdi
movslq -0x64(%rbp), %rsi
callq 0x3d7a0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x3d7f0
jmp 0x37cce
jmp 0x37cd0
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x37ca7
movq -0x28(%rbp), %rax
testb $0x1, 0x68(%rax)
je 0x37d01
movq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3d7c0
movl $0x1, -0x60(%rbp)
jmp 0x37df5
movl -0x44(%rbp), %eax
movl %eax, -0x68(%rbp)
movl -0x68(%rbp), %eax
movl -0x48(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jg 0x37dde
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x20, %rdi
movslq -0x68(%rbp), %rsi
callq 0x3d6f0
movq -0x90(%rbp), %rsi
movq -0xb8(%rbp), %rdx
movl (%rax), %ecx
leaq -0x80(%rbp), %rdi
callq 0x37ae0
jmp 0x37d4f
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
movq %rax, -0xc0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x3d860
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
jae 0x37dc7
movl -0x84(%rbp), %eax
movl %eax, %esi
leaq -0x80(%rbp), %rdi
callq 0x3d6f0
movq %rax, %rsi
leaq -0x40(%rbp), %rdi
callq 0x3d7f0
jmp 0x37d9d
jmp 0x37d9f
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x37d59
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0xde10
jmp 0x37e0e
leaq -0x80(%rbp), %rdi
callq 0xde10
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x37d07
movq -0xa0(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3d7c0
movl $0x1, -0x60(%rbp)
leaq -0x40(%rbp), %rdi
callq 0xde10
movq -0x98(%rbp), %rax
addq $0xc0, %rsp
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0xde10
movq -0x58(%rbp), %rdi
callq 0x6890