// File: /workspace/github_cpp_makefile_star2_O1/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 $0x118, %rsp            # imm = 0x118
movl %esi, %ebp
movq %rdi, %r15
movq 0x48(%rdi), %rdi
movl 0x9fa4(%r15), %esi
movl %ebp, %eax
xorl %edx, %edx
divl 0x9fac(%r15)
leaq 0xac(%rsp), %rcx
movl %eax, %edx
callq 0x6834
movq %rax, %rcx
movl %ebp, %eax
xorl %edx, %edx
divl 0x9fac(%r15)
movl %edx, %eax
shrl $0x3, %eax
movzbl (%rcx,%rax), %eax
andl $0x7, %edx
btl %edx, %eax
jae 0x22be9
movq %rcx, 0xf0(%rsp)
leaq 0x110(%rsp), %rdx
movq %r15, %rdi
movl %ebp, 0x6c(%rsp)
movl %ebp, %esi
callq 0x22d28
cmpl $0x0, 0x798(%r15)
je 0x22bae
movabsq $0x7fffffff8, %r13      # imm = 0x7FFFFFFF8
leaq 0x7a0(%r15), %rax
movq %rax, 0xf8(%rsp)
leaq 0x20(%rsp), %rbx
xorl %ecx, %ecx
movq %r15, %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq %rcx, 0xc8(%rsp)
imulq $0x98, %rcx, %rax
movq 0xf8(%rsp), %rcx
leaq (%rcx,%rax), %rbp
cmpl $0x0, 0x28(%rcx,%rax)
je 0x2248c
movq 0x110(%rsp), %r14
xorl %r15d, %r15d
movq 0x30(%rbp), %rax
movl (%rax,%r15,4), %eax
movq (%r14,%rax,8), %rdi
testq %rdi, %rdi
je 0x22452
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x22454
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xa1bc
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x22481
movq (%rdi), %rax
callq *0x8(%rax)
incq %r15
movl 0x28(%rbp), %eax
cmpq %rax, %r15
jb 0x22439
movq %rbp, %rdi
leaq 0x50(%rsp), %rsi
movl 0x6c(%rsp), %edx
callq 0x1afe8
movq %r12, %r15
movl 0x778(%r12), %eax
cmpq %rax, 0xc8(%rsp)
jne 0x22b89
movq 0x758(%r15), %rax
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rax
movq %rax, 0x100(%rsp)
cmpq %rax, %rcx
je 0x22b89
movq %rcx, 0x108(%rsp)
movq (%rcx), %r14
movq 0x48(%r14), %rax
movq 0x760(%rax), %rcx
cmpq %rcx, 0x768(%rax)
je 0x22b6f
xorl %ebp, %ebp
movq (%rcx,%rbp,8), %rcx
movq 0x50(%rcx), %rcx
cmpq %r15, 0x48(%rcx)
jne 0x22b4b
leaq 0x7a0(%rax), %rsi
movq 0x780(%rax), %rcx
movslq (%rcx,%rbp,4), %rdx
imulq $0x98, %rdx, %rdx
cmpl $-0x1, 0x814(%rax,%rdx)
movq %rbp, 0x18(%rsp)
je 0x22569
movslq (%rcx,%rbp,4), %rax
imulq $0x98, %rax, %rax
addq %rax, %rsi
movq %rbx, %rdi
leaq 0x50(%rsp), %rdx
callq 0x1a1fe
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rax, 0x48(%rsp)
jmp 0x225fb
addq %rdx, %rsi
movq $0x0, 0x48(%rsp)
xorl %ebp, %ebp
movq %rsi, %rdi
callq 0x19846
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x18(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rsi
addq $0x7a0, %rsi            # imm = 0x7A0
movq %rbx, %rdi
leaq 0x50(%rsp), %rdx
callq 0x1a1fe
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x18(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x19886
movq 0x70(%rsp), %rcx
movq %rbp, 0x8(%rsp)
subq %rbp, %rcx
je 0x22b2f
sarq $0x2, %rcx
movq $0x0, 0x10(%rsp)
movq %rcx, 0x70(%rsp)
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x18(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
cmpl $-0x1, 0x74(%rdi)
je 0x22707
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x50(%rsp), %rsi
callq 0x1afe8
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
testq %r13, %rax
je 0x226c7
xorl %ebp, %ebp
movq $0x0, 0x90(%rsp)
movq %rbx, %rdi
leaq 0x90(%rsp), %rsi
callq 0xa1bc
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x226b3
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebp
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebp
jb 0x22684
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x18(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq %rbx, %rsi
callq 0x1ae86
jmp 0x2280f
callq 0x19846
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x18(%rsp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x50(%rsp), %rsi
callq 0x1afe8
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
testq %r13, %rax
je 0x227ae
xorl %ebp, %ebp
movq $0x0, 0x98(%rsp)
movq %rbx, %rdi
leaq 0x98(%rsp), %rsi
callq 0xa1bc
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2279a
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebp
movq 0x58(%rsp), %rax
subq 0x50(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebp
jb 0x2276b
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x18(%rsp), %rbp
movslq (%rcx,%rbp,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
movq %rbx, %rsi
callq 0x1ae86
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movslq (%rcx,%rbp,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x19886
movq %rbx, %rdi
callq 0xa564
movq 0x48(%r14), %rsi
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0xb0(%rsp), %rdi
callq 0x22ea4
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
xorl %eax, %eax
movq %rax, 0xe0(%rsp)
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
movq 0xb8(%rsp), %rax
subq 0xb0(%rsp), %rax
testq %r13, %rax
je 0x2289f
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0x12d56
incl %ebp
movq 0xb8(%rsp), %rax
subq 0xb0(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebp
jb 0x22878
movq 0x48(%r14), %rax
movq 0x760(%rax), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x30(%rcx), %rax
movq 0x38(%rcx), %rdx
subq %rax, %rdx
je 0x228ed
sarq $0x2, %rdx
movq 0x20(%rsp), %rsi
xorl %edi, %edi
movl (%rax,%rdi,4), %ecx
movl %ecx, %r8d
movq $-0x2, %r9
rolq %cl, %r9
shrl $0x6, %r8d
andq %r9, (%rsi,%r8,8)
incq %rdi
movl %edi, %ecx
cmpq %rcx, %rdx
ja 0x228cb
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rcx
subq %rax, %rcx
testq %r13, %rcx
je 0x229b4
xorl %ebp, %ebp
movq 0x20(%rsp), %rcx
movq %rbp, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
btq %rbp, %rcx
jae 0x22932
movq (%rax,%rbp,8), %rdi
testq %rdi, %rdi
je 0x2295d
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x2295f
movq $0x0, 0x80(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0xa1bc
movq 0x80(%rsp), %rdi
jmp 0x22984
xorl %eax, %eax
movq %rax, 0x88(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0xa1bc
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2298f
movq (%rdi), %rax
callq *0x8(%rax)
incq %rbp
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movl %ecx, %ecx
cmpq %rcx, %rbp
jb 0x2290b
movq %r13, %rbx
movq 0x48(%r15), %rdi
movq 0x48(%r14), %rcx
movl 0x9fa4(%rcx), %esi
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rdx
movl (%rax,%rdx,4), %eax
xorl %edx, %edx
divl 0x9fac(%rcx)
movl %eax, %edx
leaq 0xa8(%rsp), %rcx
callq 0x6834
movq %rax, 0x78(%rsp)
movq 0x48(%r14), %rcx
movl 0x9fac(%rcx), %esi
leal -0x1(%rsi), %edx
shrl $0x3, %edx
leaq (%rax,%rdx), %rdi
addq %rdx, %rax
incq %rax
movq %rax, 0x78(%rsp)
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rdx
movl (%rax,%rdx,4), %eax
xorl %edx, %edx
divl %esi
imull 0x9fa8(%rcx), %edx
leaq (%rdx,%rdi), %rax
incq %rax
movq %rax, 0x78(%rsp)
movq 0x48(%r14), %rax
cmpl $0x0, 0x54(%rax)
je 0x22aaf
movl $0x10, %ebp
xorl %r13d, %r13d
xorl %r15d, %r15d
movl -0x4(%rax,%rbp,8), %edx
cmpq $0x4, %rdx
ja 0x22a7b
leaq 0x1efad(%rip), %rsi     # 0x41a04
movslq (%rsi,%rdx,4), %rcx
addq %rsi, %rcx
jmpq *%rcx
movl $0x4, %ecx
jmp 0x22a80
movl $0x10, %ecx
jmp 0x22a80
movzbl (%rax,%rbp,8), %ecx
jmp 0x22a80
movl $0x8, %ecx
jmp 0x22a80
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0xd0(%rsp), %rsi
addq %r13, %rsi
movq %r12, %rdi
leaq 0x78(%rsp), %r8
callq 0x21df2
incq %r15
movq 0x48(%r14), %rax
movl 0x54(%rax), %ecx
addq $0x8, %r13
addq $0x7, %rbp
cmpq %rcx, %r15
jb 0x22a46
movq %r12, %r15
movq 0x48(%r12), %rdi
movl 0xa8(%rsp), %esi
callq 0x68ee
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
movq %rbx, %r13
je 0x22af6
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xa564
leaq 0xb0(%rsp), %rdi
callq 0xa564
movq 0x10(%rsp), %rdx
incl %edx
movq 0x70(%rsp), %rcx
movq %rdx, 0x10(%rsp)
cmpq %rdx, %rcx
leaq 0x20(%rsp), %rbx
ja 0x2261b
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %rbp
je 0x22b4b
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
incl %ebp
movq 0x48(%r14), %rax
movq 0x760(%rax), %rcx
movq 0x768(%rax), %rdx
subq %rcx, %rdx
sarq $0x3, %rdx
cmpq %rbp, %rdx
ja 0x224fb
movq 0x108(%rsp), %rcx
addq $0x8, %rcx
cmpq 0x100(%rsp), %rcx
jne 0x224d6
leaq 0x50(%rsp), %rdi
callq 0xa564
movq 0xc8(%rsp), %rcx
incq %rcx
movl 0x798(%r15), %eax
cmpq %rax, %rcx
jb 0x223f8
movl 0x6c(%rsp), %eax
xorl %edx, %edx
divl 0x9fac(%r15)
movl %edx, %ecx
andb $0x7, %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
shrl $0x3, %edx
movq 0xf0(%rsp), %rcx
addb %al, (%rcx,%rdx)
xorl %ebp, %ebp
movq 0x48(%r15), %rdi
movl 0xac(%rsp), %esi
callq 0x68ee
jmp 0x22bee
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x22c04
movq %rax, %rbx
jmp 0x22d15
jmp 0x22c2d
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x22d15
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x22d15
movq %rax, %rbx
movq $0x0, 0x48(%rsp)
xorl %edi, %edi
jmp 0x22d03
movq %rax, %rbx
movq %rbp, %rdi
jmp 0x22d03
jmp 0x22c4d
movq %rax, %rbx
jmp 0x22ca8
jmp 0x22c54
movq %rax, %rbx
jmp 0x22cfe
jmp 0x22cb1
movq %rax, %rbx
movq 0x80(%rsp), %rdi
jmp 0x22c85
movq %rax, %rbx
movq 0x98(%rsp), %rdi
jmp 0x22c9d
jmp 0x22cb1
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x22cb4
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x22cb4
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x22ca8
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x20(%rsp), %rdi
jmp 0x22cf9
jmp 0x22cb1
movq %rax, %rbx
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x22ce4
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
xorl %eax, %eax
movq %rax, 0x20(%rsp)
movl %eax, 0x28(%rsp)
movq %rax, 0x30(%rsp)
movl %eax, 0x38(%rsp)
movq %rax, 0x40(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xa564
leaq 0xb0(%rsp), %rdi
callq 0xa564
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x22d15
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
leaq 0x50(%rsp), %rdi
callq 0xa564
movq %rbx, %rdi
callq 0x56e0
nop