// File: Konano[P]UselessDatabase/Table.cpp
// Function: Table::findWheres(std::vector<WhereStmt, std::allocator<WhereStmt>>&)
vector<uint> Table::findWheres(vector<WhereStmt> &where) { // preliminary search
    int mx = -1;
    WhereStmt w;
    // uint w_index;
    for (auto it: where) if (it.rvalue_ty == 1) {
        for (uint i = 0; i < index_num; i++) if (index[i].key.size() == it.cols.size()) {
            bool tmp = true;
            for (uint j = 0; j < it.cols.size(); j++) tmp &= (index[i].key[j] == it.cols[j].second);
            if (tmp) {
                Anys data;
                for (auto _it: it.rvalue) data.push_back(_it);
                int nums = index[i].queryRecordsNum(it.op, data);
                if (nums > mx) {
                    mx = nums;
                    w = it;
                    // w_index = i;
                }
            }
        }
    }

    // FIXME
    // if (mx == -1) {
        return existentRecords();
    // } else {
    //     Anys data;
    //     for (auto it: w.rvalue) data.push_back(it);
    //     return index[w_index].queryRecords(w.op, data);           
    // }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x170(%rbp)
movq %rdi, %rax
movq %rax, -0x168(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x160(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
leaq -0x80(%rbp), %rdi
callq 0x53900
movq -0x18(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0xce20
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
callq 0xce50
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0xce80
testb $0x1, %al
jne 0x4ff40
jmp 0x502d4
leaq -0x90(%rbp), %rdi
callq 0xcec0
movq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0xcee0
jmp 0x4ff5d
cmpl $0x1, -0xd8(%rbp)
jne 0x502a9
movl $0x0, -0x108(%rbp)
movq -0x160(%rbp), %rcx
movl -0x108(%rbp), %eax
cmpl 0x798(%rcx), %eax
jae 0x502a7
movq -0x160(%rbp), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movl -0x108(%rbp), %eax
imulq $0x98, %rax, %rax
addq %rax, %rdi
addq $0x30, %rdi
callq 0x3d1f0
movq %rax, -0x178(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xc8d0
movq %rax, %rcx
movq -0x178(%rbp), %rax
cmpq %rcx, %rax
jne 0x50291
movb $0x1, -0x109(%rbp)
movl $0x0, -0x110(%rbp)
movl -0x110(%rbp), %eax
movq %rax, -0x180(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0xc8d0
movq %rax, %rcx
movq -0x180(%rbp), %rax
cmpq %rcx, %rax
jae 0x500bc
movq -0x160(%rbp), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movl -0x108(%rbp), %eax
imulq $0x98, %rax, %rax
addq %rax, %rdi
addq $0x30, %rdi
movl -0x110(%rbp), %eax
movl %eax, %esi
callq 0x3cf40
movl (%rax), %eax
movl %eax, -0x184(%rbp)
leaq -0xf8(%rbp), %rdi
movl -0x110(%rbp), %eax
movl %eax, %esi
callq 0x53950
movq %rax, %rcx
movl -0x184(%rbp), %eax
cmpl 0x4(%rcx), %eax
sete %al
andb $0x1, %al
movzbl %al, %ecx
movb -0x109(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
andl %ecx, %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x109(%rbp)
movl -0x110(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x110(%rbp)
jmp 0x4ffeb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x50302
testb $0x1, -0x109(%rbp)
je 0x5028f
leaq -0x128(%rbp), %rdi
callq 0xc310
jmp 0x500d7
leaq -0xf8(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x130(%rbp)
movq -0x130(%rbp), %rdi
callq 0xc940
movq %rax, -0x138(%rbp)
movq -0x130(%rbp), %rdi
callq 0xc970
movq %rax, -0x140(%rbp)
leaq -0x138(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0xc9a0
testb $0x1, %al
jne 0x5012b
jmp 0x50209
leaq -0x138(%rbp), %rdi
callq 0xc9e0
movq %rax, %rsi
leaq -0x148(%rbp), %rdi
callq 0xca00
jmp 0x50148
leaq -0x150(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0xca00
jmp 0x5015d
leaq -0x128(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0xc330
jmp 0x50172
leaq -0x150(%rbp), %rdi
callq 0xc3c0
leaq -0x148(%rbp), %rdi
callq 0xc3c0
leaq -0x138(%rbp), %rdi
callq 0xca50
jmp 0x5010f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x502c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x50281
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
jmp 0x501fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x100(%rbp)
movl %eax, -0x104(%rbp)
leaq -0x150(%rbp), %rdi
callq 0xc3c0
leaq -0x148(%rbp), %rdi
callq 0xc3c0
jmp 0x50281
movq -0x160(%rbp), %rax
movl -0x108(%rbp), %ecx
imulq $0x98, %rcx, %rcx
leaq 0x7a0(%rax,%rcx), %rdi
movl -0xe0(%rbp), %esi
leaq -0x128(%rbp), %rdx
callq 0x3ced0
movl %eax, -0x188(%rbp)
jmp 0x5023f
movl -0x188(%rbp), %eax
movl %eax, -0x154(%rbp)
movl -0x154(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jle 0x50273
movl -0x154(%rbp), %eax
movl %eax, -0x1c(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x53970
jmp 0x50271
jmp 0x50273
leaq -0x128(%rbp), %rdi
callq 0xc430
jmp 0x5028f
leaq -0x128(%rbp), %rdi
callq 0xc430
jmp 0x502c6
jmp 0x50291
jmp 0x50293
movl -0x108(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x108(%rbp)
jmp 0x4ff74
jmp 0x502a9
leaq -0xf8(%rbp), %rdi
callq 0xcfa0
leaq -0x90(%rbp), %rdi
callq 0xcfe0
jmp 0x4ff24
leaq -0xf8(%rbp), %rdi
callq 0xcfa0
jmp 0x50302
movq -0x160(%rbp), %rsi
movq -0x170(%rbp), %rdi
callq 0x4fd70
jmp 0x502e9
leaq -0x80(%rbp), %rdi
callq 0xcfa0
movq -0x168(%rbp), %rax
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
leaq -0x80(%rbp), %rdi
callq 0xcfa0
movq -0x100(%rbp), %rdi
callq 0x6890
nopw (%rax,%rax)