// File: /workspace/github_cpp_makefile_star2_O3/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 0x67e4
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 0x22684
movq %rcx, 0xe8(%rsp)
leaq 0x110(%rsp), %rdx
movq %r15, %rdi
movl %ebp, 0x3c(%rsp)
movl %ebp, %esi
callq 0x227aa
cmpl $0x0, 0x798(%r15)
je 0x22649
movabsq $0x7fffffff8, %r13      # imm = 0x7FFFFFFF8
leaq 0x7a0(%r15), %rax
movq %rax, 0xf0(%rsp)
leaq 0x40(%rsp), %rbx
xorl %ecx, %ecx
movq %r15, %r12
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movq %rcx, 0xb0(%rsp)
imulq $0x98, %rcx, %rax
movq 0xf0(%rsp), %rcx
leaq (%rcx,%rax), %rbp
cmpl $0x0, 0x28(%rcx,%rax)
je 0x21f50
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 0x21f16
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x21f18
xorl %eax, %eax
movq %rax, 0xa0(%rsp)
leaq 0x20(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x9f9a
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x21f45
movq (%rdi), %rax
callq *0x8(%rax)
incq %r15
movl 0x28(%rbp), %eax
cmpq %rax, %r15
jb 0x21efd
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
movl 0x3c(%rsp), %edx
callq 0x1a82c
movq %r12, %r15
movl 0x778(%r12), %eax
cmpq %rax, 0xb0(%rsp)
jne 0x22624
movq 0x758(%r15), %rax
movq 0x50(%rax), %rcx
movq 0x58(%rax), %rax
movq %rax, 0xf8(%rsp)
cmpq %rax, %rcx
je 0x22624
movq %rcx, 0x100(%rsp)
movq (%rcx), %r14
movq 0x48(%r14), %rax
movq 0x760(%rax), %rcx
cmpq %rcx, 0x768(%rax)
je 0x2260a
xorl %ebp, %ebp
movq (%rcx,%rbp,8), %rcx
movq 0x50(%rcx), %rcx
cmpq %r15, 0x48(%rcx)
jne 0x225e6
leaq 0x7a0(%rax), %rsi
movq 0x780(%rax), %rcx
movq %rbp, 0x18(%rsp)
movslq (%rcx,%rbp,4), %rcx
imulq $0x98, %rcx, %rcx
cmpl $-0x1, 0x814(%rax,%rcx)
je 0x22022
addq %rcx, %rsi
movq %rbx, %rdi
leaq 0x20(%rsp), %rdx
callq 0x19a30
movq 0x40(%rsp), %rbp
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rax, 0x70(%rsp)
jmp 0x220b4
addq %rcx, %rsi
movq $0x0, 0x70(%rsp)
xorl %ebp, %ebp
movq %rsi, %rdi
callq 0x19088
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 0x20(%rsp), %rdx
callq 0x19a30
movq 0x40(%rsp), %rbp
movq 0x48(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 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
callq 0x190c8
movq 0x78(%rsp), %rcx
movq %rbp, 0x8(%rsp)
subq %rbp, %rcx
je 0x225ca
sarq $0x2, %rcx
movq $0x0, 0x10(%rsp)
movq %rcx, 0x78(%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 0x221c0
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0x20(%rsp), %rsi
callq 0x1a82c
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
testq %r13, %rax
je 0x22180
xorl %ebp, %ebp
movq $0x0, 0x90(%rsp)
movq %rbx, %rdi
leaq 0x90(%rsp), %rsi
callq 0x9f9a
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x2216c
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebp
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebp
jb 0x2213d
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 0x1a6ca
jmp 0x222cb
callq 0x19088
leaq 0x98(%rsp), %r15
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 0x20(%rsp), %rsi
callq 0x1a82c
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
testq %r13, %rax
je 0x2226a
xorl %ebp, %ebp
movq $0x0, 0x98(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x9f9a
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x22256
movq (%rdi), %rax
callq *0x8(%rax)
incl %ebp
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
shrq $0x3, %rax
cmpl %eax, %ebp
jb 0x2222c
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movq 0x18(%rsp), %r15
movslq (%rcx,%r15,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 0x1a6ca
movq 0x48(%r14), %rax
movq 0x780(%rax), %rcx
movslq (%rcx,%r15,4), %rcx
imulq $0x98, %rcx, %rcx
leaq (%rax,%rcx), %rdi
addq $0x7a0, %rdi            # imm = 0x7A0
callq 0x190c8
movq %rbx, %rdi
callq 0xa37e
movq 0x48(%r14), %rsi
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %edx
leaq 0xb8(%rsp), %rdi
callq 0x22900
xorps %xmm0, %xmm0
movaps %xmm0, 0xd0(%rsp)
xorl %eax, %eax
movq %rax, 0xe0(%rsp)
movq %rax, 0x40(%rsp)
movl %eax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movl %eax, 0x58(%rsp)
movq %rax, 0x60(%rsp)
movq 0xb8(%rsp), %rax
movq 0xc0(%rsp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
testq %r13, %rcx
je 0x22367
xorl %ebp, %ebp
movq %rbx, %rdi
movl $0x1, %esi
callq 0x126f6
incl %ebp
movq 0xb8(%rsp), %rax
movq 0xc0(%rsp), %rdx
movq %rdx, %rcx
subq %rax, %rcx
shrq $0x3, %rcx
cmpl %ecx, %ebp
jb 0x2233a
movq 0x48(%r14), %r8
movq 0x760(%r8), %rcx
movq 0x18(%rsp), %rsi
movq (%rcx,%rsi,8), %rcx
movq 0x30(%rcx), %rsi
movq 0x38(%rcx), %rdi
subq %rsi, %rdi
je 0x223b8
sarq $0x2, %rdi
movq 0x40(%rsp), %r9
xorl %r10d, %r10d
movl (%rsi,%r10,4), %ecx
movl %ecx, %r11d
movq $-0x2, %r15
rolq %cl, %r15
shrl $0x6, %r11d
andq %r15, (%r9,%r11,8)
incq %r10
movl %r10d, %ecx
cmpq %rcx, %rdi
ja 0x22394
subq %rax, %rdx
testq %r13, %rdx
movq %r12, %r15
je 0x22476
xorl %ebp, %ebp
movq 0x40(%rsp), %rcx
movq %rbp, %rdx
shrq $0x6, %rdx
movq (%rcx,%rdx,8), %rcx
btq %rbp, %rcx
jae 0x223f0
movq (%rax,%rbp,8), %rdi
testq %rdi, %rdi
je 0x2241b
movq (%rdi), %rax
callq *0x10(%rax)
jmp 0x2241d
movq $0x0, 0x80(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x9f9a
movq 0x80(%rsp), %rdi
jmp 0x22442
xorl %eax, %eax
movq %rax, 0x88(%rsp)
leaq 0xd0(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x9f9a
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2244d
movq (%rdi), %rax
callq *0x8(%rax)
incq %rbp
movq 0xb8(%rsp), %rax
movq 0xc0(%rsp), %rcx
subq %rax, %rcx
shrq $0x3, %rcx
movl %ecx, %ecx
cmpq %rcx, %rbp
jb 0x223c9
movq 0x48(%r14), %r8
movq %r13, %rbx
movq 0x48(%r15), %rdi
movl 0x9fa4(%r8), %esi
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movl (%rax,%rcx,4), %eax
xorl %edx, %edx
divl 0x9fac(%r8)
movl %eax, %edx
leaq 0xa8(%rsp), %rcx
callq 0x67e4
movq %rax, %rcx
movq 0x48(%r14), %rsi
movl 0x9fac(%rsi), %edi
leal -0x1(%rdi), %eax
shrl $0x3, %eax
addq %rax, %rcx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rdx
movl (%rax,%rdx,4), %eax
xorl %edx, %edx
divl %edi
imull 0x9fa8(%rsi), %edx
leaq (%rdx,%rcx), %rax
incq %rax
movq %rax, 0x108(%rsp)
cmpl $0x0, 0x54(%rsi)
je 0x22563
movl $0x10, %ebp
xorl %r13d, %r13d
xorl %r15d, %r15d
movl -0x4(%rsi,%rbp,8), %edx
cmpq $0x4, %rdx
ja 0x2252c
leaq 0x1e4ec(%rip), %rcx     # 0x409f4
movslq (%rcx,%rdx,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x4, %ecx
jmp 0x22531
movl $0x10, %ecx
jmp 0x22531
movzbl (%rsi,%rbp,8), %ecx
jmp 0x22531
movl $0x8, %ecx
jmp 0x22531
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0xd0(%rsp), %rsi
addq %r13, %rsi
movq %r12, %rdi
leaq 0x108(%rsp), %r8
callq 0x218fe
incq %r15
movq 0x48(%r14), %rsi
movl 0x54(%rsi), %eax
addq $0x8, %r13
addq $0x7, %rbp
cmpq %rax, %r15
jb 0x224f7
movq %r12, %r15
movq 0x48(%r12), %rdi
movl 0xa8(%rsp), %esi
callq 0x689e
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
movq %rbx, %r13
je 0x22591
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
leaq 0xd0(%rsp), %rdi
callq 0xa37e
leaq 0xb8(%rsp), %rdi
callq 0xa37e
movq 0x10(%rsp), %rdx
incl %edx
movq 0x78(%rsp), %rcx
movq %rdx, 0x10(%rsp)
cmpq %rdx, %rcx
leaq 0x40(%rsp), %rbx
ja 0x220d4
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
movq 0x18(%rsp), %rbp
je 0x225e6
movq 0x70(%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 0x21fbf
movq 0x100(%rsp), %rcx
addq $0x8, %rcx
cmpq 0xf8(%rsp), %rcx
jne 0x21f9a
leaq 0x20(%rsp), %rdi
callq 0xa37e
movq 0xb0(%rsp), %rcx
incq %rcx
movl 0x798(%r15), %eax
cmpq %rax, %rcx
jb 0x21ebc
movl 0x3c(%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 0xe8(%rsp), %rcx
addb %al, (%rcx,%rdx)
xorl %ebp, %ebp
movq 0x48(%r15), %rdi
movl 0xac(%rsp), %esi
callq 0x689e
jmp 0x22689
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 0x226c2
jmp 0x226c2
jmp 0x226c2
movq %rax, %rbx
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x22797
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x22797
movq %rax, %rbx
jmp 0x22797
movq %rax, %rbx
movq %rbp, %rdi
jmp 0x22785
jmp 0x226d7
movq %rax, %rbx
jmp 0x22732
jmp 0x226de
movq %rax, %rbx
jmp 0x22780
jmp 0x2273b
movq %rax, %rbx
movq 0x80(%rsp), %rdi
jmp 0x2270f
movq %rax, %rbx
movq 0x98(%rsp), %rdi
jmp 0x22727
jmp 0x2273b
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2273e
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x2273e
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x22732
movq (%rdi), %rax
callq *0x8(%rax)
leaq 0x40(%rsp), %rdi
jmp 0x2277b
jmp 0x2273b
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x22766
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
movq $0x0, 0x40(%rsp)
movl $0x0, 0x48(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xa37e
leaq 0xb8(%rsp), %rdi
callq 0xa37e
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0x22797
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x53a0
leaq 0x20(%rsp), %rdi
callq 0xa37e
movq %rbx, %rdi
callq 0x56e0
nop