// File: JMMackenzie[P]binary_to_jass/bin_to_jass_disk.cpp
// Function: read_and_write_doclist(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void read_and_write_doclist(std::string docid_file,
                            std::string out_file) {
  std::ifstream docids(docid_file);
  std::ofstream out(out_file);
  std::vector<uint64_t> offsets;
  std::string doc;

  out << "SENTINEL" << '\0';
  offsets.push_back(out.tellp());

  while (docids >> doc) {
    offsets.push_back(out.tellp());
    out << doc << '\0';
  }

  // Now write the offsets
  out.write((char *)&offsets[0], offsets.size() * sizeof(uint64_t));

  uint64_t total_docs = offsets.size();
  // Now write the number of docs
  out.write((char *)&total_docs, sizeof(uint64_t));
}

// Assembly:
subq $0x508, %rsp            # imm = 0x508
movq %rsi, %rax
movq %rdi, %rsi
movq %rax, 0x68(%rsp)
movq %rsi, 0x500(%rsp)
movq %rax, 0x4f8(%rsp)
leaq 0x2f0(%rsp), %rdi
movl $0x8, %edx
callq 0x22e0
movq 0x68(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
movl $0x10, %edx
callq 0x2360
jmp 0x269d
leaq 0xc8(%rsp), %rdi
callq 0x4c40
leaq 0xa8(%rsp), %rdi
callq 0x2280
leaq 0x30095e(%rip), %rsi    # 0x30301c
leaq 0xf0(%rsp), %rdi
callq 0x2180
movq %rax, 0x60(%rsp)
jmp 0x26d2
movq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x21e0
jmp 0x26e0
leaq 0xf0(%rsp), %rdi
callq 0x2150
movq %rdx, 0x50(%rsp)
movq %rax, 0x58(%rsp)
jmp 0x26f9
movq 0x50(%rsp), %rax
movq 0x58(%rsp), %rcx
movq %rcx, 0x90(%rsp)
movq %rax, 0x98(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x4c80
movq %rax, 0x48(%rsp)
jmp 0x2727
movq 0x48(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x4c50
jmp 0x274b
jmp 0x274d
leaq 0x2f0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2230
movq %rax, 0x40(%rsp)
jmp 0x2769
movq 0x40(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x2220
movb %al, 0x3f(%rsp)
jmp 0x2783
movb 0x3f(%rsp), %al
testb $0x1, %al
jne 0x2790
jmp 0x287d
leaq 0xf0(%rsp), %rdi
callq 0x2150
movq %rdx, 0x28(%rsp)
movq %rax, 0x30(%rsp)
jmp 0x27a9
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, 0x78(%rsp)
movq %rax, 0x80(%rsp)
leaq 0x78(%rsp), %rdi
callq 0x4c80
movq %rax, 0x20(%rsp)
jmp 0x27d1
movq 0x20(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x4c50
jmp 0x27f5
leaq 0xf0(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2170
movq %rax, 0x18(%rsp)
jmp 0x2811
movq 0x18(%rsp), %rdi
xorl %esi, %esi
callq 0x21e0
jmp 0x281f
jmp 0x274d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
jmp 0x2924
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe8(%rsp)
movl %eax, 0xe4(%rsp)
leaq 0xa8(%rsp), %rdi
callq 0x2120
leaq 0xc8(%rsp), %rdi
callq 0x4cd0
leaq 0xf0(%rsp), %rdi
callq 0x22a0
jmp 0x2924
xorl %eax, %eax
movl %eax, %esi
leaq 0xc8(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x4c90
movq 0x8(%rsp), %rdi
movq %rax, 0x10(%rsp)
callq 0x4cb0
movq 0x10(%rsp), %rsi
movq %rax, %rdx
shlq $0x3, %rdx
leaq 0xf0(%rsp), %rdi
callq 0x2250
jmp 0x28bd
leaq 0xc8(%rsp), %rdi
callq 0x4cb0
movq %rax, 0x70(%rsp)
leaq 0xf0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x8, %edx
callq 0x2250
jmp 0x28e8
leaq 0xa8(%rsp), %rdi
callq 0x2120
leaq 0xc8(%rsp), %rdi
callq 0x4cd0
leaq 0xf0(%rsp), %rdi
callq 0x22a0
leaq 0x2f0(%rsp), %rdi
callq 0x2070
addq $0x508, %rsp            # imm = 0x508
retq
leaq 0x2f0(%rsp), %rdi
callq 0x2070
movq 0xe8(%rsp), %rdi
callq 0x2320
nop