// File: /workspace/github_cpp_makefile_star2_O3/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 $0xe8, %rsp
movq %rdi, %r15
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0xc0(%rsp)
movaps %xmm0, 0xb0(%rsp)
movq (%rsi), %rax
movq %rsi, 0x18(%rsp)
movq %rsi, %rdi
callq *(%rax)
cmpl $0x1, %eax
jne 0x23eff
leaq 0x58(%rsp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x30(%rsp), %rdi
movq %r15, (%rdi)
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
leaq 0x80(%rsp), %rbx
leaq 0x50(%rsp), %r14
leaq 0xb0(%rsp), %rbp
leaq 0x28(%rsp), %r12
movq %rdi, %r13
callq 0x1f964
testb %al, %al
je 0x24119
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1fa4c
movq 0x10(%rsp), %rax
movaps 0x80(%rsp), %xmm0
movq 0x90(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movaps (%rsp), %xmm1
movaps %xmm0, (%rsp)
movaps %xmm1, 0xd0(%rsp)
movq %rax, 0xe0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x80(%rsp)
movq $0x0, 0x90(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xa37e
movq %rbx, %rdi
callq 0xa37e
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rbx
movq 0x38(%rax), %r15
cmpq %r15, %rbx
je 0x23ec8
movl (%rbx), %eax
movq (%rsp), %rcx
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x240f7
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, 0x28(%rsp)
movq %rbp, %rdi
movq %r12, %rsi
callq 0x9f9a
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x23ec2
movq (%rdi), %rax
callq *0x8(%rax)
addq $0x4, %rbx
jmp 0x23e84
movq %r14, %rdi
movq %rbp, %rsi
callq 0x28c12
leaq 0x80(%rsp), %rbx
leaq 0x58(%rsp), %rcx
cmpq %rcx, %rax
jne 0x2414e
movq %r14, %rdi
movq %rbp, %rsi
callq 0x2820a
movb $0x1, (%rax)
movq %r13, %rdi
jmp 0x23dfe
leaq 0x2ec6a(%rip), %rsi     # 0x52b70
leaq 0x2ec73(%rip), %rdx     # 0x52b80
movq 0x18(%rsp), %rdi
xorl %ecx, %ecx
callq 0x5430
movq 0x50(%rax), %rax
movq 0x48(%rax), %r12
movslq 0x778(%r12), %rax
imulq $0x98, %rax, %rax
cmpl $-0x1, 0x814(%r12,%rax)
jne 0x23f4b
leaq (%r12,%rax), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x19088
leaq 0x7a0(%r12), %rax
movq %rax, 0xa0(%rsp)
leaq 0xd0(%rsp), %r13
movq %r15, (%r13)
movl $0xffffffff, 0x8(%r13)  # imm = 0xFFFFFFFF
leaq 0x30(%rsp), %r15
movq %r12, 0x98(%rsp)
movq %r13, %rdi
callq 0x1f964
testb %al, %al
je 0x24123
movq %r15, %rdi
movq %r13, %rsi
callq 0x1fa4c
movq 0x10(%rsp), %rax
movaps 0x30(%rsp), %xmm0
movq 0x40(%rsp), %rcx
movq %rcx, 0x10(%rsp)
movaps (%rsp), %xmm1
movaps %xmm0, (%rsp)
movaps %xmm1, 0x50(%rsp)
movq %rax, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x40(%rsp)
leaq 0x50(%rsp), %rdi
callq 0xa37e
movq %r15, %rdi
callq 0xa37e
movq %rbx, 0x60(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq 0x18(%rsp), %rax
movq 0x30(%rax), %r14
movq 0x38(%rax), %rax
movq %rax, 0xa8(%rsp)
cmpq %rax, %r14
je 0x2409a
movb $0x1, %r15b
movb $0x1, %r13b
movl %r13d, %ebx
movl %r15d, %r12d
movl (%r14), %eax
movq (%rsp), %rcx
movq (%rcx,%rax,8), %rbp
testq %rbp, %rbp
setne %r15b
sete %r13b
je 0x24039
movq (%rbp), %rax
movq %rbp, %rdi
callq *0x10(%rax)
jmp 0x2403b
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x9f9a
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x2405f
movq (%rdi), %rax
callq *0x8(%rax)
andb %bl, %r13b
andb %r12b, %r15b
addq $0x4, %r14
cmpq 0xa8(%rsp), %r14
jne 0x2400f
testq %rbp, %rbp
movzbl %bl, %eax
movzbl %r12b, %ecx
cmovel %eax, %ecx
testb $0x1, %cl
movq 0x98(%rsp), %r12
leaq 0xd0(%rsp), %r13
leaq 0x30(%rsp), %r15
je 0x24108
movslq 0x778(%r12), %rax
imulq $0x98, %rax, %rsi
addq 0xa0(%rsp), %rsi
movq %r15, %rdi
leaq 0x50(%rsp), %rdx
callq 0x19a30
movq 0x30(%rsp), %rbp
movq 0x38(%rsp), %rbx
testq %rbp, %rbp
je 0x240dd
movq 0x40(%rsp), %rsi
subq %rbp, %rsi
movq %rbp, %rdi
callq 0x53a0
leaq 0x50(%rsp), %rdi
callq 0xa37e
cmpq %rbp, %rbx
jne 0x23f7c
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
jmp 0x24125
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
leaq 0x50(%rsp), %rdi
callq 0x288ec
jmp 0x24125
leaq 0x50(%rsp), %rdi
callq 0xa37e
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jmp 0x24125
leaq 0x50(%rsp), %rdi
callq 0x288ec
xorl %ebx, %ebx
leaq 0xb0(%rsp), %rdi
callq 0xa37e
movq %rsp, %rdi
callq 0xa37e
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
jmp 0x240fc
jmp 0x24161
jmp 0x24161
jmp 0x2417b
jmp 0x2417b
jmp 0x2418a
jmp 0x24161
movq %rax, %rbx
jmp 0x241ac
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2417e
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x2417e
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x288ec
jmp 0x241ac
movq %rax, %rbx
jmp 0x241a2
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x241a2
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x50(%rsp), %rdi
callq 0xa37e
leaq 0xb0(%rsp), %rdi
callq 0xa37e
movq %rsp, %rdi
callq 0xa37e
movq %rbx, %rdi
callq 0x56e0
nop