// File: /workspace/github_cpp_makefile_star2_O1/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 0x9384
movq %rax, %r15
incl %ebx
movl 0x100c(%rax), %edx
leal (%rdx,%rbx), %r12d
cmpl $0xffc, %r12d           # imm = 0xFFC
jl 0x11d5e
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 0x1203a
leaq -0x1140(%rbp), %rsi
movl %ebx, 0xffc(%rsi)
movq -0x48(%rbp), %rax
movq (%rax), %rdi
callq 0x9744
movq -0x30(%rbp), %rdi
incl 0x40(%rdi)
callq 0x12cc6
movq -0x140(%rbp), %rdi
cmpq %r12, %rdi
je 0x11d79
callq 0x3270
jmp 0x11d79
movq %r15, %rsi
addq $0x10, %rsi
movq -0x40(%rbp), %rcx
movq -0x30(%rbp), %r8
callq 0x1203a
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
cmpq %rax, 0x30(%rcx)
je 0x11f71
xorl %edx, %edx
leaq -0x88(%rbp), %r13
movq %rdx, -0x90(%rbp)
leaq (%rdx,%rdx,2), %rbx
movq %rbx, -0x98(%rbp)
shlq $0x5, %rbx
leaq (%rax,%rbx), %r12
addq $0x38, %r12
movq 0x10(%r12), %r14
cmpq %r12, %r14
je 0x11f3d
leaq -0xa8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
leaq -0xb8(%rbp), %rdi
callq 0x8766
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 0x8766
movq %r13, %rdi
leaq 0x2492(%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 0x11e80
movq %rdx, -0x68(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x58(%rbp)
jmp 0x11e86
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 0xbd90
leaq -0xe8(%rbp), %rdi
callq 0x7926
movq -0x108(%rbp), %rdi
leaq -0xf8(%rbp), %rax
cmpq %rax, %rdi
je 0x11eea
callq 0x3270
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x11efc
callq 0x3270
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x11f11
callq 0x3270
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x11f29
callq 0x3270
movq %r14, %rdi
callq 0x3320
movq %rax, %r14
cmpq %r12, %rax
jne 0x11de3
movq -0x90(%rbp), %rdx
incq %rdx
movq -0x30(%rbp), %rcx
movq 0x28(%rcx), %rax
movq 0x30(%rcx), %rcx
subq %rax, %rcx
sarq $0x5, %rcx
movabsq $-0x5555555555555555, %rsi # imm = 0xAAAAAAAAAAAAAAAB
imulq %rsi, %rcx
cmpq %rdx, %rcx
ja 0x11db7
leaq -0x1130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x11f86
callq 0x3270
leaq -0xd0(%rbp), %rdi
callq 0x889a
addq $0x1118, %rsp           # imm = 0x1118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11fa8
jmp 0x11fa8
movq %rax, %r14
jmp 0x12026
movq %rax, %r14
movq -0x140(%rbp), %rdi
cmpq %r12, %rdi
jne 0x12021
jmp 0x12026
movq %rax, %r14
jmp 0x11ff9
jmp 0x11fc5
movq %rax, %r14
jmp 0x11fe4
movq %rax, %r14
jmp 0x12011
movq %rax, %r14
movq -0x68(%rbp), %rdi
leaq -0x58(%rbp), %rax
cmpq %rax, %rdi
je 0x11fe4
callq 0x3270
movq -0x88(%rbp), %rdi
leaq -0x78(%rbp), %rax
cmpq %rax, %rdi
je 0x11ff9
callq 0x3270
movq -0xb8(%rbp), %rdi
leaq -0xa8(%rbp), %rax
cmpq %rax, %rdi
je 0x12011
callq 0x3270
leaq -0x1130(%rbp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x12026
callq 0x3270
leaq -0xd0(%rbp), %rdi
callq 0x889a
movq %r14, %rdi
callq 0x3480