// File: /workspace/github_cpp_makefile_star2_O3/adamnovak[P]rlcsa/parallel_build.cpp
// Function: indexParts(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&, unsigned int, CSA::Parameters&, double&)
double
indexParts(std::vector<std::string>& filenames, usint threads, Parameters& parameters, double& build_time)
{
  double start = readTimer();
  std::cout << "Phase 1: Building indexes for input files" << std::endl;
  usint block_size = parameters.get(RLCSA_BLOCK_SIZE);
  usint sample_rate = parameters.get(SAMPLE_RATE);
  usint total_size = 0;

  for(usint i = 0; i < filenames.size(); i++)
  {
    double init = readTimer();
    uchar* data = 0; usint size = 0;
    std::cout << "Input: " << filenames[i]; std::cout.flush();
    std::ifstream input(filenames[i].c_str(), std::ios_base::binary);
    if(!input)
    {
      std::cerr << "Error opening input file " << filenames[i] << "!" << std::endl;
    }
    else
    {
      size = fileSize(input);
      data = new uchar[size];
      input.read((char*)data, size);
      input.close();
    }

    if(size > 0)
    {
      double mark = readTimer();
      RLCSA* index = new RLCSA(data, size, block_size, sample_rate, threads, true);
      double done = readTimer();
      std::cout << " (" << (done - init) << " seconds)" << std::endl;
      build_time += done - mark;
      if(index != 0 && index->isOk()) { index->writeTo(filenames[i]); total_size += size; }
      delete index;
    }
    else
    {
      std::cerr << "Warning: Empty input file " << filenames[i] << "!" << std::endl;
    }
  }

  double total_time = readTimer() - start;
  double megabytes = total_size / (double)MEGABYTE;
  std::cout << "Indexed " << megabytes << " megabytes in " << total_time << " seconds (" << (megabytes / total_time) << " MB/s)." << std::endl;
  std::cout << "Memory: " << memoryUsage() << " kB" << std::endl;
  std::cout << std::endl;

  return megabytes;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x248, %rsp            # imm = 0x248
movq %rcx, 0x30(%rsp)
movq %rdx, %rbx
movl %esi, 0x24(%rsp)
movq %rdi, %r15
callq 0x16c4f
movsd %xmm0, 0x28(%rsp)
movq 0x1c945(%rip), %r14     # 0x21fd0
leaq 0x13c06(%rip), %rsi     # 0x19298
movl $0x29, %edx
movq %r14, %rdi
callq 0x3280
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
leaq 0x1cc8b(%rip), %rsi     # 0x22358
movq %rbx, %rdi
callq 0x15cd2
movl %eax, 0x20(%rsp)
leaq 0x1cca0(%rip), %rsi     # 0x22380
movq %rbx, %rdi
callq 0x15cd2
movl %eax, 0x1c(%rsp)
movq 0x8(%r15), %rax
cmpq (%r15), %rax
je 0x59dd
xorl %ebp, %ebp
movl $0x1, %ebx
leaq 0x40(%rsp), %r12
movl $0x0, 0x18(%rsp)
callq 0x16c4f
movsd %xmm0, 0x8(%rsp)
movl $0x7, %edx
movq 0x1c8ac(%rip), %r14     # 0x21fd0
movq %r14, %rdi
leaq 0x13b94(%rip), %rsi     # 0x192c2
callq 0x3280
movq (%r15), %rax
shlq $0x5, %rbp
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
movq %r14, %rdi
callq 0x3280
movq %r14, %rdi
callq 0x3170
movq (%r15), %rax
movq (%rax,%rbp), %rsi
movq %r12, %rdi
movl $0x4, %edx
callq 0x3430
movq 0x40(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x60(%rsp,%rax)
je 0x585c
movl $0x19, %edx
movq 0x1c869(%rip), %rdi     # 0x21ff0
leaq 0x13b3c(%rip), %rsi     # 0x192ca
callq 0x3280
movq (%r15), %rax
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
movq 0x1c84a(%rip), %rdi     # 0x21ff0
callq 0x3280
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x140e3(%rip), %rsi     # 0x198a0
callq 0x3280
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
movl $0x1a, %edx
movq 0x1c7fb(%rip), %rdi     # 0x21ff0
leaq 0x13ae8(%rip), %rsi     # 0x192e4
callq 0x3280
movq (%r15), %rax
movq (%rax,%rbp), %rsi
movq 0x8(%rax,%rbp), %rdx
movq 0x1c7dc(%rip), %rdi     # 0x21ff0
callq 0x3280
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x14075(%rip), %rsi     # 0x198a0
callq 0x3280
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
jmp 0x5995
movq %r12, %rdi
callq 0x16860
movq %rax, %r14
movl %r14d, %r13d
movq %r13, %rdi
callq 0x3030
movq %rax, %r12
leaq 0x40(%rsp), %rdi
movq %rax, %rsi
movq %r13, %rdx
callq 0x32a0
leaq 0x40(%rsp), %rdi
callq 0x3080
testl %r14d, %r14d
je 0x57e9
callq 0x16c4f
movsd %xmm0, 0x38(%rsp)
movl $0x830, %edi            # imm = 0x830
callq 0x3230
movq %rax, %r13
movl $0x1, (%rsp)
movq %rax, %rdi
movq %r12, %rsi
movl %r14d, %edx
movl 0x20(%rsp), %ecx
movl 0x1c(%rsp), %r8d
movl 0x24(%rsp), %r9d
callq 0x62be
callq 0x16c4f
movsd %xmm0, 0x10(%rsp)
movl $0x2, %edx
movq 0x1c6e6(%rip), %rdi     # 0x21fd0
leaq 0x1393f(%rip), %rsi     # 0x19230
callq 0x3280
movsd 0x10(%rsp), %xmm0
subsd 0x8(%rsp), %xmm0
movq 0x1c6c7(%rip), %rdi     # 0x21fd0
callq 0x3380
movq %rax, %r12
movl $0x9, %edx
movq %rax, %rdi
leaq 0x138ca(%rip), %rsi     # 0x191ea
callq 0x3280
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
movsd 0x10(%rsp), %xmm0
subsd 0x38(%rsp), %xmm0
movq 0x30(%rsp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
cmpb $0x1, (%r13)
jne 0x5980
addq (%r15), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x73f0
addl %r14d, 0x18(%rsp)
movq %r13, %rdi
callq 0x7336
movl $0x830, %esi            # imm = 0x830
movq %r13, %rdi
callq 0x3240
leaq 0x40(%rsp), %r12
movq %r12, %rdi
callq 0x3090
movq 0x8(%r15), %rax
subq (%r15), %rax
movl %ebx, %ebp
sarq $0x5, %rax
incl %ebx
cmpq %rbp, %rax
ja 0x570d
movl 0x18(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x1363a(%rip), %xmm0    # 0x19008
movsd %xmm0, 0x8(%rsp)
movq 0x1c5f5(%rip), %r14     # 0x21fd0
jmp 0x59e7
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
callq 0x16c4f
subsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x13900(%rip), %rsi     # 0x192ff
movl $0x8, %edx
movq %r14, %rdi
callq 0x3280
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3380
movq %rax, %rbx
leaq 0x138e4(%rip), %rsi     # 0x19308
movl $0xe, %edx
movq %rax, %rdi
callq 0x3280
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x3380
movq %rax, %rbx
leaq 0x137df(%rip), %rsi     # 0x19228
movl $0xa, %edx
movq %rax, %rdi
callq 0x3280
movsd 0x8(%rsp), %xmm0
divsd 0x10(%rsp), %xmm0
movq %rbx, %rdi
callq 0x3380
movq %rax, %rbx
leaq 0x137bf(%rip), %rsi     # 0x19233
movl $0x7, %edx
movq %rax, %rdi
callq 0x3280
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
leaq 0x13868(%rip), %rsi     # 0x19317
movl $0x8, %edx
movq %r14, %rdi
callq 0x3280
callq 0x16c64
movl %eax, %esi
movq %r14, %rdi
callq 0x3160
movq %rax, %rbx
leaq 0x137bf(%rip), %rsi     # 0x19294
movl $0x3, %edx
movq %rax, %rdi
callq 0x3280
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
movsd 0x8(%rsp), %xmm0
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5b60
movq %rax, %rbx
movl $0x830, %esi            # imm = 0x830
movq %r13, %rdi
callq 0x3240
jmp 0x5b63
jmp 0x5b60
jmp 0x5b60
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3410
nop