// File: /workspace/github_cpp_makefile_star2_O2/prakhar2808[P]DBEngine/dbengine/sstableWrapper.cc
// Function: sstableWrapper::dumpMemtableToSSTable(memtable*)
void sstableWrapper::dumpMemtableToSSTable(memtable* memtableObjRef) {
  // File path
  std::string filePath = 
    "SSTablesDir/" + std::to_string(memtableObjRef->memtableID) + ".txt";
  // Bloom File path
  std::string bloomFilePath =
    "bloomFiltersDir/" + std::to_string(memtableObjRef->memtableID) + ".txt";
  // Creating SSTable
  sstable* sstableObjRef = new sstable(filePath, bloomFilePath);
  // Opening SSTable file to write
  sstableObjRef->openFileToWrite();
  // Writing to the file
  std::map<std::string, std::string>::iterator iter;
  // Bytes array
  std::vector<unsigned char> buffer;
  // To write each key-value pair in the SSTable and index using buffer.
  for(iter = memtableObjRef->table.begin();
      iter != memtableObjRef->table.end();
      ++iter) {
    buffer.clear();
    buffer.push_back((iter->first).length());
    std::copy((iter->first).begin(), 
              (iter->first).end(), 
              std::back_inserter(buffer));
    buffer.push_back((iter->second).length());
    std::copy((iter->second).begin(),
              (iter->second).end(),
              std::back_inserter(buffer));
    // Add the record to file and index.
    sstableObjRef->writeInFile(buffer);
    // Add the key to bloom filter.
    sstableObjRef->filter->add(iter->first);
  }
  
  // Close the file to save the changes. SSTable and index files are dumped.
  sstableObjRef->closeFileAfterWrite();
  // Dump the bloom filter to the disk.
  sstableObjRef->filter->writeToFile();
  
  // Loading the index in memory.
  sstableObjRef->loadIndexInMemory();
  
  // Inserting SSTable to list.
  sstableObjRefList.push_back(sstableObjRef);
  // Increasing the count of number of SSTables.
  ++(*sstable_no);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rsi, %r14
movq %rdi, %r12
movl 0x38(%rsi), %esi
leaq 0x10(%rsp), %rbx
movq %rbx, %rdi
callq 0x133b8
leaq 0x2b1b(%rip), %rsi      # 0x18521
leaq 0x58(%rsp), %rdi
movq %rbx, %rdx
callq 0x13394
leaq 0x27a4(%rip), %rdx      # 0x181be
leaq 0xd8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x13375
leaq 0x58(%rsp), %rdi
callq 0x51d0
leaq 0x10(%rsp), %rdi
callq 0x51d0
movl 0x38(%r14), %esi
leaq 0x38(%rsp), %rdi
callq 0x133b8
leaq 0x2ad9(%rip), %rsi      # 0x1852e
leaq 0x10(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0x13394
leaq 0x2753(%rip), %rdx      # 0x181be
leaq 0x58(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x13375
leaq 0x10(%rsp), %rdi
callq 0x51d0
leaq 0x38(%rsp), %rdi
callq 0x51d0
movl $0x468, %edi            # imm = 0x468
callq 0x53c0
movq %rax, %r15
leaq 0xb8(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x5540
leaq 0x98(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x5540
leaq 0x191b(%rip), %rsi      # 0x173e4
leaq 0x78(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x6ac6
leaq 0xb8(%rsp), %rsi
leaq 0x98(%rsp), %rdx
leaq 0x78(%rsp), %rcx
movq %r15, %rdi
callq 0x14598
leaq 0x78(%rsp), %rdi
callq 0x51d0
leaq 0x98(%rsp), %rdi
callq 0x51d0
leaq 0xb8(%rsp), %rdi
callq 0x51d0
movq %r15, 0x38(%rsp)
movq %r15, %rdi
callq 0x148be
movq %r12, 0x30(%rsp)
xorps %xmm0, %xmm0
leaq 0x10(%rsp), %r15
movaps %xmm0, (%r15)
andq $0x0, 0x10(%r15)
movq 0x18(%r14), %r13
addq $0x8, %r14
leaq 0xf(%rsp), %r12
leaq 0xf8(%rsp), %rbp
cmpq %r14, %r13
je 0x15bfa
movq 0x10(%rsp), %rax
cmpq %rax, 0x18(%rsp)
je 0x15b6b
movq %rax, 0x18(%rsp)
movb 0x28(%r13), %al
movb %al, 0xf(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x15122
movq 0x20(%r13), %rdi
movq 0x28(%r13), %rsi
addq %rdi, %rsi
movq %r15, %rdx
callq 0x16046
movb 0x48(%r13), %al
movb %al, 0xf(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x15122
movq 0x40(%r13), %rdi
movq 0x48(%r13), %rsi
addq %rdi, %rsi
movq %r15, %rdx
callq 0x1608e
movq 0x38(%rsp), %rbx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x14936
leaq 0x20(%r13), %rsi
movq 0x30(%rbx), %rbx
movq %rbp, %rdi
callq 0x5540
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x61ce
movq %rbp, %rdi
callq 0x51d0
movq %r13, %rdi
callq 0x52d0
movq %rax, %r13
jmp 0x15b51
movq 0x38(%rsp), %r14
movq %r14, %rdi
callq 0x14ad8
movq 0x30(%rsp), %rbx
movq 0x30(%r14), %rdi
callq 0x624a
movq %r14, %rdi
callq 0x146c6
leaq 0x8(%rbx), %rdi
leaq 0x38(%rsp), %rsi
callq 0x15f3c
movq (%rbx), %rax
incl (%rax)
leaq 0x10(%rsp), %rdi
callq 0x150f6
leaq 0x58(%rsp), %rdi
callq 0x51d0
leaq 0xd8(%rsp), %rdi
callq 0x51d0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x51d0
jmp 0x15c75
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x51d0
jmp 0x15c87
movq %rax, %rbx
leaq 0xb8(%rsp), %rdi
callq 0x51d0
jmp 0x15c99
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq %r15, %rdi
callq 0x53d0
jmp 0x15d09
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x51d0
jmp 0x15cba
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
jmp 0x15d0e
movq %rax, %rbx
jmp 0x15d13
movq %rax, %rbx
leaq 0x58(%rsp), %rdi
callq 0x51d0
jmp 0x15cd8
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
jmp 0x15d1b
movq %rax, %rbx
jmp 0x15d09
jmp 0x15cfc
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x51d0
jmp 0x15cff
jmp 0x15cfc
jmp 0x15cfc
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x150f6
leaq 0x58(%rsp), %rdi
callq 0x51d0
leaq 0xd8(%rsp), %rdi
callq 0x51d0
movq %rbx, %rdi
callq 0x56c0