// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, %r13
movq %rsi, 0x40(%rsp)
movl 0x38(%rsi), %r15d
movl %r15d, %ebx
negl %ebx
cmovsl %r15d, %ebx
movl $0x1, %ebp
cmpl $0xa, %ebx
jb 0x19574
movl $0x4, %ebp
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x1956d
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x19572
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x19574
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %ebp
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x1953c
addl $-0x3, %ebp
jmp 0x19574
addl $-0x2, %ebp
jmp 0x19574
decl %ebp
shrl $0x1f, %r15d
movl %r15d, %esi
addl %ebp, %esi
leaq 0x10(%rsp), %r12
movq %r12, -0x10(%r12)
movq %rsp, %r14
movq %r14, %rdi
movl $0x2d, %edx
callq 0x5450
movq (%r14), %rdi
addq %r15, %rdi
movl %ebp, %esi
movl %ebx, %edx
callq 0x1606c
leaq 0x2f74(%rip), %rcx      # 0x1c521
movl $0xc, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5400
leaq 0x30(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x195e6
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x195ed
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x20(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x2bae(%rip), %rsi      # 0x1c1be
callq 0x56f0
leaq 0x58(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x1963c
movq %rdx, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x19642
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x50(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x19671
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x19687
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0x40(%rsp), %rax
movl 0x38(%rax), %ebx
movl %ebx, %ebp
negl %ebp
cmovsl %ebx, %ebp
movl $0x1, %r15d
cmpl $0xa, %ebp
jb 0x196ea
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x196e1
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x196e7
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x196ea
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x196ae
addl $-0x3, %r15d
jmp 0x196ea
addl $-0x2, %r15d
jmp 0x196ea
decl %r15d
movq %r13, 0xb0(%rsp)
shrl $0x1f, %ebx
leal (%r15,%rbx), %esi
leaq 0x80(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x70(%rsp), %rdi
movl $0x2d, %edx
callq 0x5450
leaq 0x70(%rsp), %r14
addq (%r14), %rbx
movq %rbx, %rdi
movl %r15d, %esi
movl %ebp, %edx
callq 0x1606c
leaq 0x2dfe(%rip), %rcx      # 0x1c52e
movl $0x10, %r8d
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5400
movq %r12, (%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
leaq 0x30(%rsp), %rbx
je 0x19768
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x19770
movups (%rcx), %xmm0
movups %xmm0, (%r12)
movq 0x8(%rax), %rdx
movq %rsp, %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x2a2d(%rip), %rsi      # 0x1c1be
callq 0x56f0
movq %rbx, 0x20(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x197b9
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x197bf
movups (%rcx), %xmm0
movups %xmm0, (%rbx)
movq 0x8(%rax), %rdx
movq %rdx, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x197ed
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x19807
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5390
movl $0x468, %edi            # imm = 0x468
callq 0x5380
movq %rax, %r15
leaq 0x108(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf8(%rsp), %rdi
movq %rax, 0x68(%rsp)
callq 0x6924
leaq 0xe8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x6924
leaq 0xc8(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x1b6b(%rip), %rdx      # 0x1b3e4
leaq 0xb8(%rsp), %rdi
movq %rdx, %rsi
callq 0x7326
leaq 0xf8(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
leaq 0xb8(%rsp), %rcx
movq %r15, %rdi
callq 0x1757c
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x198c6
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x198e3
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x19900
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5390
movq %r15, %rdi
callq 0x179d4
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x40(%rsp), %rax
movq 0x18(%rax), %r12
addq $0x8, %rax
movq %rax, 0x40(%rsp)
cmpq %rax, %r12
je 0x19a5a
movq %rsp, %r13
leaq 0x70(%rsp), %rbp
leaq 0x90(%rsp), %rbx
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x19953
movq %rax, 0x8(%rsp)
movb 0x28(%r12), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18664
movq 0x28(%r12), %r14
testq %r14, %r14
jle 0x19997
movq 0x20(%r12), %r15
incq %r14
movb (%r15), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18664
incq %r15
decq %r14
cmpq $0x1, %r14
jg 0x19979
movb 0x48(%r12), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18664
movq 0x48(%r12), %r14
testq %r14, %r14
jle 0x199db
movq 0x40(%r12), %r15
incq %r14
movb (%r15), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18664
incq %r15
decq %r14
cmpq $0x1, %r14
jg 0x199bd
movq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x17a7a
movq 0x30(%r15), %r14
leaq 0xa0(%rsp), %rax
movq %rax, 0x90(%rsp)
movq 0x20(%r12), %rsi
movq 0x28(%r12), %rdx
addq %rsi, %rdx
movq %rbx, %rdi
callq 0x6924
movq %r14, %rdi
movq %rbx, %rsi
callq 0x64e4
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x19a44
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5390
movq %r12, %rdi
callq 0x5290
movq %rax, %r12
cmpq 0x40(%rsp), %rax
jne 0x19943
movq %r15, %rdi
callq 0x17ce4
movq 0x30(%r15), %rdi
callq 0x65bc
movq %r15, %rdi
callq 0x17712
movl $0x18, %edi
callq 0x5380
movq 0xb0(%rsp), %rbx
leaq 0x8(%rbx), %rsi
movq %r15, 0x10(%rax)
movq %rax, %rdi
callq 0x5080
incq 0x18(%rbx)
movq (%rbx), %rax
incl (%rax)
movq (%rsp), %rdi
testq %rdi, %rdi
leaq 0x58(%rsp), %rbx
leaq 0x30(%rsp), %r14
je 0x19abe
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x19ad5
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x19aec
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5390
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x19b23
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19b23
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x19b45
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19b45
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x19b67
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19b67
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq 0x68(%rsp), %rdi
callq 0x5390
jmp 0x19bfb
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x19b99
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19b99
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x19bb8
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19bb8
movq %rax, %rbx
leaq 0x58(%rsp), %r14
jmp 0x19c75
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x19be1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19be1
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x19c8c
movq 0x10(%rsp), %rsi
jmp 0x19c84
movq %rax, %rbx
leaq 0x58(%rsp), %r14
leaq 0x30(%rsp), %r15
jmp 0x19c5e
jmp 0x19c3b
jmp 0x19c3b
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x19c3e
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19c3e
jmp 0x19c3b
jmp 0x19c3b
jmp 0x19c3b
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
leaq 0x58(%rsp), %r14
leaq 0x30(%rsp), %r15
je 0x19c5e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x19c75
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x19c8c
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5390
movq %rbx, %rdi
callq 0x5670