// File: /workspace/github_cpp_makefile_star2_O2/prakhar2808[P]DBEngine/dbengine/sstable.cc
// Function: sstable::writeInFile(std::vector<unsigned char, std::allocator<unsigned char>>&)
void sstable::writeInFile(std::vector<unsigned char>& buffer) {
  // Writing in SSTable.
  for(int i = 0; i < (int)buffer.size(); ++i) {
    writefd << buffer[i];
  }
  
  // Check if this is the first key in the block, if yes then put in index.
  if((no_bytes / FS_BLOCK_SIZE) > total_blocks) {
    // Length of key
    writeIndexfd << buffer[0];
    // The key
    for(int i = 1; i < (int)buffer[0] + 1; ++i) {
      writeIndexfd << buffer[i];
    }
    long long cpy_no_bytes = no_bytes;
    std::vector<unsigned char> offset;
    while(cpy_no_bytes) {
      offset.push_back((unsigned char)(cpy_no_bytes % 10 + '0'));
      cpy_no_bytes /= 10;
    }
    std::reverse(offset.begin(), offset.end());
    if(no_bytes == 0) {
      offset.push_back('0');
    }
    // Length of the offset's string representation
    writeIndexfd << (unsigned char)(offset.size());
    // The offset's string representation
    for(int i = 0; i < (int)offset.size(); ++i) {
      writeIndexfd << offset[i];
    }
    ++total_blocks;
  }
  
  // Updating total number of bytes written in the SSTable.
  no_bytes += (long long)buffer.size();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r14
movq %rdi, %r12
leaq 0x58(%rdi), %r15
xorl %ebx, %ebx
movq (%r14), %rdi
movq 0x8(%r14), %rsi
subq %rdi, %rsi
movslq %esi, %rax
cmpq %rax, %rbx
jge 0x14973
movsbl (%rdi,%rbx), %esi
movq %r15, %rdi
callq 0x5480
incq %rbx
jmp 0x14950
movq 0x458(%r12), %rcx
movl $0x400, %r8d            # imm = 0x400
movq %rcx, %rax
cqto
idivq %r8
movslq 0x460(%r12), %rdx
cmpq %rdx, %rax
jle 0x14aa3
leaq 0x258(%r12), %r15
movsbl (%rdi), %esi
movq %r15, %rdi
callq 0x5480
pushq $0x1
popq %rbx
movq (%r14), %rax
movzbl (%rax), %ecx
cmpq %rcx, %rbx
ja 0x149cc
movsbl (%rax,%rbx), %esi
movq %r15, %rdi
callq 0x5480
incq %rbx
jmp 0x149b0
movq %r12, 0x30(%rsp)
movq 0x458(%r12), %rbp
leaq 0x10(%rsp), %r12
andq $0x0, 0x10(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, (%r12)
pushq $0xa
popq %rbx
leaq 0xf(%rsp), %r13
testq %rbp, %rbp
je 0x14a18
movq %rbp, %rax
cqto
idivq %rbx
addb $0x30, %dl
movb %dl, 0xf(%rsp)
movq %rax, %rbp
movq %r12, %rdi
movq %r13, %rsi
callq 0x15122
jmp 0x149f4
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x15277
movq 0x30(%rsp), %r12
cmpq $0x0, 0x458(%r12)
jne 0x14a49
leaq 0xf(%rsp), %rsi
movb $0x30, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x15122
movl 0x18(%rsp), %eax
subl 0x10(%rsp), %eax
movsbl %al, %esi
movq %r15, %rdi
callq 0x5480
xorl %ebx, %ebx
movl 0x18(%rsp), %ecx
movq 0x10(%rsp), %rax
subl %eax, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rbx
jge 0x14a82
movsbl (%rax,%rbx), %esi
movq %r15, %rdi
callq 0x5480
incq %rbx
jmp 0x14a5e
incl 0x460(%r12)
leaq 0x10(%rsp), %rdi
callq 0x150f6
movq 0x8(%r14), %rsi
movq 0x458(%r12), %rcx
subq (%r14), %rsi
addq %rcx, %rsi
movq %rsi, 0x458(%r12)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14ac3
jmp 0x14ac3
jmp 0x14ac3
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x150f6
movq %rbx, %rdi
callq 0x56c0