// File: /workspace/github_cpp_makefile_star2_O1/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, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movq %rax, 0xe0(%rsp)
movaps %xmm0, 0xd0(%rsp)
movq (%rsi), %rax
movq %rsi, 0x28(%rsp)
movq %rsi, %rdi
callq *(%rax)
cmpl $0x1, %eax
jne 0x244c9
leaq 0x68(%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 0x48(%rsp), %rdi
movq %r15, (%rdi)
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
leaq 0xb8(%rsp), %rbx
leaq 0x60(%rsp), %r15
leaq 0xd0(%rsp), %r12
leaq 0x38(%rsp), %r13
movq %rdi, %r14
callq 0x20038
movb %al, 0x8(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpb $0x0, 0x8(%rsp)
je 0x246f8
movq %rbx, %rdi
movq %r14, %rsi
callq 0x20100
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movaps 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rax
movups 0xb8(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0xc8(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movaps 0x90(%rsp), %xmm1
movaps %xmm0, 0x90(%rsp)
movq %rax, 0xa0(%rsp)
movups %xmm1, 0xb8(%rsp)
movq $0x0, 0xc8(%rsp)
leaq 0x90(%rsp), %rdi
callq 0xa564
movq %rbx, %rdi
callq 0xa564
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rbx
movq 0x38(%rax), %rbp
cmpq %rbp, %rbx
je 0x24492
movl (%rbx), %eax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %rdi
testq %rdi, %rdi
je 0x246f3
movq (%rdi), %rax
callq *0x10(%rax)
movq %rax, 0x38(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xa1bc
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x2448c
movq (%rdi), %rax
callq *0x8(%rax)
addq $0x4, %rbx
jmp 0x2444d
movq %r15, %rdi
movq %r12, %rsi
callq 0x29362
leaq 0xb8(%rsp), %rbx
leaq 0x68(%rsp), %rcx
cmpq %rcx, %rax
jne 0x24736
movq %r15, %rdi
movq %r12, %rsi
callq 0x28924
movb $0x1, (%rax)
movq %r14, %rdi
jmp 0x243a9
leaq 0x2f6a0(%rip), %rsi     # 0x53b70
leaq 0x2f6a9(%rip), %rdx     # 0x53b80
movq 0x28(%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 0x24515
leaq (%r12,%rax), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x19846
leaq 0x7a0(%r12), %rax
movq %rax, 0xb0(%rsp)
leaq 0x90(%rsp), %r13
movq %r15, (%r13)
movl $0xffffffff, 0x8(%r13)  # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %r14
movq %r12, 0xa8(%rsp)
movq %r13, %rdi
callq 0x20038
testb %al, %al
movb %al, 0x7(%rsp)
je 0x246ea
movq %r14, %rdi
movq %r13, %rsi
callq 0x20100
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movaps 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rax
movups 0x48(%rsp), %xmm1
movaps %xmm1, 0x10(%rsp)
movq 0x58(%rsp), %rcx
movq %rcx, 0x20(%rsp)
movaps 0x60(%rsp), %xmm1
movaps %xmm0, 0x60(%rsp)
movq %rax, 0x70(%rsp)
movups %xmm1, 0x48(%rsp)
xorl %ebx, %ebx
movq %rbx, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
callq 0xa564
movq %r14, %rdi
callq 0xa564
movq %rbx, 0x70(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movq 0x28(%rsp), %rax
movq 0x30(%rax), %rbx
movq 0x38(%rax), %rax
movq %rax, 0x8(%rsp)
cmpq %rax, %rbx
je 0x24676
movl %ebp, 0x44(%rsp)
movb $0x1, %r14b
movb $0x1, %r13b
movl %r13d, %ebp
movl %r14d, %r12d
movl (%rbx), %eax
movq 0x10(%rsp), %rcx
movq (%rcx,%rax,8), %r15
testq %r15, %r15
setne %r14b
sete %r13b
je 0x24613
movq (%r15), %rax
movq %r15, %rdi
callq *0x10(%rax)
jmp 0x24615
xorl %eax, %eax
movq %rax, 0x30(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x30(%rsp), %rsi
callq 0xa1bc
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x24639
movq (%rdi), %rax
callq *0x8(%rax)
andb %bpl, %r13b
andb %r12b, %r14b
addq $0x4, %rbx
cmpq 0x8(%rsp), %rbx
jne 0x245ea
testq %r15, %r15
movzbl %bpl, %eax
movzbl %r12b, %ecx
cmovel %eax, %ecx
testb $0x1, %cl
movl 0x44(%rsp), %ebp
movq 0xa8(%rsp), %r12
leaq 0x90(%rsp), %r13
leaq 0x48(%rsp), %r14
je 0x246d1
movslq 0x778(%r12), %rax
imulq $0x98, %rax, %rsi
addq 0xb0(%rsp), %rsi
movq %r14, %rdi
leaq 0x60(%rsp), %rdx
callq 0x1a1fe
movq 0x48(%rsp), %r15
movq 0x50(%rsp), %r14
cmpq %r15, %r14
setne %bl
testq %r15, %r15
je 0x246bf
movq 0x58(%rsp), %rsi
subq %r15, %rsi
movq %r15, %rdi
callq 0x53a0
cmpq %r15, %r14
movl $0xfffffffc, %eax       # imm = 0xFFFFFFFC
cmovel %eax, %ebp
leaq 0x48(%rsp), %r14
jmp 0x246d8
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %ebx, %ebx
leaq 0x60(%rsp), %rdi
callq 0xa564
testb %bl, %bl
jne 0x24546
cmpb $0x0, 0x7(%rsp)
je 0x24709
jmp 0x2470b
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
leaq 0x60(%rsp), %rdi
callq 0x2903c
cmpb $0x0, 0x8(%rsp)
jne 0x2470b
xorl %ebp, %ebp
leaq 0xd0(%rsp), %rdi
callq 0xa564
leaq 0x10(%rsp), %rdi
callq 0xa564
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xfffffffe, %ebp       # imm = 0xFFFFFFFE
jmp 0x246f8
jmp 0x24749
jmp 0x24749
jmp 0x2474e
jmp 0x2474e
jmp 0x24772
jmp 0x24749
movq %rax, %rbx
jmp 0x24794
movq %rax, %rbx
jmp 0x24766
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x24766
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x60(%rsp), %rdi
callq 0x2903c
jmp 0x24794
movq %rax, %rbx
jmp 0x2478a
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2478a
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x60(%rsp), %rdi
callq 0xa564
leaq 0xd0(%rsp), %rdi
callq 0xa564
leaq 0x10(%rsp), %rdi
callq 0xa564
movq %rbx, %rdi
callq 0x56e0
nop