// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/test-maxpairs.c
// Function: gt_testmaxpairs
int gt_testmaxpairs(const char *indexname,
                    GtUword samples,
                    unsigned int minlength,
                    GtUword substringlength,
                    GtLogger *logger,
                    GtError *err)
{
  bool haserr = false;
  GtEncseq *encseq;
  GtUword idx, totallength = 0, dblen, querylen;
  GtUchar *dbseq = NULL, *query = NULL;
  GtAlphabet *alphabet = NULL;
  GtArray *tabmaxquerymatches;
  GtMaxmatchselfinfo maxmatchselfinfo;
  GtEncseqLoader *el;

  gt_logger_log(logger,"draw "GT_WU" samples",samples);
  el = gt_encseq_loader_new();
  gt_encseq_loader_do_not_require_des_tab(el);
  gt_encseq_loader_do_not_require_ssp_tab(el);
  gt_encseq_loader_do_not_require_sds_tab(el);
  gt_encseq_loader_set_logger(el, logger);
  encseq = gt_encseq_loader_load(el, indexname, err);
  gt_encseq_loader_delete(el);

  if (encseq == NULL)
  {
    haserr = true;
  } else
  {
    totallength = gt_encseq_total_length(encseq);
  }
  if (!haserr)
  {
    if (substringlength > totallength/2)
    {
      substringlength = totallength/2;
    }
    /* use one memory area for dbseq and query, since in one method
       we concatenate both sequences */
    dbseq = gt_malloc(sizeof *dbseq * (1 + GT_MULT2(substringlength)));
    alphabet = gt_encseq_alphabet(encseq);
  }
  for (idx = 0; idx < samples && !haserr; idx++)
  {
    dblen = gt_samplesubstring(false,dbseq,encseq,substringlength);
    gt_assert(dbseq != NULL);
    query = dbseq + dblen + 1;
    gt_assert(query != NULL);
    dbseq[dblen] = GT_SEPARATOR;
    querylen = gt_samplesubstring(true,query,encseq,substringlength);
    if (querylen < (GtUword) minlength || dblen < (GtUword) minlength ||
        dbseq[0] == GT_SEPARATOR || query[0] == GT_SEPARATOR ||
        dbseq[substringlength-1] == GT_SEPARATOR ||
        query[substringlength-1] == GT_SEPARATOR)
    {
      continue;
    }
    gt_logger_log(logger,"run query match for dblen="GT_WU""
                         ",querylen= "GT_WU", minlength=%u",
                         dblen,
                         querylen,
                         minlength);
    tabmaxquerymatches = gt_array_new(sizeof (Substringmatch));
    if (gt_sarrquerysubstringmatch(dbseq,
                                   dblen,
                                   query,
                                   querylen,
                                   minlength,
                                   alphabet,
                                   gt_storemaxmatchquery,
                                   tabmaxquerymatches,
                                   logger,
                                   err) != 0)
    {
      haserr = true;
      break;
    }
    gt_logger_log(logger,"run self match for dblen="GT_WU""
                         ",querylen= "GT_WU", minlength=%u",
                         dblen,
                         querylen,
                         minlength);
    maxmatchselfinfo.results = gt_array_new(sizeof (Substringmatch));
    maxmatchselfinfo.dblen = dblen;
    maxmatchselfinfo.querylen = querylen;
    maxmatchselfinfo.querymarkpos
      = gt_sequence2markpositions(&maxmatchselfinfo.numofquerysequences,
                                  query,querylen);
    if (gt_constructsarrandrunmaxpairs(
                 dbseq,
                 dblen + 1 + querylen,
                 GT_READMODE_FORWARD,
                 minlength,
                 gt_encseq_alphabetnumofchars(encseq),
                 gt_storemaxmatchself,
                 &maxmatchselfinfo,
                 err) != 0)
    {
      haserr = true;
      break;
    }
    gt_array_sort(tabmaxquerymatches,gt_orderSubstringmatch);
    gt_array_sort(maxmatchselfinfo.results,gt_orderSubstringmatch);
    if (!gt_array_equal(tabmaxquerymatches,maxmatchselfinfo.results,
                        gt_orderSubstringmatch))
    {
      const GtUword width = 60UL;
      fprintf(stderr,"failure for query of length "GT_WU"\n",querylen);
      fprintf(stderr,"querymatches\n");
      (void) gt_array_iterate(tabmaxquerymatches,gt_showSubstringmatch,NULL,
                              err);
      fprintf(stderr,"dbmatches\n");
      (void) gt_array_iterate(maxmatchselfinfo.results,gt_showSubstringmatch,
                              NULL,err);
      gt_symbolstring2fasta(stderr,"dbseq", alphabet, dbseq, dblen, width);
      gt_symbolstring2fasta(stderr,"queryseq", alphabet, query, querylen,width);
      exit(GT_EXIT_PROGRAMMING_ERROR);
    }
    gt_free(maxmatchselfinfo.querymarkpos);
    gt_array_delete(tabmaxquerymatches);
    gt_array_delete(maxmatchselfinfo.results);
  }
  gt_free(dbseq);
  gt_encseq_delete(encseq);
  return haserr ? -1 : 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, %rbx
movq %r8, %rbp
movq %rcx, %r15
movl %edx, 0xc(%rsp)
movq %rsi, %r13
movq %rdi, %r14
leaq 0x1bc443(%rip), %rsi    # 0x3bc3c3
movq %r8, %rdi
movq %r13, %rdx
xorl %eax, %eax
callq 0x103fe1
callq 0xef0cd
movq %rax, %r12
movq %rax, %rdi
callq 0xf23ac
movq %r12, %rdi
callq 0xf23d9
movq %r12, %rdi
callq 0xf2408
movq %r12, %rdi
movq %rbp, 0x40(%rsp)
movq %rbp, %rsi
callq 0xf249c
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0xef129
movq %rax, %r14
movq %r12, %rdi
callq 0xefbe3
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %r14, %r14
je 0x200043
sete %bpl
movq %r14, %rdi
callq 0xe7b9c
shrq %rax
cmpq %r15, %rax
cmovaeq %r15, %rax
movq %rax, 0x30(%rsp)
leaq 0x1(,%rax,2), %rdi
leaq 0x1bc3ca(%rip), %rsi    # 0x3bc3d4
movl $0x136, %edx            # imm = 0x136
callq 0x104226
movq %rax, (%rsp)
movq %r14, 0x10(%rsp)
movq %r14, %rdi
callq 0xebcd9
movq %rax, %rcx
testq %r13, %r13
sete %al
orb %bpl, %al
je 0x20004a
xorl %ebp, %ebp
movq 0x10(%rsp), %r14
movq (%rsp), %rcx
jmp 0x2002fc
xorl %ecx, %ecx
jmp 0x2002fc
movq %r13, %r12
movq %rbx, 0x18(%rsp)
movl 0xc(%rsp), %eax
movq %rax, 0x70(%rsp)
xorl %r14d, %r14d
movq %rcx, 0x28(%rsp)
movq 0x30(%rsp), %rbx
movq (%rsp), %rcx
xorl %edi, %edi
movq %rcx, %rsi
movq 0x10(%rsp), %r13
movq %r13, %rdx
movq %rbx, %rcx
callq 0x200415
movq (%rsp), %rcx
testq %rcx, %rcx
je 0x20033f
movq %rax, %r15
leaq (%rcx,%rax), %rbp
incq %rbp
movb $-0x1, (%rcx,%rax)
movl $0x1, %edi
movq %rbp, %rsi
movq %r13, %rdx
movq %rbx, %rcx
callq 0x200415
movq %rax, %r13
movq 0x70(%rsp), %rcx
cmpq %rcx, %rax
setb %al
cmpq %rcx, %r15
setb %cl
orb %al, %cl
movq (%rsp), %rcx
jne 0x2002e9
cmpb $-0x1, (%rcx)
je 0x2002e9
cmpb $-0x1, (%rbp)
je 0x2002e9
cmpb $-0x1, -0x1(%rcx,%rbx)
je 0x2002e9
leaq (%rcx,%r15), %rax
cmpb $-0x1, (%rax,%rbx)
je 0x2002e9
movl 0xc(%rsp), %ebx
movq 0x40(%rsp), %rdi
leaq 0x1bc301(%rip), %rsi    # 0x3bc40c
movq %r15, %rdx
movq %r13, %rcx
movl %ebx, %r8d
xorl %eax, %eax
callq 0x103fe1
movl $0x20, %edi
callq 0xd214c
movq (%rsp), %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r13, %rcx
movl %ebx, %r8d
movq 0x28(%rsp), %r9
movq 0x40(%rsp), %r10
pushq 0x18(%rsp)
movq %r10, %rbx
pushq %r10
movq %rax, 0x48(%rsp)
pushq %rax
leaq 0x362(%rip), %rax       # 0x2004b7
pushq %rax
callq 0x1a4168
addq $0x20, %rsp
testl %eax, %eax
jne 0x200330
movq %rbx, %rdi
leaq 0x1bc2d5(%rip), %rsi    # 0x3bc446
movq %r15, %rdx
movq %r13, %rcx
movl 0xc(%rsp), %r8d
xorl %eax, %eax
callq 0x103fe1
movl $0x20, %edi
callq 0xd214c
movq %rax, 0x48(%rsp)
movq %r15, 0x50(%rsp)
movq %r13, 0x60(%rsp)
movq $0x1, 0x68(%rsp)
testq %r13, %r13
je 0x2001ce
movl $0x1, %eax
xorl %ecx, %ecx
cmpb $-0x1, (%rbp,%rcx)
jne 0x2001c0
incq %rax
movq %rax, 0x68(%rsp)
incq %rcx
cmpq %rcx, %r13
jne 0x2001b1
cmpq $0x1, %rax
jne 0x2001d2
xorl %eax, %eax
jmp 0x200205
leaq -0x8(,%rax,8), %rdi
leaq 0x1bc1f3(%rip), %rsi    # 0x3bc3d4
movl $0x103, %edx            # imm = 0x103
callq 0x104226
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $-0x1, (%rbp,%rdx)
jne 0x2001fd
movq %rdx, (%rax,%rcx,8)
incq %rcx
incq %rdx
cmpq %rdx, %r13
jne 0x2001ef
movq %rax, 0x58(%rsp)
leaq (%r15,%r13), %rbx
incq %rbx
movq 0x10(%rsp), %rdi
callq 0xebcb6
movl %eax, %r8d
movl $0x1, %edi
movq (%rsp), %rsi
movq %rbx, %rdx
xorl %ecx, %ecx
movq 0x18(%rsp), %r9
callq 0x1f3507
testq %rax, %rax
je 0x200329
movq %rax, %rbx
movq %rax, %rdi
movl 0xc(%rsp), %esi
leaq 0x2ce(%rip), %rdx       # 0x20051e
leaq 0x48(%rsp), %rcx
movq 0x18(%rsp), %r8
callq 0x1a2ead
movl %eax, 0x24(%rsp)
movq %rbx, %rdi
callq 0x1f3647
cmpl $0x0, 0x24(%rsp)
jne 0x200330
movq 0x38(%rsp), %rdi
leaq 0x35d(%rip), %rbx       # 0x2005df
movq %rbx, %rsi
callq 0xd252d
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0xd252d
movq 0x48(%rsp), %rsi
movq 0x38(%rsp), %rdi
movq %rdi, %rbx
leaq 0x334(%rip), %rdx       # 0x2005df
callq 0xd2630
testb %al, %al
je 0x200344
movq 0x58(%rsp), %rdi
leaq 0x1bc110(%rip), %rsi    # 0x3bc3d4
movl $0x185, %edx            # imm = 0x185
callq 0x1045eb
movq %rbx, %rdi
callq 0xd2938
movq 0x48(%rsp), %rdi
callq 0xd2938
movq 0x30(%rsp), %rbx
movq (%rsp), %rcx
incq %r14
cmpq %r12, %r14
jb 0x20006c
xorl %ebp, %ebp
movq 0x10(%rsp), %r14
leaq 0x1bc0d1(%rip), %rsi    # 0x3bc3d4
movq %rcx, %rdi
movl $0x189, %edx            # imm = 0x189
callq 0x1045eb
movq %r14, %rdi
callq 0xea375
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %edi, %edi
callq 0x1f3647
movq 0x10(%rsp), %r14
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x20003a
callq 0x7f18a
movq 0x2b8c35(%rip), %rax    # 0x4b8f80
movq (%rax), %rdi
movq %rax, %r14
leaq 0x1bc127(%rip), %rsi    # 0x3bc47f
movq %r13, %rdx
xorl %eax, %eax
callq 0x17ab0
movq (%r14), %rcx
leaq 0x1bc134(%rip), %rdi    # 0x3bc4a0
movl $0xd, %esi
movl $0x1, %edx
callq 0x17fa0
leaq 0x2a1(%rip), %r14       # 0x200623
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
movq 0x18(%rsp), %r12
movq %r12, %rcx
callq 0xd26d4
movq 0x2b8be2(%rip), %rbx    # 0x4b8f80
movq (%rbx), %rcx
leaq 0x1bc106(%rip), %rdi    # 0x3bc4ae
movl $0xa, %esi
movl $0x1, %edx
callq 0x17fa0
movq 0x48(%rsp), %rdi
movq %r14, %rsi
xorl %edx, %edx
movq %r12, %rcx
callq 0xd26d4
movq (%rbx), %rdi
leaq 0x1bc0e6(%rip), %rsi    # 0x3bc4b9
movl $0x3c, %r9d
movq 0x28(%rsp), %r14
movq %r14, %rdx
movq (%rsp), %rcx
movq %r15, %r8
callq 0x198a58
movq (%rbx), %rdi
leaq 0x1bc0c8(%rip), %rsi    # 0x3bc4bf
movl $0x3c, %r9d
movq %r14, %rdx
movq %rbp, %rcx
movq %r13, %r8
callq 0x198a58
movl $0x2, %edi
callq 0x17940