// File: Konano[P]UselessDatabase/Table.cpp
// Function: Table::removeColumn(unsigned int)
int Table::removeColumn(uint col_id) {
    // if (col_ty[col_id].key == Primary) {
    //     printf("Need to remove primary key \"%s\" first.", p_key->name.c_str());
    //     return -1;
    // }
    // for (auto it: f_key) for (auto _i: it->v) if (_i == col_id) {
    //     printf("Need to remove foreign key \"%s\" first.", it->name.c_str());
    //     return -2;
    // }
    // for (uint i = 0; i < index_num; i++) for (auto _i: index[i].key) if (_i == col_id) {
    //     printf("Need to remove index \"%s\" first.", index[i].name);
    //     return -3;
    // }
    rebuild(0, col_id);
    for (uint i = col_id; i < col_num - 1; i++) col_ty[i] = col_ty[i + 1];
    col_num -= 1;

    if (p_key) {
        for (auto it = p_key->v.begin(); it != p_key->v.end(); it++) if (*it == col_id) {
            removePrimaryKey();
            break;
        } else if (*it > col_id) *it -= 1;
    }
    if (f_key.size()) for (uint i = 0; i < f_key.size(); i++) {
        for (auto it = f_key[i]->v.begin(); it != f_key[i]->v.end(); it++) if (*it == col_id) {
            removeForeignKey(f_key[i--]);
            break;
        } else if (*it > col_id) *it -= 1;
    }
    for (uint i = 0; i < index_num; i++) {
        for (auto it = index[i].key.begin(); it != index[i].key.end(); it++) if (*it == col_id) {
            removeIndex(i--);
            break;
        } else if (*it > col_id) *it -= 1;
    }
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movl -0xc(%rbp), %edx
xorl %esi, %esi
callq 0x4b890
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x70(%rbp), %rcx
movl -0x10(%rbp), %eax
movl 0x54(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jae 0x4c163
movq -0x70(%rbp), %rdi
movq %rdi, %rsi
addq $0x58, %rsi
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, %eax
imulq $0x38, %rax, %rax
addq %rax, %rsi
addq $0x58, %rdi
movl -0x10(%rbp), %eax
imulq $0x38, %rax, %rax
addq %rax, %rdi
callq 0x53220
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x4c11a
movq -0x70(%rbp), %rax
movl 0x54(%rax), %ecx
subl $0x1, %ecx
movl %ecx, 0x54(%rax)
cmpq $0x0, 0x758(%rax)
je 0x4c213
movq -0x70(%rbp), %rax
movq 0x758(%rax), %rdi
addq $0x30, %rdi
callq 0x3d210
movq %rax, -0x18(%rbp)
movq -0x70(%rbp), %rax
movq 0x758(%rax), %rdi
addq $0x30, %rdi
callq 0x3d240
movq %rax, -0x20(%rbp)
leaq -0x18(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x3d270
testb $0x1, %al
jne 0x4c1c1
jmp 0x4c211
leaq -0x18(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x4c1dc
movq -0x70(%rbp), %rdi
callq 0x4c430
jmp 0x4c211
leaq -0x18(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jbe 0x4c1fc
leaq -0x18(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %ecx
subl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4c1fe
jmp 0x4c200
leaq -0x18(%rbp), %rdi
xorl %esi, %esi
callq 0x53270
movq %rax, -0x28(%rbp)
jmp 0x4c196
jmp 0x4c213
movq -0x70(%rbp), %rdi
addq $0x760, %rdi            # imm = 0x760
callq 0x447e0
cmpq $0x0, %rax
je 0x4c33f
movl $0x0, -0x2c(%rbp)
movq -0x70(%rbp), %rdi
movl -0x2c(%rbp), %eax
movq %rax, -0x78(%rbp)
addq $0x760, %rdi            # imm = 0x760
callq 0x447e0
movq %rax, %rcx
movq -0x78(%rbp), %rax
cmpq %rcx, %rax
jae 0x4c33d
movq -0x70(%rbp), %rdi
addq $0x760, %rdi            # imm = 0x760
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x52cd0
movq (%rax), %rdi
addq $0x30, %rdi
callq 0x3d210
movq %rax, -0x38(%rbp)
movq -0x70(%rbp), %rdi
addq $0x760, %rdi            # imm = 0x760
movl -0x2c(%rbp), %eax
movl %eax, %esi
callq 0x52cd0
movq (%rax), %rdi
addq $0x30, %rdi
callq 0x3d240
movq %rax, -0x40(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x3d270
testb $0x1, %al
jne 0x4c2b8
jmp 0x4c32d
leaq -0x38(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x4c2f5
movq -0x70(%rbp), %rdi
addq $0x760, %rdi            # imm = 0x760
movl -0x2c(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x2c(%rbp)
movl %eax, %eax
movl %eax, %esi
callq 0x52cd0
movq -0x70(%rbp), %rdi
movq (%rax), %rsi
callq 0x4c590
jmp 0x4c32d
leaq -0x38(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jbe 0x4c315
leaq -0x38(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %ecx
subl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4c317
jmp 0x4c319
leaq -0x38(%rbp), %rdi
xorl %esi, %esi
callq 0x53270
movq %rax, -0x48(%rbp)
jmp 0x4c280
jmp 0x4c32f
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x4c234
jmp 0x4c33f
movl $0x0, -0x4c(%rbp)
movq -0x70(%rbp), %rcx
movl -0x4c(%rbp), %eax
cmpl 0x798(%rcx), %eax
jae 0x4c424
movq -0x70(%rbp), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movl -0x4c(%rbp), %eax
imulq $0x98, %rax, %rax
addq %rax, %rdi
addq $0x30, %rdi
callq 0x3d210
movq %rax, -0x58(%rbp)
movq -0x70(%rbp), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movl -0x4c(%rbp), %eax
imulq $0x98, %rax, %rax
addq %rax, %rdi
addq $0x30, %rdi
callq 0x3d240
movq %rax, -0x60(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x3d270
testb $0x1, %al
jne 0x4c3b6
jmp 0x4c414
leaq -0x58(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jne 0x4c3dc
movq -0x70(%rbp), %rdi
movl -0x4c(%rbp), %esi
movl %esi, %eax
addl $-0x1, %eax
movl %eax, -0x4c(%rbp)
callq 0x49120
jmp 0x4c414
leaq -0x58(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jbe 0x4c3fc
leaq -0x58(%rbp), %rdi
callq 0x3d2b0
movl (%rax), %ecx
subl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x4c3fe
jmp 0x4c400
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
callq 0x53270
movq %rax, -0x68(%rbp)
jmp 0x4c37e
jmp 0x4c416
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x4c346
xorl %eax, %eax
addq $0x80, %rsp
popq %rbp
retq
nop