// File: AlgoLab[P]bwt-lcp-parallel/bwt_lcp.cpp
// Function: compute_BWT(unsigned char, unsigned int, 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>>>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
void compute_BWT(
    const strlen_t k, const strnum_t m,
    const fnames_t& B_tpl,
    const fname_t& IXk_name
) {
  const strlen_t k1 = k+1;
  const luint_t tot = static_cast<luint_t>(m)*k1;
  strlen_reader_t IXk(IXk_name);
  std::vector<enc_fasta_reader_t> Bl;
  for (const fname_t& fname: B_tpl) {
    Bl.emplace_back(fname);
  }
  enc_fasta_writer_t B("outfile-BWT.bin");

  for (luint_t i = 0; i < tot; ++i) {
    const strlen_t l = IXk.read();
    const enc_nucl_t c = Bl[(l+1)%k1].read();
    B.write(c);
  }
  remove_files(B_tpl);
  remove_file(IXk_name);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movb %dil, %al
movb %al, -0x1(%rbp)
movl %esi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movzbl -0x1(%rbp), %eax
addl $0x1, %eax
movb %al, -0x19(%rbp)
movl -0x8(%rbp), %eax
movzbl -0x19(%rbp), %ecx
imulq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x38(%rbp), %rdi
leaq 0x128d3(%rip), %rdx     # 0x19047
callq 0x96a0
leaq -0x50(%rbp), %rdi
callq 0xaa30
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rdi
callq 0x7ef0
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rdi
callq 0x7f20
movq %rax, -0x68(%rbp)
leaq -0x60(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x7f50
testb $0x1, %al
jne 0x67b7
jmp 0x67f1
leaq -0x60(%rbp), %rdi
callq 0x7f90
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0xaa50
jmp 0x67d3
jmp 0x67d5
leaq -0x60(%rbp), %rdi
callq 0x7fb0
jmp 0x67a4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x697a
leaq -0xb1(%rbp), %rdi
movq %rdi, -0xd0(%rbp)
callq 0x3490
movq -0xd0(%rbp), %rdx
leaq 0x12989(%rip), %rsi     # 0x1919b
leaq -0xb0(%rbp), %rdi
callq 0x7fd0
jmp 0x6820
leaq 0x1281d(%rip), %rdx     # 0x19044
leaq -0x90(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x8470
jmp 0x683c
leaq -0xb0(%rbp), %rdi
callq 0x3170
leaq -0xb1(%rbp), %rdi
callq 0x3300
movq $0x0, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x6941
leaq -0x38(%rbp), %rdi
callq 0x97a0
movb %al, -0xd1(%rbp)
jmp 0x6881
movb -0xd1(%rbp), %al
movb %al, -0xc1(%rbp)
movzbl -0xc1(%rbp), %eax
incl %eax
movzbl -0x19(%rbp), %ecx
xorl %edx, %edx
divl %ecx
movl %edx, %esi
leaq -0x50(%rbp), %rdi
callq 0xaad0
movq %rax, %rdi
callq 0x8300
movb %al, -0xd2(%rbp)
jmp 0x68b9
movb -0xd2(%rbp), %al
movb %al, -0xc2(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0xc2(%rbp), %rsi
callq 0x8500
jmp 0x68da
jmp 0x68dc
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
jmp 0x685f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
jmp 0x6919
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3170
leaq -0xb1(%rbp), %rdi
callq 0x3300
jmp 0x697a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x8570
jmp 0x697a
movq -0x10(%rbp), %rdi
callq 0x3860
movq -0x18(%rbp), %rdi
callq 0x3830
leaq -0x90(%rbp), %rdi
callq 0x8570
leaq -0x50(%rbp), %rdi
callq 0xaaf0
leaq -0x38(%rbp), %rdi
callq 0x97e0
addq $0xe0, %rsp
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0xaaf0
leaq -0x38(%rbp), %rdi
callq 0x97e0
movq -0x78(%rbp), %rdi
callq 0x3480
nopw %cs:(%rax,%rax)