// File: /workspace/github_cpp_makefile_star2_O3/wwdatabase[P]database/./rcdmana/rm_filehandle.h
// Function: RM_FileHandle::deleteRec(RID const&)
RC RM_FileHandle::deleteRec(const RID &rid) {
    rid.getPageNum(this->pageID);
    this->bufType = bpm->getPage(this->fileID,
                                 this->pageID,
                                 this->index);
    BufType b = this->bufType;
    int tagID ;
    rid.getSlotNum(tagID);

    int tagInt = tagID / 32;
    int tagBit = tagID % 32;
    unsigned int &tagBlock = b[PAGE_INT_NUM-1-tagInt];

    // check bit correct
    if ((tagBlock & (1 << tagBit)) == 0) {
        cout << "error delete" << endl;
        return 108;
    }

    cout << ">>> delete record : (" << fileID << ", " << pageID << ", " << tagID << ")" << endl;
    tagBlock &= ~(1 << tagBit);

    bpm->markDirty(index);

    /* fresh table info with page index 0
     */
    this->bufType = this->bpm->getPage(this->fileID,
                                 0,
                                 this->index);
    b = this->bufType;
    --recordNumForAllPages;
    b[3] = recordNumForAllPages;
    this->bpm->markDirty(this->index);

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movl (%rsi), %edx
movl %edx, 0x78(%rdi)
movq 0x98(%rdi), %rdi
movl 0x8(%rbx), %esi
leaq 0x88(%rbx), %r14
movq %r14, %rcx
callq 0x4478
movq %rax, 0x80(%rbx)
movl 0x4(%r12), %r12d
leal 0x1f(%r12), %ecx
testl %r12d, %r12d
cmovnsl %r12d, %ecx
sarl $0x5, %ecx
negl %ecx
movslq %ecx, %rsi
movl 0x1ffc(%rax,%rsi,4), %edx
movl $0x1, %r15d
movl %r12d, %ecx
shll %cl, %r15d
btl %r12d, %edx
jae 0x2a63
movq 0x6699(%rip), %r13      # 0x8fd8
movq %rsi, -0x38(%rbp)
leaq 0x373a(%rip), %rsi      # 0x6084
movq %rax, -0x30(%rbp)
movl $0x15, %edx
movq %r13, %rdi
callq 0x2170
movl 0x8(%rbx), %esi
movq %r13, %rdi
callq 0x21f0
movq %rax, %r13
movq %r14, -0x40(%rbp)
leaq 0x39c6(%rip), %r14      # 0x633a
movl $0x2, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2170
movl 0x78(%rbx), %esi
movq %r13, %rdi
callq 0x21f0
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2170
movq %r13, %rdi
movl %r12d, %esi
callq 0x21f0
movq %rax, %r14
leaq 0x36a5(%rip), %rsi      # 0x605c
movl $0x1, %edx
movq %rax, %rdi
callq 0x2170
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
notl %r15d
movq -0x38(%rbp), %rax
movq -0x30(%rbp), %rcx
andl %r15d, 0x1ffc(%rcx,%rax,4)
movq 0x98(%rbx), %rdi
movslq 0x88(%rbx), %rsi
movq 0x20(%rdi), %rax
movb $0x1, %r14b
movb %r14b, (%rax,%rsi)
callq 0x4536
movq 0x98(%rbx), %rdi
movl 0x8(%rbx), %esi
xorl %r15d, %r15d
xorl %edx, %edx
movq -0x40(%rbp), %rcx
callq 0x4478
movq %rax, 0x80(%rbx)
movl 0x68(%rbx), %ecx
decl %ecx
movl %ecx, 0x68(%rbx)
movl %ecx, 0xc(%rax)
movq 0x98(%rbx), %rdi
movslq 0x88(%rbx), %rsi
movq 0x20(%rdi), %rax
movb %r14b, (%rax,%rsi)
callq 0x4536
jmp 0x2aab
movq 0x656e(%rip), %rbx      # 0x8fd8
leaq 0x3606(%rip), %rsi      # 0x6077
movl $0xc, %edx
movq %rbx, %rdi
callq 0x2170
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20c0
movl $0x6c, %r15d
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop