// File: /workspace/github_cpp_makefile_star2_O1/adamnovak[P]rlcsa/display_test.cpp
// Function: main
int main(int argc, char** argv)
{
  std::cout << "RLCSA display test" << std::endl;
  if(argc < 5)
  {
    std::cout << "Usage: display_test basename weights sequences length [random_seed]" << std::endl;
    return 1;
  }
  std::cout << std::endl;

  std::cout << "Base name: " << argv[1] << std::endl;
  std::cout << "Weights: " << argv[2] << std::endl; 

  usint sequences = std::max(atoi(argv[3]), 1);
  std::cout << "Sequences: " << sequences << std::endl;

  usint seq_length = std::max(atoi(argv[4]), 1);
  std::cout << "Sequence length: " << seq_length << std::endl;

  usint seed = 0xDEADBEEF;
  if(argc > 5)
  {
    seed = atoi(argv[5]);
  }
  std::cout << "Random seed: " << seed << std::endl; 
  std::cout << std::endl;

  RLCSA rlcsa(argv[1]);
  if(!rlcsa.isOk() || !rlcsa.supportsDisplay())
  {
    std::cerr << "Error: Display is not supported!" << std::endl;
    return 2;
  }
  rlcsa.printInfo();
  rlcsa.reportSize(true);
  usint size = rlcsa.getSize();


  // Read weights and determine positions.
  weight_type* weights = new weight_type[size];
  std::ifstream weight_file(argv[2], std::ios_base::binary);
  if(!weight_file)
  {
    std::cerr << "Error: Cannot open weight file!" << std::endl;
    delete[] weights;
    return 3;
  }
  weight_file.read((char*)weights, size * sizeof(weight_type));
  weight_file.close();
  srand(seed);
  usint* positions = generatePositions(weights, size, sequences);
  delete[] weights;
  std::cout << "Generated " << sequences << " positions." << std::endl;
  std::cout << std::endl;


  // Do & measure the actual work.
  uchar* buffer = new uchar[seq_length];
  double start = readTimer();
  for(usint i = 0; i < sequences; i++)
  {
    rlcsa.display(0, pair_type(positions[i], positions[i] + seq_length - 1), buffer);
  }
  double time = readTimer() - start;
  std::cout << "Total time: " << time << " seconds." << std::endl;
  std::cout << std::endl;


  delete[] buffer;
  delete[] positions;
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa58, %rsp            # imm = 0xA58
movq %rsi, %r15
movl %edi, %ebp
movq 0x1a9f7(%rip), %r12     # 0x1efd0
leaq 0x12ac5(%rip), %rsi     # 0x170a5
movl $0x12, %edx
movq %r12, %rdi
callq 0x32a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
cmpl $0x4, %ebp
jg 0x4660
leaq 0x12a97(%rip), %rsi     # 0x170b8
movl $0x43, %edx
movq %r12, %rdi
callq 0x32a0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movl $0x1, %ebx
jmp 0x4c0c
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
leaq 0x12a6d(%rip), %rsi     # 0x170fc
movl $0xb, %edx
movq %r12, %rdi
callq 0x32a0
movq 0x8(%r15), %rbx
testq %rbx, %rbx
je 0x46c1
movq %rbx, %rdi
callq 0x3110
movq 0x1a91c(%rip), %rdi     # 0x1efd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x32a0
jmp 0x46da
movq (%r12), %rax
movq -0x18(%rax), %rax
leaq (%r12,%rax), %rdi
movl 0x20(%r12,%rax), %esi
orl $0x1, %esi
callq 0x33e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
leaq 0x129ff(%rip), %rsi     # 0x17108
movl $0x9, %edx
movq %r12, %rdi
callq 0x32a0
movq 0x10(%r15), %rbx
testq %rbx, %rbx
je 0x473b
movq %rbx, %rdi
callq 0x3110
movq 0x1a8a2(%rip), %rdi     # 0x1efd0
movq %rbx, %rsi
movq %rax, %rdx
callq 0x32a0
jmp 0x4754
movq (%r12), %rax
movq -0x18(%rax), %rax
leaq (%r12,%rax), %rdi
movl 0x20(%r12,%rax), %esi
orl $0x1, %esi
callq 0x33e0
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq 0x18(%r15), %rdi
callq 0x3370
movl %eax, %ebx
cmpl $0x2, %eax
movl $0x1, %r14d
cmovll %r14d, %ebx
leaq 0x12977(%rip), %rsi     # 0x17112
movl $0xb, %edx
movq %r12, %rdi
callq 0x32a0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3170
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq 0x20(%r15), %rdi
callq 0x3370
cmpl $0x2, %eax
cmovgel %eax, %r14d
leaq 0x1292a(%rip), %rsi     # 0x1711e
movl $0x11, %edx
movq %r12, %rdi
callq 0x32a0
movq %r12, %rdi
movq %r14, %rsi
callq 0x3170
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movl $0xdeadbeef, %r13d      # imm = 0xDEADBEEF
cmpl $0x5, %ebp
je 0x484d
movq 0x28(%r15), %rdi
callq 0x3370
movl %eax, %r13d
leaq 0x128dc(%rip), %rsi     # 0x17130
movl $0xd, %edx
movq %r12, %rdi
callq 0x32a0
movl %r13d, %esi
movq %r12, %rdi
callq 0x3170
movq %rax, %rbp
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq 0x8(%r15), %rsi
leaq 0x20(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x4ea2
leaq 0x228(%rsp), %rdi
leaq 0x20(%rsp), %rsi
xorl %edx, %edx
callq 0x4f8c
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4900
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3260
cmpb $0x1, 0x228(%rsp)
jne 0x49d1
cmpb $0x0, 0xa41(%rsp)
je 0x49d1
leaq 0x228(%rsp), %rdi
callq 0x8504
leaq 0x228(%rsp), %rdi
movl $0x1, %esi
callq 0x825c
movl 0x22c(%rsp), %eax
movq %rax, 0x10(%rsp)
leaq (,%rax,4), %r12
movq %r12, %rdi
callq 0x3030
movq %rax, %rbp
movq 0x10(%r15), %rsi
leaq 0x20(%rsp), %rdi
movl $0x4, %edx
callq 0x3460
movq 0x20(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x40(%rsp,%rax)
je 0x4a21
movq 0x1a668(%rip), %rbx     # 0x1eff0
leaq 0x127d0(%rip), %rsi     # 0x1715f
movl $0x1f, %edx
movq %rbx, %rdi
callq 0x32a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x1a636(%rip), %rdi     # 0x1eff0
callq 0x3040
movl $0x3, %ebx
movq %rax, %rdi
callq 0x3180
jmp 0x4bed
movq 0x1a618(%rip), %rbx     # 0x1eff0
leaq 0x1275f(%rip), %rsi     # 0x1713e
movl $0x20, %edx
movq %rbx, %rdi
callq 0x32a0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x1a5e6(%rip), %rdi     # 0x1eff0
callq 0x3040
movl $0x2, %ebx
movq %rax, %rdi
callq 0x3180
jmp 0x4bff
leaq 0x20(%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x32c0
leaq 0x20(%rsp), %rdi
callq 0x3080
movl %r13d, %edi
callq 0x3220
movq %rbp, %rdi
movq 0x10(%rsp), %rsi
movl %ebx, %edx
callq 0x4c7a
movq %rax, %r15
movq %rbp, %rdi
callq 0x32e0
movq 0x1a56c(%rip), %rdi     # 0x1efd0
leaq 0x12714(%rip), %rsi     # 0x1717f
movl $0xa, %edx
callq 0x32a0
movq 0x1a554(%rip), %r12     # 0x1efd0
movq %r12, %rdi
movq %rbx, %rsi
callq 0x3170
movq %rax, %r13
leaq 0x126f9(%rip), %rsi     # 0x1718a
movl $0xb, %edx
movq %rax, %rdi
callq 0x32a0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq (%r12), %rax
addq -0x18(%rax), %r12
movq %r12, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x1a4eb(%rip), %rdi     # 0x1efd0
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq %r14, %rdi
callq 0x3030
movq %rax, %r12
callq 0x14aef
movsd %xmm0, 0x10(%rsp)
decl %r14d
xorl %ebp, %ebp
leaq 0x228(%rsp), %r13
movl (%r15,%rbp,4), %eax
leal (%r14,%rax), %edx
shlq $0x20, %rdx
orq %rax, %rdx
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rcx
callq 0x7a2e
incq %rbp
cmpq %rbp, %rbx
jne 0x4b15
callq 0x14aef
movsd %xmm0, 0x18(%rsp)
movq 0x1a485(%rip), %rdi     # 0x1efd0
leaq 0x12644(%rip), %rsi     # 0x17196
movl $0xc, %edx
callq 0x32a0
movsd 0x18(%rsp), %xmm0
subsd 0x10(%rsp), %xmm0
movq 0x1a461(%rip), %rbx     # 0x1efd0
movq %rbx, %rdi
callq 0x33a0
movq %rax, %r14
leaq 0x12622(%rip), %rsi     # 0x171a3
movl $0x9, %edx
movq %rax, %rdi
callq 0x32a0
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3230
movsbl %al, %esi
movq 0x1a3fd(%rip), %rdi     # 0x1efd0
callq 0x3040
movq %rax, %rdi
callq 0x3180
movq %r12, %rdi
callq 0x32e0
xorl %ebx, %ebx
movq %r15, %rbp
movq %rbp, %rdi
callq 0x32e0
leaq 0x20(%rsp), %rdi
callq 0x3090
leaq 0x228(%rsp), %rdi
callq 0x6474
movl %ebx, %eax
addq $0xa58, %rsp            # imm = 0xA58
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4c53
jmp 0x4c53
jmp 0x4c62
jmp 0x4c62
jmp 0x4c53
jmp 0x4c53
jmp 0x4c53
movq %rax, %rbx
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x4c72
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x3260
jmp 0x4c72
movq %rax, %rbx
jmp 0x4c72
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3090
jmp 0x4c65
movq %rax, %rbx
leaq 0x228(%rsp), %rdi
callq 0x6474
movq %rbx, %rdi
callq 0x3440