// File: /workspace/github_cpp_makefile_star2_O2/Konano[P]UselessDatabase/Table.cpp
// Function: Table::constraintKey(Key*)
int Table::constraintKey(Key* key) {
    Anys data, _data;
    if (key->ty() == 1) {
        std::map<Anys, bool> m;
        Pointer p(this);
        while (p.next()) {
            data = p.get();
            for (auto i: key->v) {
                if (data[i].isNull()) return -1;
                _data.push_back(data[i]);
            }
            if (m.count(_data)) return -2;
            m[_data] = true;
        }
        // for (uint record_id = 0; record_id < record_num; record_id++) {
        //     if (queryRecord(record_id, data)) continue;
        //     Anys as;
        //     for (auto i: key->v) {
        //         if (data[i].isNull()) return -1;
        //         as.push_back(data[i]);
        //     }
        //     if (m.count(as)) return -2;
        //     m[as] = true;
        // }
    } else {
        Table* p_table = dynamic_cast<ForeignKey*>(key)->p->table;
        if (p_table->index[p_table->p_key_index].fileID == -1) 
            p_table->index[p_table->p_key_index].open();
        Pointer p(this);
        while (p.next()) {
            data = p.get();
            Anys _data;
            bool null = true, non_null = true;
            for (auto i: key->v) {
                null &= data[i].isNull();
                non_null &= !data[i].isNull();
                _data.push_back(data[i]);
            }
            if (null == false && non_null == false) return -1;
            if (p_table->index[p_table->p_key_index].queryRecord(&_data).size() == 0) return -4;
        }
        // for (uint record_id = 0; record_id < record_num; record_id++) {
        //     if (queryRecord(record_id, data)) continue;
        //     Anys as;
        //     bool null = true, non_null = true;
        //     for (auto i: key->v) {
        //         null &= data[i].isNull();
        //         non_null &= !data[i].isNull();
        //         as.push_back(data[i]);
        //     }
        //     if (null == false && non_null == false) return -1;
        //     Anys _data = Anys(data, col_num);
        //     Anys val = chooseData(_data, key->v);
        //     Table* p_table = dynamic_cast<ForeignKey*>(key)->p->table;
        //     if (p_table->index[p_table->p_key_index].queryRecord(&val).size() == 0) return -4;
        // }
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
movaps %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
movq (%rsi), %rax
movq %rsi, (%rsp)
movq %rsi, %rdi
callq *(%rax)
cmpl $0x1, %eax
jne 0x1dd17
leaq 0xb0(%rsp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq 0x20(%rsp), %rbx
movq %r15, (%rbx)
orl $-0x1, 0x8(%rbx)
pushq $-0x1
popq %rbp
leaq 0x70(%rsp), %r12
leaq 0x10(%rsp), %r13
movq %rbx, %rdi
callq 0x1a98e
movl %eax, %r15d
testb %al, %al
je 0x1deff
movl %ebp, %r14d
leaq 0x90(%rsp), %rbp
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x1aa4a
leaq 0x40(%rsp), %rdi
movq %rbp, %rsi
callq 0x19190
movq %rbp, %rdi
callq 0x9268
movq (%rsp), %rax
movq 0x30(%rax), %rbx
movq 0x38(%rax), %rbp
cmpq %rbp, %rbx
je 0x1dcde
movl (%rbx), %eax
movq 0x40(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x1debd
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, 0x10(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x8ea0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1dcd8
movq (%rdi), %rax
callq *0x8(%rax)
addq $0x4, %rbx
jmp 0x1dc99
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0x211f0
leaq 0x20(%rsp), %rbx
testq %rax, %rax
jne 0x1df04
movl %r14d, %ebp
leaq 0xa8(%rsp), %rdi
movq %r12, %rsi
callq 0x2120a
movb $0x1, (%rax)
jmp 0x1dc4f
leaq 0x31f22(%rip), %rsi     # 0x4fc40
leaq 0x31f2b(%rip), %rdx     # 0x4fc50
movq (%rsp), %rdi
xorl %ecx, %ecx
callq 0x5470
movq 0x50(%rax), %rax
movq 0x48(%rax), %rbx
movslq 0x778(%rbx), %rax
imulq $0x98, %rax, %rax
cmpl $-0x1, 0x814(%rbx,%rax)
jne 0x1dd60
leaq (%rbx,%rax), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x155f8
leaq 0xa8(%rsp), %r14
movq %r15, (%r14)
orl $-0x1, 0x8(%r14)
movq %rbx, 0x68(%rsp)
leaq 0x7a0(%rbx), %rax
movq %rax, 0x60(%rsp)
leaq 0x20(%rsp), %r15
movq %r14, %rdi
callq 0x1a98e
testb %al, %al
je 0x1ded5
movl %ebp, 0x1c(%rsp)
movq %r15, %rdi
movq %r14, %rsi
callq 0x1aa4a
leaq 0x40(%rsp), %rdi
movq %r15, %rsi
callq 0x19190
movq %r15, %rdi
callq 0x9268
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq (%rsp), %rax
movq 0x30(%rax), %rbp
movq 0x38(%rax), %r14
movb $0x1, %r13b
movb $0x1, %bl
cmpq %r14, %rbp
je 0x1de31
movl (%rbp), %eax
movq 0x40(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
setne %r12b
sete %r15b
je 0x1ddff
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x1de01
xorl %eax, %eax
movq %rax, 0x8(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8ea0
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1de25
movq (%rdi), %rax
callq *0x8(%rax)
andb %r15b, %r13b
andb %r12b, %bl
addq $0x4, %rbp
jmp 0x1ddd9
orb %bl, %r13b
testb $0x1, %r13b
je 0x1de99
movq 0x68(%rsp), %rax
movslq 0x778(%rax), %rax
imulq $0x98, %rax, %rsi
addq 0x60(%rsp), %rsi
leaq 0x90(%rsp), %r12
movq %r12, %rdi
leaq 0x20(%rsp), %r15
movq %r15, %rdx
callq 0x15da2
leaq 0xa8(%rsp), %r14
movq 0x98(%rsp), %rax
cmpq 0x90(%rsp), %rax
setne %bl
movl 0x1c(%rsp), %ebp
pushq $-0x4
popq %rax
cmovel %eax, %ebp
movq %r12, %rdi
callq 0x8c8c
jmp 0x1deab
xorl %ebx, %ebx
pushq $-0x1
popq %rbp
leaq 0xa8(%rsp), %r14
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x9268
testb %bl, %bl
jne 0x1dd86
jmp 0x1ded7
movb $0x1, %r15b
movl %r14d, %ebp
leaq 0xa8(%rsp), %rdi
callq 0x21ab6
testb %r15b, %r15b
jne 0x1ded7
xorl %ebp, %ebp
leaq 0x70(%rsp), %rdi
callq 0x9268
leaq 0x40(%rsp), %rdi
callq 0x9268
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r15d, %r15d
jmp 0x1dec3
pushq $-0x2
popq %rbp
jmp 0x1dec3
jmp 0x1df15
jmp 0x1df1a
jmp 0x1df15
jmp 0x1df1a
jmp 0x1df41
jmp 0x1df15
movq %rax, %rbx
jmp 0x1df63
movq %rax, %rbx
jmp 0x1df32
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x1df32
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0xa8(%rsp), %rdi
callq 0x21ab6
jmp 0x1df63
movq %rax, %rbx
jmp 0x1df59
movq %rax, %rbx
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x1df59
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x20(%rsp), %rdi
callq 0x9268
leaq 0x70(%rsp), %rdi
callq 0x9268
leaq 0x40(%rsp), %rdi
callq 0x9268
movq %rbx, %rdi
callq 0x56f0
nop