// File: /workspace/github_cpp_makefile_star2_O1/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, %r13
movl 0x8(%rsi), %ecx
movq (%rsi), %rax
subl %eax, %ecx
testl %ecx, %ecx
jle 0x17ad2
leaq 0x58(%r13), %r15
xorl %r12d, %r12d
leaq 0x10(%rsp), %rbx
movb (%rax,%r12), %al
movb %al, 0x10(%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5430
incq %r12
movl 0x8(%r14), %ecx
movq (%r14), %rax
subl %eax, %ecx
movslq %ecx, %rcx
cmpq %rcx, %r12
jl 0x17aa6
movq 0x458(%r13), %rcx
leaq 0x3ff(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0xa, %rdx
movslq 0x460(%r13), %rcx
cmpq %rcx, %rdx
jle 0x17c9f
leaq 0x258(%r13), %r15
movb (%rax), %al
leaq 0x10(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r15, %rdi
callq 0x5430
movq (%r14), %rax
cmpb $0x0, (%rax)
je 0x17b4f
xorl %r12d, %r12d
leaq 0x10(%rsp), %rbx
movb 0x1(%rax,%r12), %al
movb %al, 0x10(%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5430
movq (%r14), %rax
movzbl (%rax), %ecx
incq %r12
cmpq %rcx, %r12
jb 0x17b28
movq %r13, 0x30(%rsp)
movq 0x458(%r13), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %rbx, %rbx
je 0x17bc6
leaq 0x10(%rsp), %r13
leaq 0xf(%rsp), %rbp
movq %rbx, %rax
movabsq $0x6666666666666667, %rcx # imm = 0x6666666666666667
imulq %rcx
movq %rdx, %r12
movq %rdx, %rax
shrq $0x3f, %rax
sarq $0x2, %r12
addq %rax, %r12
leal (%r12,%r12), %eax
leal (%rax,%rax,4), %eax
movl %ebx, %ecx
subl %eax, %ecx
addb $0x30, %cl
movb %cl, 0xf(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
callq 0x18664
addq $0x9, %rbx
cmpq $0x13, %rbx
movq %r12, %rbx
jae 0x17b7b
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
cmpq %rcx, %rax
setne %dl
decq %rcx
cmpq %rax, %rcx
seta %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x17c07
incq %rax
movb -0x1(%rax), %dl
movb (%rcx), %sil
movb %sil, -0x1(%rax)
movb %dl, (%rcx)
decq %rcx
leaq 0x1(%rax), %rdx
cmpq %rcx, %rax
movq %rdx, %rax
jb 0x17bec
movq 0x30(%rsp), %r13
cmpq $0x0, 0x458(%r13)
jne 0x17c28
leaq 0xf(%rsp), %rsi
movb $0x30, (%rsi)
leaq 0x10(%rsp), %rdi
callq 0x18664
movl 0x18(%rsp), %eax
subl 0x10(%rsp), %eax
leaq 0xf(%rsp), %rsi
movb %al, (%rsi)
movl $0x1, %edx
movq %r15, %rdi
callq 0x5430
movl 0x18(%rsp), %eax
movq 0x10(%rsp), %rdi
subl %edi, %eax
testl %eax, %eax
jle 0x17c86
xorl %ebx, %ebx
leaq 0xf(%rsp), %r12
movb (%rdi,%rbx), %al
movb %al, 0xf(%rsp)
movl $0x1, %edx
movq %r15, %rdi
movq %r12, %rsi
callq 0x5430
incq %rbx
movl 0x18(%rsp), %eax
movq 0x10(%rsp), %rdi
subl %edi, %eax
cltq
cmpq %rax, %rbx
jl 0x17c5a
incl 0x460(%r13)
testq %rdi, %rdi
je 0x17c9f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq 0x8(%r14), %rax
subq (%r14), %rax
addq %rax, 0x458(%r13)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x17cc2
jmp 0x17cc2
jmp 0x17cc2
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x17cdc
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq %rbx, %rdi
callq 0x5670