// File: /workspace/github_cpp_makefile_star2_O1/Konano[P]UselessDatabase/Table.cpp
// Function: Table::createForeignKey(ForeignKey*, PrimaryKey*)
int Table::createForeignKey(ForeignKey* fk, PrimaryKey* pk) {
    if (*pk->table->p_key != *pk) return -1;
    fk->p = pk->table->p_key;
    if (fk->size() != pk->size()) return -3;
    for (uint i = 0; i < fk->size(); i++) {
        if (col_ty[fk->v[i]].ty == CHAR || col_ty[fk->v[i]].ty == VARCHAR) {
            if (pk->table->col_ty[pk->v[i]].ty != CHAR && pk->table->col_ty[pk->v[i]].ty != VARCHAR) return -5;
        }
        else if (col_ty[fk->v[i]].ty != pk->table->col_ty[pk->v[i]].ty) return -5;
    }
    if (constraintKey(fk)) return -2;
    
    ForeignKey* f_keyx = new ForeignKey(this);
    f_keyx->v_size = fk->v_size;
    f_keyx->name = fk->name;
    f_keyx->v.clear();
    for (auto i: fk->v)f_keyx->v.push_back(i);
    f_keyx->table = fk->table;
    f_keyx->p = pk->table->p_key;
    f_key.push_back(f_keyx);
    updateColumns();

    string name = std::string("fk_") + std::string(f_keyx->name) + std::to_string(f_key.size());
    f_key_index.push_back(createIndex(f_keyx->v, name));

    pk->table->p_key->f.push_back(f_keyx);

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
movq 0x48(%rdx), %rax
movq 0x758(%rax), %rdi
movq %rdx, %rsi
callq 0x288a6
movl %eax, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb %cl, %cl
jne 0x24d78
movq 0x48(%rbx), %rcx
movq 0x758(%rcx), %rax
movq %rax, 0x50(%r15)
movl 0x8(%r15), %edx
movl $0xfffffffd, %eax       # imm = 0xFFFFFFFD
cmpl 0x8(%rbx), %edx
jne 0x24d78
testq %rdx, %rdx
setne %sil
je 0x248a7
leaq 0x58(%r14), %rax
movq 0x30(%r15), %rdi
addq $0x58, %rcx
movq %rdx, %r8
negq %r8
movl $0x1, %r9d
movl -0x4(%rdi,%r9,4), %r10d
imulq $0x38, %r10, %r10
movl 0x24(%rax,%r10), %r10d
leal -0x1(%r10), %r11d
cmpl $0x1, %r11d
ja 0x2486b
movq 0x30(%rbx), %r10
movl -0x4(%r10,%r9,4), %r10d
imulq $0x38, %r10, %r10
movl 0x24(%rcx,%r10), %r10d
decl %r10d
cmpl $0x2, %r10d
jb 0x2487f
jmp 0x24898
movq 0x30(%rbx), %r11
movl -0x4(%r11,%r9,4), %r11d
imulq $0x38, %r11, %r11
cmpl 0x24(%rcx,%r11), %r10d
jne 0x24898
cmpq %rdx, %r9
setb %sil
leaq (%r8,%r9), %r10
incq %r10
incq %r9
cmpq $0x1, %r10
jne 0x24836
jmp 0x248a7
movl $0xfffffffb, %eax       # imm = 0xFFFFFFFB
testb $0x1, %sil
jne 0x24d78
movq %r14, %rdi
movq %r15, %rsi
callq 0x2431a
movl %eax, %ecx
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
testl %ecx, %ecx
jne 0x24d78
movl $0x58, %edi
callq 0x5390
movl $0x0, 0x8(%rax)
leaq 0x10(%rax), %rdi
leaq 0x20(%rax), %rcx
movq %rcx, 0x10(%rax)
xorl %ecx, %ecx
movq %rcx, 0x18(%rax)
movb $0x0, 0x20(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x30(%rax)
movq %rcx, 0x40(%rax)
movq %r14, 0x48(%rax)
leaq 0x2f25a(%rip), %rcx     # 0x53b58
movq %rcx, (%rax)
movq %rax, 0x8(%rsp)
movl 0x8(%r15), %ecx
movl %ecx, 0x8(%rax)
leaq 0x10(%r15), %rsi
callq 0x5230
movq 0x8(%rsp), %rax
movq 0x30(%rax), %rcx
cmpq %rcx, 0x38(%rax)
je 0x24929
movq %rcx, 0x38(%rax)
movq 0x30(%r15), %r13
movq 0x38(%r15), %rbp
cmpq %rbp, %r13
je 0x24973
leaq 0x30(%rsp), %r12
movl (%r13), %eax
movl %eax, 0x30(%rsp)
movq 0x8(%rsp), %rdi
movq 0x38(%rdi), %rsi
cmpq 0x40(%rdi), %rsi
je 0x2495e
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rdi)
jmp 0x2496a
addq $0x30, %rdi
movq %r12, %rdx
callq 0x1d780
addq $0x4, %r13
cmpq %rbp, %r13
jne 0x2493b
movq 0x48(%r15), %rcx
movq 0x8(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x48(%rbx), %rcx
movq 0x758(%rcx), %rcx
movq %rcx, 0x50(%rax)
movq 0x768(%r14), %rsi
cmpq 0x770(%r14), %rsi
je 0x249ac
movq %rax, (%rsi)
addq $0x8, 0x768(%r14)
jmp 0x249bd
leaq 0x760(%r14), %rdi
leaq 0x8(%rsp), %rdx
callq 0x29286
movq %r14, %rdi
callq 0x218a4
leaq 0xa0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x1d249(%rip), %rsi     # 0x41c22
leaq 0x1d245(%rip), %rdx     # 0x41c25
leaq 0x90(%rsp), %rdi
callq 0xaccc
movq 0x8(%rsp), %rax
leaq 0x80(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0x10(%rax), %rsi
movq 0x18(%rax), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0xa88e
movq 0x90(%rsp), %rcx
movq 0x98(%rsp), %r8
movq 0x78(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r12, %rcx
je 0x24a3e
movq 0xa0(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x24a5c
movl $0xf, %esi
cmpq %r13, 0x70(%rsp)
je 0x24a57
movq 0x80(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x24a70
movq 0x70(%rsp), %rsi
leaq 0x90(%rsp), %rdi
callq 0x5160
jmp 0x24a7e
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5420
leaq 0x20(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x24aa2
movq %rsi, 0x10(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x20(%rsp)
jmp 0x24aa8
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x18(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x768(%r14), %r15
subq 0x760(%r14), %r15
sarq $0x3, %r15
movl $0x1, %esi
cmpq $0xa, %r15
jb 0x24b31
movl $0x4, %esi
movabsq $0x346dc5d63886594b, %rdi # imm = 0x346DC5D63886594B
movq %r15, %rcx
cmpq $0x63, %rcx
jbe 0x24b2a
cmpq $0x3e7, %rcx            # imm = 0x3E7
jbe 0x24b2f
cmpq $0x2710, %rcx           # imm = 0x2710
jb 0x24b31
movq %rcx, %rax
mulq %rdi
shrq $0xb, %rdx
addl $0x4, %esi
cmpq $0x1869f, %rcx          # imm = 0x1869F
movq %rdx, %rcx
ja 0x24af4
addl $-0x3, %esi
jmp 0x24b31
addl $-0x2, %esi
jmp 0x24b31
decl %esi
movl %esi, %esi
leaq 0x60(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x50(%rsp), %rdi
xorl %edx, %edx
callq 0x5460
movq 0x50(%rsp), %rdi
movl 0x58(%rsp), %esi
movq %r15, %rdx
callq 0xc683
leaq 0x20(%rsp), %r15
movq -0x10(%r15), %rcx
movq -0x8(%r15), %r8
movq 0x58(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %esi
cmpq %r15, %rcx
je 0x24b7e
movq 0x20(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x24b99
movl $0xf, %esi
cmpq %rbp, 0x50(%rsp)
je 0x24b94
movq 0x60(%rsp), %rsi
cmpq %rsi, %rax
jbe 0x24baa
movq 0x50(%rsp), %rsi
leaq 0x10(%rsp), %rdi
callq 0x5160
jmp 0x24bb8
leaq 0x50(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5420
leaq 0x40(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0x24bdc
movq %rsi, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x24be2
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x38(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x24c16
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0x10(%rsp), %rdi
cmpq %r15, %rdi
je 0x24c2d
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x24c47
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0x90(%rsp), %rdi
cmpq %r12, %rdi
je 0x24c64
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0x8(%rsp), %rsi
addq $0x30, %rsi
leaq 0xb0(%rsp), %rdi
callq 0x1cc60
leaq 0xd8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc8(%rsp), %rdi
callq 0xa88e
leaq 0xb0(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
movq %r14, %rdi
callq 0x21a1e
movl %eax, 0x10(%rsp)
movq 0x788(%r14), %rsi
cmpq 0x790(%r14), %rsi
je 0x24cdb
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x788(%r14)
jmp 0x24cef
addq $0x780, %r14            # imm = 0x780
leaq 0x10(%rsp), %rdx
movq %r14, %rdi
callq 0x1d2b4
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x24d0c
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x24d29
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
movq 0x48(%rbx), %rax
movq 0x758(%rax), %rdi
movq 0x58(%rdi), %rsi
cmpq 0x60(%rdi), %rsi
je 0x24d4d
movq 0x8(%rsp), %rax
movq %rax, (%rsi)
addq $0x8, 0x58(%rdi)
jmp 0x24d5b
addq $0x50, %rdi
leaq 0x8(%rsp), %rdx
callq 0x29286
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24d76
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x53a0
xorl %eax, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x24d94
movq %rax, %rbx
jmp 0x24e36
movq %rax, %rbx
jmp 0x24e53
movq %rax, %rbx
movq 0x50(%rsp), %rdi
cmpq %rbp, %rdi
je 0x24dbb
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x53a0
jmp 0x24dbb
movq %rax, %rbx
leaq 0x20(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24ddb
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x53a0
jmp 0x24ddb
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x24dfa
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x53a0
jmp 0x24dfa
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %r12, %rdi
je 0x24e6e
movq 0xa0(%rsp), %rsi
jmp 0x24e66
movq %rax, %rbx
jmp 0x24e6e
movq %rax, %rbx
movq 0xc8(%rsp), %rdi
cmpq %r15, %rdi
je 0x24e36
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x53a0
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x24e53
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
leaq 0x40(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x24e6e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x53a0
movq %rbx, %rdi
callq 0x56e0