// File: /workspace/github_cpp_makefile_star2_O2/zimpha[P]MiniSQL/RecordManager.cc
// Function: RecordManager::RecordManagerRecordInsert(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::vector<element, std::allocator<element>> const&, Table&)
void RecordManager::RecordManagerRecordInsert(std::string dbName, const std::vector<element> & entry, Table & nt)
{
    long offset = (nt.blockCount - 1) * BLOCKSIZE;
    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);
    if (endPoint + tupleSize + 4 >= BLOCKSIZE) {
        // The block is full;
        setInt(block, BLOCKSIZE - 4, BLOCKSIZE);
        offset += BLOCKSIZE;
        Block newBlock;
        newBlock.fileName = dbName;
        newBlock.offset = offset;
        InputRecord(newBlock, 0, entry, nt);
        setInt(newBlock, BLOCKSIZE - 4, tupleSize);
        bm.BufferManagerWrite(newBlock);

        nt.blockCount++;
        nt.write();
    }
    else {
        // The block is not full;
        InputRecord(block, endPoint, entry, nt);
        endPoint += tupleSize;
        setInt(block, BLOCKSIZE - 4, endPoint);
    }
    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.insert(tableName+"."+nt.attributes[i].name, entry[i], offset);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1128, %rsp           # imm = 0x1128
movq %rdx, -0x40(%rbp)
movq %rsi, %r13
movl 0x40(%rcx), %eax
shll $0xc, %eax
addl $0xfffff000, %eax       # imm = 0xFFFFF000
movslq %eax, %rdx
andq $0x0, -0x70(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movq %rcx, -0x30(%rbp)
movl (%rcx), %r15d
movq %rdi, -0x48(%rbp)
movq (%rdi), %rdi
movq %rdx, -0x38(%rbp)
callq 0x7a04
movq %rax, %rbx
incl %r15d
movq %rax, %r14
addq $0x10, %r14
movq %r14, %rsi
movl $0xffc, %edx            # imm = 0xFFC
callq 0xea9c
leal (%rax,%r15), %r12d
cmpl $0xffc, %r12d           # imm = 0xFFC
jl 0xece2
leaq -0x1150(%rbp), %rdi
movl $0x1000, 0x100c(%rbx)   # imm = 0x1000
movl $0x1000, %ebx           # imm = 0x1000
leaq (%rdi,%rbx), %r14
leaq -0x140(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
andq $0x0, 0x10(%rax)
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x3160
movq %r14, %rdi
movq %r13, %rsi
callq 0x3150
movq -0x38(%rbp), %rax
addq %rbx, %rax
leaq -0x1150(%rbp), %rsi
movq %rax, -0x38(%rbp)
movq %rax, 0x1020(%rsi)
xorl %edx, %edx
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0xeeba
leaq -0x1150(%rbp), %rsi
movl %r15d, 0xffc(%rsi)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
callq 0x7c8a
movq -0x30(%rbp), %rdi
incl 0x40(%rdi)
callq 0xf884
movq %r14, %rdi
callq 0x34f8
jmp 0xecfb
movq %r14, %rsi
movl %eax, %edx
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0xeeba
movl %r12d, 0x100c(%rbx)
pushq $0x2e
popq %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x3350
leaq -0x1150(%rbp), %rdi
movq %r13, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x32b0
xorl %esi, %esi
leaq -0xa0(%rbp), %r12
leaq -0xc0(%rbp), %r15
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rcx
movq 0x30(%rax), %rax
subq %rcx, %rax
cqto
pushq $0x60
popq %rdi
idivq %rdi
cmpq %rsi, %rax
jbe 0xee2e
imulq $0x60, %rsi, %rax
movq %rax, -0x60(%rbp)
addq %rcx, %rax
addq $0x38, %rax
movq %rax, -0x68(%rbp)
movq 0x10(%rax), %r14
movq %rsi, -0x50(%rbp)
imulq $0x30, %rsi, %rax
movq %rax, -0x58(%rbp)
cmpq -0x68(%rbp), %r14
je 0xee22
leaq 0x20(%r14), %rsi
movq %r12, %rdi
callq 0x3380
movq -0x48(%rbp), %rax
movq 0x8(%rax), %r13
movq %r15, %rdi
leaq -0x1150(%rbp), %rsi
leaq 0x2508(%rip), %rdx      # 0x112a6
callq 0x5d7d
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rdx
addq -0x60(%rbp), %rdx
leaq -0xe0(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x5dd8
movq %r15, %rbx
movq -0x40(%rbp), %rax
movq (%rax), %rcx
addq -0x58(%rbp), %rcx
leaq -0x120(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq -0x38(%rbp), %r8
callq 0x989c
movq %r15, %rdi
callq 0x5e02
movq %r12, %rdi
callq 0x34f8
movq %rbx, %r15
movq %rbx, %rdi
callq 0x34f8
leaq -0xa0(%rbp), %r12
movq %r12, %rdi
callq 0x34f8
movq %r14, %rdi
callq 0x32f0
movq %rax, %r14
jmp 0xed6f
movq -0x50(%rbp), %rsi
incq %rsi
jmp 0xed2c
leaq -0x1150(%rbp), %rdi
callq 0x34f8
leaq -0x80(%rbp), %rdi
callq 0x6dc8
addq $0x1128, %rsp           # imm = 0x1128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xee59
jmp 0xee59
movq %rax, %rbx
jmp 0xeea8
movq %rax, %rbx
movq %r14, %rdi
jmp 0xeea3
movq %rax, %rbx
jmp 0xee9c
movq %rax, %rbx
jmp 0xee90
movq %rax, %rbx
jmp 0xee84
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x34f8
leaq -0xc0(%rbp), %rdi
callq 0x34f8
leaq -0xa0(%rbp), %rdi
callq 0x34f8
leaq -0x1150(%rbp), %rdi
callq 0x34f8
leaq -0x80(%rbp), %rdi
callq 0x6dc8
movq %rbx, %rdi
callq 0x3450
nop