// File: /workspace/github_cpp_makefile_star2_O2/Konano[P]UselessDatabase/Table.cpp
// Function: Table::removeRecord(int)
int Table::removeRecord(const int record_id) {
    int index;
    BufType buf = bpm->getPage(main_file, record_id / record_onepg, index);
    if (exist(buf, record_id % record_onepg)) {
        Any* data;
        queryRecord(record_id, data);
        for (uint i = 0; i < index_num; i++) {
            Anys temp;
            for (uint j = 0; j < this->index[i].key_num; j++) {
                temp.push_back(data[this->index[i].key[j]]);
            }
            this->index[i].removeRecord(&temp, record_id);
            if (i == (uint)p_key_index) {
                for (auto _k: p_key->f) {
                    for(uint jx = 0;jx < _k->table->f_key.size();jx ++){
                        if(_k->table->f_key[jx]->p->table == this){
                            std::vector <int> ans;
                            if(_k->table->index[_k->table->f_key_index[jx]].fileID == -1){
                                _k->table->index[_k->table->f_key_index[jx]].open();
                                ans = _k->table->index[_k->table->f_key_index[jx]].queryRecord(&temp);
                                _k->table->index[_k->table->f_key_index[jx]].close();
                            }
                            else {
                                ans = _k->table->index[_k->table->f_key_index[jx]].queryRecord(&temp);
                            }
                            for(uint k = 0;k < ans.size();k ++){
                                if(_k->table->index[_k->table->f_key_index[jx]].fileID == -1){
                                    _k->table->index[_k->table->f_key_index[jx]].open();
                                    _k->table->index[_k->table->f_key_index[jx]].removeRecord(&temp,ans[k]);
                                    Anys nullkey;
                                    for(uint m = 0;m < temp.size();m ++)nullkey.push_back(Any());
                                    _k->table->index[_k->table->f_key_index[jx]].insertRecord(&nullkey,ans[k]);
                                    _k->table->index[_k->table->f_key_index[jx]].close();
                                }
                                else {
                                    _k->table->index[_k->table->f_key_index[jx]].removeRecord(&temp,ans[k]);
                                    Anys nullkey;
                                    for(uint m = 0;m < temp.size();m ++)nullkey.push_back(Any());
                                    _k->table->index[_k->table->f_key_index[jx]].insertRecord(&nullkey,ans[k]);
                                }
                                Anys pre = _k->table->queryRecord(ans[k]);
                                Anys after;
                                vector<bool> mark;
                                for(uint m = 0;m < pre.size();m ++)mark.push_back(true);
                                for(uint m = 0;m < _k->table->f_key[jx]->v.size();m ++)mark[_k->table->f_key[jx]->v[m]] = false;
                                for(uint m = 0;m < pre.size();m ++){
                                    if(mark[m]) after.push_back(pre[m]);
                                    else after.push_back(Any());
                                }
                                int index;
                                BufType buf = bpm->getPage(_k->table->main_file, ans[k] / _k->table->record_onepg, index);
                                buf += (_k->table->record_onepg - 1) / 8 + 1;
                                buf += _k->table->record_size * (ans[k] % _k->table->record_onepg);
                                for (uint q = 0; q < _k->table->col_num; q++) {
                                    insert(after[q], _k->table->col_ty[q].ty, _k->table->col_ty[q].size(), buf);
                                }
                                bpm->markDirty(index);
                            }
                        }
                    }
                }
            }
        }
        
        exist_reset(buf, record_id % record_onepg);
        bpm->markDirty(index);
        return 0;
    }
    return -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %esi, %ebx
movq %rdi, %r13
movq 0x48(%rdi), %rdi
movl 0x9fa4(%r13), %esi
movl %ebx, %eax
xorl %edx, %edx
divl 0x9fac(%r13)
leaq 0x9c(%rsp), %rcx
movl %eax, %edx
callq 0x5d50
movq %rax, %rsi
movl %ebx, %eax
xorl %edx, %edx
divl 0x9fac(%r13)
movl %edx, %eax
shrl $0x3, %eax
movq %rsi, 0xf8(%rsp)
movzbl (%rsi,%rax), %eax
andl $0x7, %edx
btl %edx, %eax
jae 0x1ca27
leaq 0x120(%rsp), %rdx
movq %r13, %rdi
movl %ebx, 0x24(%rsp)
movl %ebx, %esi
callq 0x1cb54
leaq 0x7a0(%r13), %rax
movq %rax, 0x100(%rsp)
xorl %ebx, %ebx
leaq 0xa0(%rsp), %r12
movl 0x798(%r13), %eax
cmpq %rax, %rbx
jae 0x1ca3e
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
andq $0x0, 0x60(%rsp)
movq %rbx, 0x70(%rsp)
imulq $0x98, %rbx, %rbp
addq 0x100(%rsp), %rbp
movq 0x120(%rsp), %r14
xorl %r15d, %r15d
leaq 0x90(%rsp), %rbx
movl 0x28(%rbp), %eax
cmpq %rax, %r15
jae 0x1c3de
movq 0x30(%rbp), %rax
movl (%rax,%r15,4), %eax
movq (%r14,%rax,8), %rdi
testq %rdi, %rdi
je 0x1c3af
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x1c3b1
xorl %eax, %eax
movq %rax, 0x90(%rsp)
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
callq 0x8ea0
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1c3d9
movq (%rdi), %rax
callq *0x8(%rax)
incq %r15
jmp 0x1c38e
movq %rbp, %rdi
leaq 0x50(%rsp), %rsi
movl 0x24(%rsp), %edx
callq 0x168cc
movl 0x778(%r13), %eax
movq 0x70(%rsp), %rbx
cmpq %rax, %rbx
leaq 0x28(%rsp), %r14
pushq $0x1
popq %rbp
leaq 0xe0(%rsp), %r15
jne 0x1ca15
movq 0x758(%r13), %rax
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rax
movq %rax, 0x108(%rsp)
movq 0x70(%rsp), %rbx
cmpq 0x108(%rsp), %rcx
je 0x1ca15
movq %rcx, 0x110(%rsp)
movq (%rcx), %rax
movq %rax, 0x18(%rsp)
xorl %edi, %edi
movl %edi, %edi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x760(%rax), %rcx
movq 0x768(%rax), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rdi, %rdx
jbe 0x1ca04
movq (%rcx,%rdi,8), %rcx
movq 0x50(%rcx), %rcx
cmpq %r13, 0x48(%rcx)
jne 0x1c9fd
andq $0x0, 0x40(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
leaq 0x7a0(%rax), %rsi
movq 0x780(%rax), %rcx
movq %rdi, 0x8(%rsp)
movslq (%rcx,%rdi,4), %rcx
imulq $0x98, %rcx, %rcx
cmpl $-0x1, 0x814(%rax,%rcx)
je 0x1c4eb
addq %rcx, %rsi
movq %r12, %rdi
leaq 0x50(%rsp), %rdx
callq 0x15da2
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x21d54
movq %r12, %rdi
callq 0x8c8c
jmp 0x1c56e
addq %rcx, %rsi
movq %rsi, %rdi
callq 0x155f8
movq 0x18(%rsp), %rbx
movq 0x48(%rbx), %rax
movq 0x780(%rax), %rcx
movq 0x8(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rsi
addq $0x7a0, %rsi            # imm = 0x7A0
movq %r12, %rdi
leaq 0x50(%rsp), %rdx
callq 0x15da2
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x21d54
movq %r12, %rdi
callq 0x8c8c
movq 0x48(%rbx), %rax
movq 0x780(%rax), %rcx
movq 0x8(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x15638
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x1c9ee
movq %rbx, 0x10(%rsp)
movq 0x18(%rsp), %rcx
movq 0x48(%rcx), %rcx
movq 0x780(%rcx), %rdx
movq 0x8(%rsp), %rsi
movslq (%rdx,%rsi,4), %rdx
imulq $0x98, %rdx, %rdx
leaq (%rcx,%rdx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
cmpl $-0x1, 0x74(%rdi)
je 0x1c675
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x50(%rsp), %rsi
callq 0x168cc
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
andq $0x0, 0xb0(%rsp)
xorl %ebx, %ebx
movq 0x18(%rsp), %r14
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebx
jae 0x1c635
andq $0x0, 0x88(%rsp)
movq %r12, %rdi
leaq 0x88(%rsp), %rsi
callq 0x8ea0
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x1c631
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebx
jmp 0x1c5f3
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x8(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq %r12, %rsi
callq 0x16790
jmp 0x1c76f
callq 0x155f8
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movq 0x780(%rax), %rcx
movq 0x8(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x50(%rsp), %rsi
callq 0x168cc
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
andq $0x0, 0xb0(%rsp)
xorl %ebx, %ebx
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebx
jae 0x1c709
andq $0x0, 0x28(%rsp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x8ea0
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x1c705
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebx
jmp 0x1c6d2
movq 0x18(%rsp), %r14
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x8(%rsp), %rbx
movslq (%rcx,%rbx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq %r12, %rsi
callq 0x16790
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movslq (%rcx,%rbx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x15638
movq %r12, %rdi
callq 0x9268
movq 0x48(%r14), %rsi
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0xc8(%rsp), %rdi
callq 0x1cc4e
andq $0x0, 0xf0(%rsp)
andq $0x0, 0xa0(%rsp)
andl $0x0, 0xa8(%rsp)
andq $0x0, 0xb0(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0xe0(%rsp)
andl $0x0, 0xb8(%rsp)
andq $0x0, 0xc0(%rsp)
xorl %ebx, %ebx
movq 0xd0(%rsp), %rax
subq 0xc8(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebx
jae 0x1c7fc
movq %r12, %rdi
movl %ebp, %esi
callq 0x10498
incl %ebx
jmp 0x1c7d6
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0x48(%r14), %rax
movq 0x760(%rax), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x30(%rcx), %rax
movq 0x38(%rcx), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
cmpq %rbx, %rcx
jbe 0x1c83d
movl (%rax,%rbx,4), %esi
movq %r12, %rdi
callq 0x20f52
notq %rdx
andq %rdx, (%rax)
incl %ebx
jmp 0x1c7fe
xorl %ebp, %ebp
leaq 0x78(%rsp), %rbx
movq 0xd0(%rsp), %rax
subq 0xc8(%rsp), %rax
shrq $0x3, %rax
movl %eax, %eax
cmpq %rax, %rbp
jae 0x1c8d5
movq %r12, %rdi
movq %rbp, %rsi
callq 0x20f52
testq %rdx, (%rax)
je 0x1c888
movq 0xc8(%rsp), %rax
movq (%rax,%rbp,8), %rdi
testq %rdi, %rdi
je 0x1c8a0
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x1c8a2
andq $0x0, 0x78(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x8ea0
movq 0x78(%rsp), %rdi
jmp 0x1c8c2
xorl %eax, %eax
movq %rax, 0x80(%rsp)
movq %r15, %rdi
leaq 0x80(%rsp), %rsi
callq 0x8ea0
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1c8cd
movq (%rdi), %rax
callq *0x8(%rax)
incq %rbp
jmp 0x1c844
movq 0x48(%r13), %rdi
movq 0x48(%r14), %rcx
movl 0x9fa4(%rcx), %esi
movq 0x30(%rsp), %rax
movq 0x10(%rsp), %rbx
movl (%rax,%rbx,4), %eax
xorl %edx, %edx
divl 0x9fac(%rcx)
movl %eax, %edx
leaq 0x98(%rsp), %rcx
callq 0x5d50
movq %rax, %rcx
movq %r13, %r12
movq 0x48(%r14), %rdi
movl 0x9fac(%rdi), %esi
leal -0x1(%rsi), %eax
shrl $0x3, %eax
addq %rax, %rcx
movq 0x30(%rsp), %rax
movl (%rax,%rbx,4), %eax
xorl %edx, %edx
divl %esi
imull 0x9fa8(%rdi), %edx
leaq (%rdx,%rcx), %rax
incq %rax
movq %rax, 0x118(%rsp)
pushq $0x58
popq %rbx
xorl %r15d, %r15d
xorl %r13d, %r13d
movl 0x54(%rdi), %eax
cmpq %rax, %r13
jae 0x1c999
movq 0xe0(%rsp), %rbp
addq %r15, %rbp
movl 0x24(%rdi,%rbx), %r14d
addq %rbx, %rdi
callq 0x17ffa
movq %r12, %rdi
movq %rbp, %rsi
movl %r14d, %edx
movl %eax, %ecx
leaq 0x118(%rsp), %r8
callq 0x1bed4
incq %r13
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rdi
addq $0x8, %r15
addq $0x38, %rbx
jmp 0x1c94b
movq %r12, %r13
movq 0x48(%r12), %rdi
movl 0x98(%rsp), %esi
callq 0x5e0a
movq 0x10(%rsp), %rbx
leaq 0xa0(%rsp), %r12
movq %r12, %rdi
callq 0x104d6
leaq 0xe0(%rsp), %r15
movq %r15, %rdi
callq 0x9268
leaq 0xc8(%rsp), %rdi
callq 0x9268
incl %ebx
leaq 0x28(%rsp), %r14
pushq $0x1
popq %rbp
jmp 0x1c570
leaq 0x30(%rsp), %rdi
callq 0x8c8c
movq 0x8(%rsp), %rdi
incl %edi
jmp 0x1c450
movq 0x110(%rsp), %rcx
addq $0x8, %rcx
jmp 0x1c42b
leaq 0x50(%rsp), %rdi
callq 0x9268
incq %rbx
jmp 0x1c349
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x24(%rsp), %eax
xorl %edx, %edx
divl 0x9fac(%r13)
movl %edx, %ecx
andb $0x7, %cl
pushq $-0x1
popq %rax
shll %cl, %eax
shrl $0x3, %edx
movq 0xf8(%rsp), %rcx
addb %al, (%rcx,%rdx)
xorl %ebp, %ebp
movq 0x48(%r13), %rdi
movl 0x9c(%rsp), %esi
callq 0x5e0a
jmp 0x1ca2a
jmp 0x1ca79
movq %rax, %rbx
jmp 0x1cb41
jmp 0x1caaf
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x1cb41
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x1cb41
jmp 0x1caaf
jmp 0x1caaf
jmp 0x1caa8
movq %rax, %rbx
jmp 0x1cafd
jmp 0x1caaf
movq %rax, %rbx
jmp 0x1cb37
jmp 0x1cb0d
movq %rax, %rbx
movq 0x78(%rsp), %rdi
jmp 0x1cada
movq %rax, %rbx
movq 0x28(%rsp), %rdi
jmp 0x1caf2
jmp 0x1cb0d
movq %rax, %rbx
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0x1cb10
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x1cb10
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x1cafd
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0xa0(%rsp), %rdi
jmp 0x1cb32
jmp 0x1cb0d
jmp 0x1cb0d
jmp 0x1cb0d
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x104d6
leaq 0xe0(%rsp), %rdi
callq 0x9268
leaq 0xc8(%rsp), %rdi
callq 0x9268
leaq 0x30(%rsp), %rdi
callq 0x8c8c
leaq 0x50(%rsp), %rdi
callq 0x9268
movq %rbx, %rdi
callq 0x56f0
nop