// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x458, %rsp            # imm = 0x458
movq %rsi, %rbx
movq %rdi, %rsi
leaq 0x250(%rsp), %rdi
movl $0x8, %edx
callq 0x22d0
leaq 0x50(%rsp), %rdi
movq %rbx, %rsi
movl $0x10, %edx
callq 0x2350
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leaq 0x40(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %rax, -0x8(%rbp)
movb $0x0, (%rbp)
leaq 0x56a53(%rip), %rsi     # 0x590b4
leaq 0x50(%rsp), %rdi
movl $0x8, %edx
callq 0x2210
leaq 0x8(%rsp), %rsi
movb $0x0, (%rsi)
leaq 0x50(%rsp), %rdi
movl $0x1, %edx
callq 0x2210
leaq 0x50(%rsp), %rdi
callq 0x2190
leaq 0x8(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x10(%rsp), %rdi
xorl %esi, %esi
callq 0x45d6
leaq 0x250(%rsp), %rbx
leaq 0x30(%rsp), %r14
leaq 0x50(%rsp), %r15
leaq 0x10(%rsp), %r12
leaq 0x8(%rsp), %r13
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2250
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x2735
movq %r15, %rdi
callq 0x2190
movq %rax, 0x8(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2701
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x270c
movq %r12, %rdi
movq %r13, %rdx
callq 0x45d6
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r15, %rdi
callq 0x2210
movb $0x0, 0x8(%rsp)
movl $0x1, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x2210
jmp 0x26c1
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
subq %rsi, %rdx
leaq 0x50(%rsp), %rdi
callq 0x2270
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x3, %rax
leaq 0x8(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x50(%rsp), %rdi
movl $0x8, %edx
callq 0x2270
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2788
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x279f
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq 0x5b81a(%rip), %rax     # 0x5dfc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x58(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x50(%rsp,%rcx)
callq 0x2180
leaq 0x148(%rsp), %rdi
callq 0x2090
leaq 0x250(%rsp), %rdi
callq 0x2070
addq $0x458, %rsp            # imm = 0x458
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x27fd
movq %rax, %rbx
jmp 0x2838
jmp 0x27fd
jmp 0x27fd
jmp 0x27fd
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2817
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x282e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
leaq 0x50(%rsp), %rdi
callq 0x2290
leaq 0x250(%rsp), %rdi
callq 0x2070
movq %rbx, %rdi
callq 0x2310