// File: /workspace/github_cpp_makefile_star2_O3/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 0x195d4
movl $0x4, %ebp
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebx, %ecx
cmpl $0x63, %ecx
jbe 0x195cd
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x195d2
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x195d4
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %ebp
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x1959c
addl $-0x3, %ebp
jmp 0x195d4
addl $-0x2, %ebp
jmp 0x195d4
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 0x160d0
leaq 0x2f14(%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 0x19646
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x1964d
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 0x2b4e(%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 0x1969c
movq %rdx, 0x48(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x58(%rsp)
jmp 0x196a2
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 0x196d1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x196e7
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 0x1974a
movl $0x4, %r15d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %ebp, %ecx
cmpl $0x63, %ecx
jbe 0x19741
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x19747
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x1974a
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r15d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x1970e
addl $-0x3, %r15d
jmp 0x1974a
addl $-0x2, %r15d
jmp 0x1974a
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 0x160d0
leaq 0x2d9e(%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 0x197c8
movq %rdx, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
jmp 0x197d0
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 0x29cd(%rip), %rsi      # 0x1c1be
callq 0x56f0
movq %rbx, 0x20(%rsp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x19819
movq %rdx, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
jmp 0x1981f
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 0x1984d
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x19867
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 0x1b0b(%rip), %rdx      # 0x1b3e4
leaq 0xb8(%rsp), %rdi
movq %rdx, %rsi
callq 0x736c
leaq 0xf8(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
leaq 0xb8(%rsp), %rcx
movq %r15, %rdi
callq 0x175c8
movq 0xb8(%rsp), %rdi
cmpq %r13, %rdi
je 0x19926
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x19943
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x19960
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5390
movq %r15, %rdi
callq 0x17a20
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 0x19aba
movq %rsp, %r13
leaq 0x70(%rsp), %rbp
leaq 0x90(%rsp), %rbx
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x199b3
movq %rax, 0x8(%rsp)
movb 0x28(%r12), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x186bc
movq 0x28(%r12), %r14
testq %r14, %r14
jle 0x199f7
movq 0x20(%r12), %r15
incq %r14
movb (%r15), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x186bc
incq %r15
decq %r14
cmpq $0x1, %r14
ja 0x199d9
movb 0x48(%r12), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x186bc
movq 0x48(%r12), %r14
testq %r14, %r14
jle 0x19a3b
movq 0x40(%r12), %r15
incq %r14
movb (%r15), %al
movb %al, 0x70(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x186bc
incq %r15
decq %r14
cmpq $0x1, %r14
ja 0x19a1d
movq 0x68(%rsp), %r15
movq %r15, %rdi
movq %r13, %rsi
callq 0x17ac6
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 0x19aa4
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5390
movq %r12, %rdi
callq 0x5290
movq %rax, %r12
cmpq 0x40(%rsp), %rax
jne 0x199a3
movq %r15, %rdi
callq 0x17d44
movq 0x30(%r15), %rdi
callq 0x65bc
movq %r15, %rdi
callq 0x1775e
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 0x19b1e
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x19b35
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0x48(%rsp), %rdi
cmpq %rbx, %rdi
je 0x19b4c
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 0x19b83
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19b83
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r12, %rdi
je 0x19ba5
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19ba5
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x19bc7
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19bc7
movq %rax, %rbx
movl $0x468, %esi            # imm = 0x468
movq 0x68(%rsp), %rdi
callq 0x5390
jmp 0x19c5b
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x19bf9
movq 0x10(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19bf9
movq %rax, %rbx
movq 0x70(%rsp), %rdi
cmpq %r13, %rdi
je 0x19c18
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19c18
movq %rax, %rbx
leaq 0x58(%rsp), %r14
jmp 0x19cd5
movq %rax, %rbx
movq 0x20(%rsp), %rdi
cmpq %r14, %rdi
je 0x19c41
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19c41
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x19cec
movq 0x10(%rsp), %rsi
jmp 0x19ce4
movq %rax, %rbx
leaq 0x58(%rsp), %r14
leaq 0x30(%rsp), %r15
jmp 0x19cbe
jmp 0x19c9b
jmp 0x19c9b
movq %rax, %rbx
movq 0x90(%rsp), %rdi
leaq 0xa0(%rsp), %rax
cmpq %rax, %rdi
je 0x19c9e
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x5390
jmp 0x19c9e
jmp 0x19c9b
jmp 0x19c9b
jmp 0x19c9b
movq %rax, %rbx
movq (%rsp), %rdi
testq %rdi, %rdi
leaq 0x58(%rsp), %r14
leaq 0x30(%rsp), %r15
je 0x19cbe
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x19cd5
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5390
movq 0x48(%rsp), %rdi
cmpq %r14, %rdi
je 0x19cec
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5390
movq %rbx, %rdi
callq 0x5670