// File: Konano[P]UselessDatabase/Table.cpp
// Function: Table::removeForeignKey(ForeignKey*)
int Table::removeForeignKey(ForeignKey* fk) {
    int i = 0;
    for (auto it = f_key.begin(); it != f_key.end(); it++){
        if (*it == fk) { 
            for (auto _it = fk->p->f.begin(); _it != fk->p->f.end(); _it++) if (*_it == fk) {
                removeIndex(f_key_index[i]);
                f_key_index.erase(f_key_index.begin()+i);
                f_key.erase(it);
                updateColumns();
                fk->p->f.erase(_it);
                delete fk;
                return 0;
            }
            return -1;
        }
        i ++;
    }
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x98(%rbp)
movl $0x0, -0x1c(%rbp)
addq $0x760, %rdi            # imm = 0x760
callq 0x446e0
movq %rax, -0x28(%rbp)
movq -0x98(%rbp), %rdi
addq $0x760, %rdi            # imm = 0x760
callq 0x44530
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x525a0
testb $0x1, %al
jne 0x4c5f2
jmp 0x4c7bd
leaq -0x28(%rbp), %rdi
callq 0x44ab0
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x4c79d
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
addq $0x50, %rdi
callq 0x446e0
movq %rax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rdi
addq $0x50, %rdi
callq 0x44530
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x525a0
testb $0x1, %al
jne 0x4c648
jmp 0x4c794
leaq -0x38(%rbp), %rdi
callq 0x44ab0
movq (%rax), %rax
cmpq -0x18(%rbp), %rax
jne 0x4c77b
movq -0x98(%rbp), %rdi
addq $0x780, %rdi            # imm = 0x780
movslq -0x1c(%rbp), %rsi
callq 0x3d6f0
movq -0x98(%rbp), %rdi
movl (%rax), %esi
callq 0x49120
movq -0x98(%rbp), %rdi
movq %rdi, %rax
addq $0x780, %rax            # imm = 0x780
movq %rax, -0xb8(%rbp)
addq $0x780, %rdi            # imm = 0x780
callq 0xd0f0
movq %rax, -0x58(%rbp)
movslq -0x1c(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x3de10
movq %rax, -0x50(%rbp)
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3da80
movq -0xb8(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x3da10
movq %rax, %rcx
movq -0x98(%rbp), %rax
movq %rcx, -0x60(%rbp)
addq $0x760, %rax            # imm = 0x760
movq %rax, -0xb0(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0x53420
movq -0xb0(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x533b0
movq -0x98(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0x48f70
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rax
addq $0x50, %rax
movq %rax, -0xa8(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x53420
movq -0xa8(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x533b0
movq %rax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
cmpq $0x0, %rax
je 0x4c772
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
callq *0x10(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x4c7c4
jmp 0x4c77d
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x53460
movq %rax, -0x88(%rbp)
jmp 0x4c61d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x4c7c4
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
leaq -0x28(%rbp), %rdi
xorl %esi, %esi
callq 0x53460
movq %rax, -0x90(%rbp)
jmp 0x4c5c5
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq