// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1118, %rsp           # imm = 0x1118
movq %rdx, -0x40(%rbp)
movq %rsi, %r14
movl 0x40(%rcx), %eax
shll $0xc, %eax
addl $0xfffff000, %eax       # imm = 0xFFFFF000
movslq %eax, %rdx
xorps %xmm0, %xmm0
movaps %xmm0, -0xd0(%rbp)
movq $0x0, -0xc0(%rbp)
movq %rcx, -0x30(%rbp)
movl (%rcx), %ebx
movq %rdi, -0x48(%rbp)
movq (%rdi), %rdi
movq %rdx, -0x38(%rbp)
callq 0x94d8
movq %rax, %r15
incl %ebx
movl 0x100c(%rax), %edx
leal (%rdx,%rbx), %r12d
cmpl $0xffc, %r12d           # imm = 0xFFC
jl 0x11eb6
leaq -0x1140(%rbp), %rdi
movl $0x1000, 0x100c(%r15) # imm = 0x1000
movl $0x1000, %r13d          # imm = 0x1000
leaq (%rdi,%r13), %r15
leaq -0x130(%rbp), %r12
movq %r12, -0x10(%r12)
xorl %eax, %eax
movq %rax, -0x8(%r12)
movb $0x0, (%r12)
movq %rax, 0x10(%r12)
movl $0x1000, %edx           # imm = 0x1000
xorl %esi, %esi
callq 0x3160
movq %r15, %rdi
movq %r14, %rsi
callq 0x3150
movq -0x38(%rbp), %rax
addq %r13, %rax
leaq -0x1140(%rbp), %rsi
movq %rax, -0x38(%rbp)
movq %rax, 0x1020(%rsi)
xorl %edx, %edx
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x12198
leaq -0x1140(%rbp), %rsi
movl %ebx, 0xffc(%rsi)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
callq 0x9898
movq -0x30(%rbp), %rdi
incl 0x40(%rdi)
callq 0x12df6
movq -0x140(%rbp), %rdi
cmpq %r12, %rdi
je 0x11ed1
callq 0x3270
jmp 0x11ed1
movq %r15, %rsi
addq $0x10, %rsi
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x12198
movl %r12d, 0x100c(%r15)
movq %r14, %rdi
movl $0x2e, %esi
xorl %edx, %edx
callq 0x3370
leaq -0x1140(%rbp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %rax, %rcx
callq 0x32c0
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rax
movq 0x30(%rcx), %rcx
cmpq %rax, %rcx
je 0x120cf
xorl %esi, %esi
leaq -0x88(%rbp), %r13
movq %rsi, -0x90(%rbp)
leaq (%rsi,%rsi,2), %rbx
movq %rbx, -0x98(%rbp)
shlq $0x5, %rbx
leaq (%rax,%rbx), %r12
addq $0x38, %r12
movq 0x10(%r12), %r14
cmpq %r12, %r14
je 0x120a4
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
leaq -0xb8(%rbp), %rdi
callq 0x88b4
movq -0x48(%rbp), %rax
movq 0x8(%rax), %r15
leaq -0x78(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x1140(%rbp), %rsi
movq -0x1138(%rbp), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x88b4
movq %r13, %rdi
leaq 0x2337(%rip), %rsi      # 0x142d0
callq 0x34f0
movq -0x30(%rbp), %rax
movq 0x28(%rax), %rax
movq (%rax,%rbx), %rsi
movq 0x8(%rax,%rbx), %rdx
movq %r13, %rdi
callq 0x30c0
leaq -0x58(%rbp), %rsi
movq %rsi, -0x68(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x11fdb
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x11fe1
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, -0x60(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x98(%rbp), %rcx
shlq $0x4, %rcx
movq -0x40(%rbp), %rax
addq (%rax), %rcx
leaq -0x110(%rbp), %rdi
movq %r15, %rsi
leaq -0x68(%rbp), %rdx
movq -0x38(%rbp), %r8
callq 0xbee6
leaq -0xe8(%rbp), %rdi
callq 0x7a6a
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x12045
callq 0x3270
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x12057
callq 0x3270
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x1206c
callq 0x3270
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x12084
callq 0x3270
movq %r14, %rdi
callq 0x3320
movq %rax, %r14
cmpq %r12, %rax
jne 0x11f3e
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rax
movq 0x30(%rcx), %rcx
movq -0x90(%rbp), %rsi
incq %rsi
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x5, %rdx
movabsq $-0x5555555555555555, %rdi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdi, %rdx
cmpq %rsi, %rdx
ja 0x11f12
leaq -0x1130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x120e4
callq 0x3270
leaq -0xd0(%rbp), %rdi
callq 0x89f0
addq $0x1118, %rsp           # imm = 0x1118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x12106
jmp 0x12106
movq %rax, %r14
jmp 0x12184
movq %rax, %r14
movq -0x140(%rbp), %rdi
cmpq %r12, %rdi
jne 0x1217f
jmp 0x12184
movq %rax, %r14
jmp 0x12157
jmp 0x12123
movq %rax, %r14
jmp 0x12142
movq %rax, %r14
jmp 0x1216f
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x12142
callq 0x3270
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x12157
callq 0x3270
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x1216f
callq 0x3270
leaq -0x1130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12184
callq 0x3270
leaq -0xd0(%rbp), %rdi
callq 0x89f0
movq %r14, %rdi
callq 0x3480