// File: zimpha[P]MiniSQL/RecordManager.cc
// Function: RecordManager::RecordManagerRecordDelete(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, long, Filter const&, Table&)
void RecordManager::RecordManagerRecordDelete(std::string dbName, long offset, const Filter & filter, Table & nt)
{
    bufferIter pBlock;
    std::vector<element> queryTuple;
    int tupleSize = nt.entrySize + 1;

    pBlock = bm.BufferManagerRead(dbName, offset);
    Block & block = *pBlock;
    int endPoint = getInt(block, BLOCKSIZE - 4);
    int tuple;
    int startPos;
    for (tuple = 0; tuple <= endPoint - tupleSize; tuple += tupleSize) {
        if (block.data[tuple] == 'N')
            continue;
        startPos = tuple + 1;
        queryTuple.clear();
        for (auto attr : nt.attributes) {
            switch (attr.type) {
                case 0:
                    queryTuple.push_back(element(getInt(block, startPos)));
                    startPos += sizeof(int);
                    break;
                case 1:
                    queryTuple.push_back(element(getFloat(block, startPos)));
                    startPos += sizeof(float);
                    break;
                case 2:
                    queryTuple.push_back(element(getString(block, startPos)));
                    startPos += attr.length;//Include +1
                    break;
                default:
                    break;
            }
        }
        if (true == filter.test(queryTuple)) {
            block.data[tuple] = 'N';
            std::string tableName = dbName.substr(0, dbName.find('.'));
            for (int i = 0; i < nt.attributes.size(); i++) {
                for (auto index : nt.attributes[i].indices) {
                    im.erase(tableName + "." + nt.attributes[i].name, queryTuple[i]);

                }
            }
        }
    }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rsi, -0x298(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x2a0(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x23de0
leaq -0x48(%rbp), %rdi
callq 0x21a10
movq -0x2a0(%rbp), %rax
movq -0x298(%rbp), %rsi
movq -0x28(%rbp), %rcx
movl (%rcx), %ecx
incl %ecx
movl %ecx, -0x4c(%rbp)
movq (%rax), %rdi
movq -0x18(%rbp), %rdx
callq 0xefc0
movq %rax, -0x290(%rbp)
jmp 0x232b1
movq -0x290(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x30(%rbp)
leaq -0x30(%rbp), %rdi
callq 0xfa80
movq -0x2a0(%rbp), %rdi
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rsi
movl $0xffc, %edx            # imm = 0xFFC
callq 0x227d0
movl %eax, -0x74(%rbp)
movl $0x0, -0x78(%rbp)
movl -0x78(%rbp), %eax
movl -0x74(%rbp), %ecx
subl -0x4c(%rbp), %ecx
cmpl %ecx, %eax
jg 0x23829
movq -0x70(%rbp), %rax
movslq -0x78(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl $0x4e, %eax
jne 0x23328
jmp 0x2381b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2383b
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x23e00
movq -0x28(%rbp), %rax
addq $0x28, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rdi
callq 0x1d230
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rdi
callq 0x1caa0
movq %rax, -0x98(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x23e20
testb $0x1, %al
jne 0x2338b
jmp 0x23597
leaq -0x90(%rbp), %rdi
callq 0x23e60
movq %rax, %rsi
leaq -0xf8(%rbp), %rdi
callq 0x1cb00
jmp 0x233a8
movl -0xd8(%rbp), %eax
movl %eax, -0x2a4(%rbp)
testl %eax, %eax
je 0x233df
jmp 0x233ba
movl -0x2a4(%rbp), %eax
subl $0x1, %eax
je 0x2345e
jmp 0x233cb
movl -0x2a4(%rbp), %eax
subl $0x2, %eax
je 0x234ca
jmp 0x23567
movq -0x2a0(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x7c(%rbp), %edx
callq 0x227d0
movl %eax, %esi
leaq -0x128(%rbp), %rdi
callq 0x24620
jmp 0x23402
leaq -0x48(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x21a30
jmp 0x23414
leaq -0x128(%rbp), %rdi
callq 0x7af0
movslq -0x7c(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x7c(%rbp)
jmp 0x23569
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x23586
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x7af0
jmp 0x23586
movq -0x2a0(%rbp), %rdi
movq -0x70(%rbp), %rsi
movl -0x7c(%rbp), %edx
callq 0x228a0
leaq -0x158(%rbp), %rdi
callq 0x24660
jmp 0x2347f
leaq -0x48(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x21a30
jmp 0x23491
leaq -0x158(%rbp), %rdi
callq 0x7af0
movslq -0x7c(%rbp), %rax
addq $0x4, %rax
movl %eax, -0x7c(%rbp)
jmp 0x23569
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x7af0
jmp 0x23586
movq -0x2a0(%rbp), %rsi
movq -0x70(%rbp), %rdx
movl -0x7c(%rbp), %ecx
leaq -0x1a8(%rbp), %rdi
callq 0x22970
jmp 0x234e6
leaq -0x188(%rbp), %rdi
leaq -0x1a8(%rbp), %rsi
callq 0x246f0
jmp 0x234fb
leaq -0x48(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x21a30
jmp 0x2350d
leaq -0x188(%rbp), %rdi
callq 0x7af0
leaq -0x1a8(%rbp), %rdi
callq 0x35b8
movl -0xd4(%rbp), %eax
addl -0x7c(%rbp), %eax
movl %eax, -0x7c(%rbp)
jmp 0x23569
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x23559
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x188(%rbp), %rdi
callq 0x7af0
leaq -0x1a8(%rbp), %rdi
callq 0x35b8
jmp 0x23586
jmp 0x23569
leaq -0xf8(%rbp), %rdi
callq 0x9fd0
leaq -0x90(%rbp), %rdi
callq 0x23e80
jmp 0x2336f
leaq -0xf8(%rbp), %rdi
callq 0x9fd0
jmp 0x2383b
movq -0x20(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x1d8f0
movb %al, -0x2a5(%rbp)
jmp 0x235ac
movb -0x2a5(%rbp), %al
andb $0x1, %al
movzbl %al, %ecx
movl $0x1, %eax
cmpl %ecx, %eax
jne 0x23819
movq -0x298(%rbp), %rdi
movq -0x70(%rbp), %rax
movslq -0x78(%rbp), %rcx
movb $0x4e, (%rax,%rcx)
xorl %eax, %eax
movl %eax, %edx
movq %rdx, -0x2b0(%rbp)
movl $0x2e, %esi
callq 0x33c0
movq -0x298(%rbp), %rsi
movq -0x2b0(%rbp), %rdx
movq %rax, %rcx
leaq -0x1c8(%rbp), %rdi
callq 0x32f0
jmp 0x2360b
movl $0x0, -0x1cc(%rbp)
movslq -0x1cc(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
callq 0x7750
movq %rax, %rcx
movq -0x2b8(%rbp), %rax
cmpq %rcx, %rax
jae 0x237fd
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movslq -0x1cc(%rbp), %rsi
callq 0x7810
addq $0x30, %rax
movq %rax, -0x1d8(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x1c060
movq %rax, -0x1e0(%rbp)
movq -0x1d8(%rbp), %rdi
callq 0x1c090
movq %rax, -0x1e8(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0xc8c0
testb $0x1, %al
jne 0x236a4
jmp 0x237e7
leaq -0x1e0(%rbp), %rdi
callq 0x1c0c0
movq %rax, %rsi
leaq -0x208(%rbp), %rdi
callq 0x3130
jmp 0x236c1
movq -0x2a0(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x2c0(%rbp)
leaq 0x3bb0(%rip), %rdx      # 0x2728a
leaq -0x288(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
callq 0x76d0
jmp 0x236ef
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movslq -0x1cc(%rbp), %rsi
callq 0x7810
movq %rax, %rdx
leaq -0x268(%rbp), %rdi
leaq -0x288(%rbp), %rsi
callq 0x78a0
jmp 0x2371b
movslq -0x1cc(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0x14b40
movq -0x2c0(%rbp), %rsi
movq %rax, %rcx
leaq -0x248(%rbp), %rdi
leaq -0x268(%rbp), %rdx
callq 0x13fe0
jmp 0x2374a
leaq -0x248(%rbp), %rdi
callq 0x78f0
leaq -0x268(%rbp), %rdi
callq 0x35b8
leaq -0x288(%rbp), %rdi
callq 0x35b8
leaq -0x208(%rbp), %rdi
callq 0x35b8
leaq -0x1e0(%rbp), %rdi
callq 0x1c0e0
jmp 0x23688
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2380b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x237d9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x237cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x268(%rbp), %rdi
callq 0x35b8
leaq -0x288(%rbp), %rdi
callq 0x35b8
leaq -0x208(%rbp), %rdi
callq 0x35b8
jmp 0x2380b
jmp 0x237e9
movl -0x1cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1cc(%rbp)
jmp 0x23615
leaq -0x1c8(%rbp), %rdi
callq 0x35b8
jmp 0x23819
leaq -0x1c8(%rbp), %rdi
callq 0x35b8
jmp 0x2383b
jmp 0x2381b
movl -0x4c(%rbp), %eax
addl -0x78(%rbp), %eax
movl %eax, -0x78(%rbp)
jmp 0x232f0
leaq -0x48(%rbp), %rdi
callq 0xb6d0
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0x48(%rbp), %rdi
callq 0xb6d0
movq -0x60(%rbp), %rdi
callq 0x34f0
nopl (%rax)