// File: /workspace/github_cpp_makefile_star2_O1/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 $0x258, %rsp            # imm = 0x258
movq %rcx, 0x40(%rsp)
movq %rdx, %rbx
movl %esi, 0x34(%rsp)
movq %rdi, %r15
callq 0x165ff
movsd %xmm0, 0x38(%rsp)
movq 0x1c947(%rip), %r14     # 0x21fd0
leaq 0x13c08(%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 0x1cc8d(%rip), %rsi     # 0x22358
movq %rbx, %rdi
callq 0x15662
movl %eax, 0x30(%rsp)
leaq 0x1cca2(%rip), %rsi     # 0x22380
movq %rbx, %rdi
callq 0x15662
movl %eax, 0x2c(%rsp)
movq 0x8(%r15), %rax
cmpq (%r15), %rax
je 0x59e1
xorl %r13d, %r13d
movl $0x1, %ebx
leaq 0x50(%rsp), %r12
movl $0x0, 0x1c(%rsp)
callq 0x165ff
movsd %xmm0, 0x20(%rsp)
movl $0x7, %edx
movq 0x1c8ad(%rip), %r14     # 0x21fd0
movq %r14, %rdi
leaq 0x13b95(%rip), %rsi     # 0x192c2
callq 0x3280
movq (%r15), %rax
shlq $0x5, %r13
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq %r14, %rdi
callq 0x3280
movq %r14, %rdi
callq 0x3170
movq (%r15), %rax
movq (%rax,%r13), %rsi
movq %r12, %rdi
movl $0x4, %edx
callq 0x3430
movq 0x50(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x70(%rsp,%rax)
je 0x57eb
movl $0x19, %edx
movq 0x1c86e(%rip), %rdi     # 0x21ff0
leaq 0x13b41(%rip), %rsi     # 0x192ca
callq 0x3280
movq (%r15), %rax
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq 0x1c84f(%rip), %rdi     # 0x21ff0
callq 0x3280
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x140a0(%rip), %rsi     # 0x19858
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
xorl %r12d, %r12d
xorl %ebp, %ebp
jmp 0x581e
movq %r12, %rdi
callq 0x16204
movq %rax, %r12
movl %r12d, %r14d
movq %r14, %rdi
callq 0x3030
movq %rax, %rbp
leaq 0x50(%rsp), %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x32a0
leaq 0x50(%rsp), %rdi
callq 0x3080
testl %r12d, %r12d
je 0x592a
callq 0x165ff
movsd %xmm0, 0x48(%rsp)
movl $0x830, %edi            # imm = 0x830
callq 0x3230
movq %rax, %r14
movl $0x1, (%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movl %r12d, %edx
movl 0x30(%rsp), %ecx
movl 0x2c(%rsp), %r8d
movl 0x34(%rsp), %r9d
callq 0x62b2
callq 0x165ff
movsd %xmm0, 0x10(%rsp)
movl $0x2, %edx
movq 0x1c757(%rip), %rdi     # 0x21fd0
leaq 0x139b0(%rip), %rsi     # 0x19230
callq 0x3280
movsd 0x10(%rsp), %xmm0
subsd 0x20(%rsp), %xmm0
movq 0x1c738(%rip), %rdi     # 0x21fd0
callq 0x3380
movq %rax, %rbp
movl $0x9, %edx
movq %rax, %rdi
leaq 0x1393b(%rip), %rsi     # 0x191ea
callq 0x3280
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3210
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3170
movsd 0x10(%rsp), %xmm0
subsd 0x48(%rsp), %xmm0
movq 0x40(%rsp), %rax
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
cmpb $0x1, (%r14)
jne 0x5913
addq (%r15), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x73d2
addl 0x1c(%rsp), %r12d
movl %r12d, 0x1c(%rsp)
movq %r14, %rdi
callq 0x7314
movl $0x830, %esi            # imm = 0x830
movq %r14, %rdi
callq 0x3240
jmp 0x5998
movl $0x1a, %edx
movq 0x1c6ba(%rip), %rdi     # 0x21ff0
leaq 0x139a7(%rip), %rsi     # 0x192e4
callq 0x3280
movq (%r15), %rax
movq (%rax,%r13), %rsi
movq 0x8(%rax,%r13), %rdx
movq 0x1c69b(%rip), %rdi     # 0x21ff0
callq 0x3280
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x13eec(%rip), %rsi     # 0x19858
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 0x50(%rsp), %r12
movq %r12, %rdi
callq 0x3090
movq 0x8(%r15), %rax
subq (%r15), %rax
movl %ebx, %r13d
sarq $0x5, %rax
incl %ebx
cmpq %r13, %rax
ja 0x570c
movl 0x1c(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
mulsd 0x13636(%rip), %xmm0    # 0x19008
movsd %xmm0, 0x10(%rsp)
movq 0x1c5f1(%rip), %r14     # 0x21fd0
jmp 0x59eb
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
callq 0x165ff
subsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0x138fc(%rip), %rsi     # 0x192ff
movl $0x8, %edx
movq %r14, %rdi
callq 0x3280
movq %r14, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x3380
movq %rax, %rbx
leaq 0x138e0(%rip), %rsi     # 0x19308
movl $0xe, %edx
movq %rax, %rdi
callq 0x3280
movq %rbx, %rdi
movsd 0x20(%rsp), %xmm0
callq 0x3380
movq %rax, %rbx
leaq 0x137db(%rip), %rsi     # 0x19228
movl $0xa, %edx
movq %rax, %rdi
callq 0x3280
movsd 0x10(%rsp), %xmm0
divsd 0x20(%rsp), %xmm0
movq %rbx, %rdi
callq 0x3380
movq %rax, %rbx
leaq 0x137bb(%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 0x13864(%rip), %rsi     # 0x19317
movl $0x8, %edx
movq %r14, %rdi
callq 0x3280
callq 0x16614
movl %eax, %esi
movq %r14, %rdi
callq 0x3160
movq %rax, %rbx
leaq 0x137bb(%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 0x10(%rsp), %xmm0
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5b64
jmp 0x5b64
movq %rax, %rbx
movl $0x830, %esi            # imm = 0x830
movq %r14, %rdi
callq 0x3240
jmp 0x5b67
jmp 0x5b64
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x3090
movq %rbx, %rdi
callq 0x3410
nop