// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/match/diagbandseed.c
// Function: gt_diagbandseed_segment2maxmatches
static void gt_diagbandseed_segment2maxmatches(
             bool forward,
             GtArrayGtDiagbandseedMaximalmatch *memstore,
             GtUword aseqnum,
             GtUword bseqnum,
             unsigned int seedlength,
             GtUword userdefinedleastlength,
             GtUword amaxlen,
             const GtSeedpairPositions *segment_positions,
             GtUword segment_length,
             GtDiagbandseedState *dbs_state,
             GtSegmentRejectFunc segment_reject_func,
             GtSegmentRejectInfo *segment_reject_info,
             const GtChain2Dimmode *chainmode,
             FILE *fpout)
{
  GtUword previous_matchlength = seedlength, localmatchcount = 0;
  const GtSeedpairPositions *current;
  GtSeedpairPositions previous;
  GtDiagbandseedSequencePair sequencepair = {aseqnum,bseqnum};
  const bool anchor_pairs = false;
  bool rejected = false;
#ifndef NDEBUG
  GtUword idx;
#endif

  gt_assert(segment_length > 0 && seedlength <= userdefinedleastlength);
#ifndef NDEBUG
  for (idx = 1; idx < segment_length; idx++)
  {
    gt_assert(segment_positions[idx-1].bpos < segment_positions[idx].bpos ||
              (segment_positions[idx-1].bpos == segment_positions[idx].bpos &&
               segment_positions[idx-1].apos <= segment_positions[idx].apos));
  }
#endif
  previous = segment_positions[0];
  if (memstore != NULL)
  {
    memstore->nextfreeGtDiagbandseedMaximalmatch = 0;
  }
  for (current = segment_positions + 1;
       current < segment_positions + segment_length && !rejected; current++)
  {
    if (previous.bpos == current->bpos && previous.apos + 1 == current->apos)
    {
      previous_matchlength++;
      previous.apos++;
    } else
    {
      if (previous.bpos == current->bpos &&
          previous.apos + seedlength - 1 >= current->apos)
      {
        /* This case can only happen if maxfreq exclude some intermediate
           matches */
        gt_assert(previous.apos <= current->apos);
        previous_matchlength += (current->apos - previous.apos + 1);
        previous.apos = current->apos;
      } else
      {
        /*
        printf("previous.diag = %u, current.diag=%u\n",previous.bpos,
                current->bpos);
        printf("previous.apos=%u,current.apos=%u,seedlength=%u\n",
                previous.apos,current->apos,seedlength);
        gt_assert (previous.bpos != current->bpos ||
                   previous.apos + seedlength - 1 < current->apos);*/
        if (anchor_pairs)
        {
          if (previous.bpos == current->bpos &&
              previous.apos + seedlength - 1 < current->apos)
          {
            printf("A %u\n",previous.apos+1);
          }
        } else
        {
          if (gt_diagbandseed_process_mem(forward,
                                          aseqnum,
                                          bseqnum,
                                          memstore,
                                          amaxlen,
                                          &previous,
                                          previous_matchlength,
                                          userdefinedleastlength,
                                          fpout))
          {
            localmatchcount++;
            if (segment_reject_func != NULL)
            {
              gt_segment_reject_register_match(segment_reject_info,bseqnum);
              rejected = true;
            }
          }
        }
        previous_matchlength = seedlength;
        previous = *current;
      }
    }
  }
  if (!anchor_pairs)
  {
    if (!rejected && gt_diagbandseed_process_mem(forward,
                                                 aseqnum,
                                                 bseqnum,
                                                 memstore,
                                                 amaxlen,
                                                 &previous,
                                                 previous_matchlength,
                                                 userdefinedleastlength,
                                                 fpout))
    {
      localmatchcount++;
      if (segment_reject_func != NULL)
      {
        gt_segment_reject_register_match(segment_reject_info,bseqnum);
      }
    }
  }
  if (dbs_state != NULL)
  {
    dbs_state->countmatches += localmatchcount;
    if (dbs_state->maxmatchespersegment < localmatchcount)
    {
      dbs_state->maxmatchespersegment = localmatchcount;
    }
  }
  if (memstore != NULL)
  {
    if (memstore->nextfreeGtDiagbandseedMaximalmatch >= 2)
    {
      qsort(memstore->spaceGtDiagbandseedMaximalmatch,
            memstore->nextfreeGtDiagbandseedMaximalmatch,
            sizeof *memstore->spaceGtDiagbandseedMaximalmatch,
            gt_diagbandseed_bstart_ldesc_compare_mems);
    }
    if (chainmode != NULL)
    {
      const GtUword presortdim = 1;
#ifndef NDEBUG
      GtUword previous_start_b = GT_UWORD_MAX;
#endif
      GtChain2Dimmatchvalues inmatch;
      GtChain2Dim *localchain = gt_chain_chain_new();
      GtDiagbandseedMaximalmatch *mmptr;
      GtChain2Dimmatchtable *chainmatchtable
        = gt_chain_matchtable_new(memstore->nextfreeGtDiagbandseedMaximalmatch);

      for (mmptr = memstore->spaceGtDiagbandseedMaximalmatch;
           mmptr < memstore->spaceGtDiagbandseedMaximalmatch +
                   memstore->nextfreeGtDiagbandseedMaximalmatch;
           mmptr++)
      {
        inmatch.startpos[0] = mmptr->apos + 1 - mmptr->len;
        inmatch.endpos[0] = mmptr->apos;
        inmatch.startpos[1] = mmptr->bpos + 1 - mmptr->len;
        inmatch.endpos[1] = mmptr->bpos;
        gt_assert(previous_start_b == GT_UWORD_MAX ||
                  previous_start_b <= inmatch.startpos[1]);
        inmatch.weight = mmptr->len;
        gt_chain_matchtable_add(chainmatchtable,&inmatch);
#ifndef NDEBUG
        previous_start_b = inmatch.startpos[1];
#endif
      }
      gt_chain_fastchaining(chainmode,
                            localchain,
                            chainmatchtable,
                            false,
                            presortdim,
                            true,
                            gt_diagbandseed_chain_out,
                            &sequencepair,
                            NULL);
      gt_chain_matchtable_delete(chainmatchtable);
      gt_chain_chain_delete(localchain);
    }
  }
}

// Assembly:
subq $0xd8, %rsp
movb %dil, %al
movq 0x118(%rsp), %rdi
movq 0x110(%rsp), %rdi
movq 0x108(%rsp), %rdi
movq 0x100(%rsp), %rdi
movq 0xf8(%rsp), %rdi
movq 0xf0(%rsp), %rdi
movq 0xe8(%rsp), %rdi
movq 0xe0(%rsp), %rdi
andb $0x1, %al
movb %al, 0xd7(%rsp)
movq %rsi, 0xc8(%rsp)
movq %rdx, 0xc0(%rsp)
movq %rcx, 0xb8(%rsp)
movl %r8d, 0xb4(%rsp)
movq %r9, 0xa8(%rsp)
movl 0xb4(%rsp), %eax
movq %rax, 0xa0(%rsp)
movq $0x0, 0x98(%rsp)
movq 0xc0(%rsp), %rax
movl %eax, 0x80(%rsp)
movq 0xb8(%rsp), %rax
movl %eax, 0x84(%rsp)
movb $0x0, 0x7f(%rsp)
movb $0x0, 0x7e(%rsp)
cmpq $0x0, 0xf0(%rsp)
jbe 0x21c4ba
movl 0xb4(%rsp), %eax
cmpq 0xa8(%rsp), %rax
jbe 0x21c4f2
movq 0x41fadf(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2f9b48(%rip), %rsi    # 0x516013
leaq 0x357701(%rip), %rdx    # 0x573bd3
leaq 0x357735(%rip), %rcx    # 0x573c0e
leaq 0x355ab4(%rip), %r8     # 0x571f94
movl $0xbad, %r9d            # imm = 0xBAD
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x21c4f4
movq $0x1, 0x70(%rsp)
movq 0x70(%rsp), %rax
cmpq 0xf0(%rsp), %rax
jae 0x21c5db
jmp 0x21c512
movq 0xe8(%rsp), %rax
movq 0x70(%rsp), %rcx
subq $0x1, %rcx
movl 0x4(%rax,%rcx,8), %eax
movq 0xe8(%rsp), %rcx
movq 0x70(%rsp), %rdx
cmpl 0x4(%rcx,%rdx,8), %eax
jb 0x21c5c4
movq 0xe8(%rsp), %rax
movq 0x70(%rsp), %rcx
subq $0x1, %rcx
movl 0x4(%rax,%rcx,8), %eax
movq 0xe8(%rsp), %rcx
movq 0x70(%rsp), %rdx
cmpl 0x4(%rcx,%rdx,8), %eax
jne 0x21c58c
movq 0xe8(%rsp), %rax
movq 0x70(%rsp), %rcx
subq $0x1, %rcx
movl (%rax,%rcx,8), %eax
movq 0xe8(%rsp), %rcx
movq 0x70(%rsp), %rdx
cmpl (%rcx,%rdx,8), %eax
jbe 0x21c5c4
movq 0x41fa0d(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2f9a76(%rip), %rsi    # 0x516013
leaq 0x35768d(%rip), %rdx    # 0x573c31
leaq 0x357663(%rip), %rcx    # 0x573c0e
leaq 0x3559e2(%rip), %r8     # 0x571f94
movl $0xbb3, %r9d            # imm = 0xBB3
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x21c5c6
jmp 0x21c5c8
movq 0x70(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x70(%rsp)
jmp 0x21c4fd
movq 0xe8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x88(%rsp)
cmpq $0x0, 0xc8(%rsp)
je 0x21c609
movq 0xc8(%rsp), %rax
movq $0x0, 0x10(%rax)
movq 0xe8(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rcx
movq 0xe8(%rsp), %rdx
movq 0xf0(%rsp), %rax
shlq $0x3, %rax
addq %rax, %rdx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, 0x1f(%rsp)
jae 0x21c651
movb 0x7e(%rsp), %al
xorb $-0x1, %al
movb %al, 0x1f(%rsp)
movb 0x1f(%rsp), %al
testb $0x1, %al
jne 0x21c65e
jmp 0x21c859
movl 0x8c(%rsp), %eax
movq 0x90(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x21c6b2
movl 0x88(%rsp), %eax
addl $0x1, %eax
movq 0x90(%rsp), %rcx
cmpl (%rcx), %eax
jne 0x21c6b2
movq 0xa0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0xa0(%rsp)
movl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x88(%rsp)
jmp 0x21c83e
movl 0x8c(%rsp), %eax
movq 0x90(%rsp), %rcx
cmpl 0x4(%rcx), %eax
jne 0x21c776
movl 0x88(%rsp), %eax
addl 0xb4(%rsp), %eax
subl $0x1, %eax
movq 0x90(%rsp), %rcx
cmpl (%rcx), %eax
jb 0x21c776
jmp 0x21c6ed
movl 0x88(%rsp), %eax
movq 0x90(%rsp), %rcx
cmpl (%rcx), %eax
jbe 0x21c738
movq 0x41f899(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2f9902(%rip), %rsi    # 0x516013
leaq 0x3575d7(%rip), %rdx    # 0x573cef
leaq 0x3574ef(%rip), %rcx    # 0x573c0e
leaq 0x35586e(%rip), %r8     # 0x571f94
movl $0xbc9, %r9d            # imm = 0xBC9
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x21c73a
movq 0x90(%rsp), %rax
movl (%rax), %eax
subl 0x88(%rsp), %eax
addl $0x1, %eax
movl %eax, %eax
addq 0xa0(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq 0x90(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x88(%rsp)
jmp 0x21c83c
movb 0xd7(%rsp), %dil
movq 0xc0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xc8(%rsp), %rcx
movq 0xe0(%rsp), %r8
movq 0xa0(%rsp), %r11
movq 0xa8(%rsp), %r10
movq 0x118(%rsp), %rax
leaq 0x88(%rsp), %r9
andb $0x1, %dil
movzbl %dil, %edi
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x21dbd0
testb $0x1, %al
jne 0x21c7df
jmp 0x21c81a
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x100(%rsp)
je 0x21c818
movq 0x108(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x21d830
movb $0x1, 0x7e(%rsp)
jmp 0x21c81a
movl 0xb4(%rsp), %eax
movq %rax, 0xa0(%rsp)
movq 0x90(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x88(%rsp)
jmp 0x21c83e
jmp 0x21c840
movq 0x90(%rsp), %rax
addq $0x8, %rax
movq %rax, 0x90(%rsp)
jmp 0x21c61d
testb $0x1, 0x7e(%rsp)
jne 0x21c903
movb 0xd7(%rsp), %dil
movq 0xc0(%rsp), %rsi
movq 0xb8(%rsp), %rdx
movq 0xc8(%rsp), %rcx
movq 0xe0(%rsp), %r8
movq 0xa0(%rsp), %r11
movq 0xa8(%rsp), %r10
movq 0x118(%rsp), %rax
leaq 0x88(%rsp), %r9
andb $0x1, %dil
movzbl %dil, %edi
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x21dbd0
testb $0x1, %al
jne 0x21c8cd
jmp 0x21c903
movq 0x98(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x98(%rsp)
cmpq $0x0, 0x100(%rsp)
je 0x21c901
movq 0x108(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x21d830
jmp 0x21c903
cmpq $0x0, 0xf8(%rsp)
je 0x21c952
movq 0x98(%rsp), %rcx
movq 0xf8(%rsp), %rax
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq 0xf8(%rsp), %rax
movq 0x38(%rax), %rax
cmpq 0x98(%rsp), %rax
jae 0x21c950
movq 0x98(%rsp), %rcx
movq 0xf8(%rsp), %rax
movq %rcx, 0x38(%rax)
jmp 0x21c952
cmpq $0x0, 0xc8(%rsp)
je 0x21cb41
movq 0xc8(%rsp), %rax
cmpq $0x2, 0x10(%rax)
jb 0x21c998
movq 0xc8(%rsp), %rax
movq (%rax), %rdi
movq 0xc8(%rsp), %rax
movq 0x10(%rax), %rsi
movl $0xc, %edx
leaq 0x14ed(%rip), %rcx      # 0x21de80
callq 0x19e70
cmpq $0x0, 0x110(%rsp)
je 0x21cb3f
movq $0x1, 0x68(%rsp)
movq $-0x1, 0x60(%rsp)
callq 0x209190
movq %rax, 0x30(%rsp)
movq 0xc8(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x207510
movq %rax, 0x20(%rsp)
movq 0xc8(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movq 0xc8(%rsp), %rcx
movq (%rcx), %rcx
movq 0xc8(%rsp), %rdx
imulq $0xc, 0x10(%rdx), %rdx
addq %rdx, %rcx
cmpq %rcx, %rax
jae 0x21cae5
movq 0x28(%rsp), %rax
movl (%rax), %eax
addl $0x1, %eax
movq 0x28(%rsp), %rcx
subl 0x8(%rcx), %eax
movl %eax, %eax
movq %rax, 0x38(%rsp)
movq 0x28(%rsp), %rax
movl (%rax), %eax
movq %rax, 0x48(%rsp)
movq 0x28(%rsp), %rax
movl 0x4(%rax), %eax
addl $0x1, %eax
movq 0x28(%rsp), %rcx
subl 0x8(%rcx), %eax
movl %eax, %eax
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rax
movl 0x4(%rax), %eax
movq %rax, 0x50(%rsp)
cmpq $-0x1, 0x60(%rsp)
je 0x21caaa
movq 0x60(%rsp), %rax
cmpq 0x40(%rsp), %rax
jbe 0x21caaa
movq 0x41f527(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x2f9590(%rip), %rsi    # 0x516013
leaq 0x357284(%rip), %rdx    # 0x573d0e
leaq 0x35717d(%rip), %rcx    # 0x573c0e
leaq 0x3554fc(%rip), %r8     # 0x571f94
movl $0xc2f, %r9d            # imm = 0xC2F
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x21caac
movq 0x28(%rsp), %rax
movl 0x8(%rax), %eax
movq %rax, 0x58(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x2076d0
movq 0x40(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0x28(%rsp), %rax
addq $0xc, %rax
movq %rax, 0x28(%rsp)
jmp 0x21c9e9
movq 0x110(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x20(%rsp), %rdx
xorl %ecx, %ecx
movl $0x1, %r9d
leaq 0x14ca(%rip), %r10      # 0x21dfd0
leaq 0x80(%rsp), %rax
xorl %r8d, %r8d
movl %r9d, %r8d
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movq $0x0, 0x10(%rsp)
callq 0x2079c0
movq 0x20(%rsp), %rdi
callq 0x2075d0
movq 0x30(%rsp), %rdi
callq 0x2091e0
jmp 0x21cb41
addq $0xd8, %rsp
retq
nopl (%rax)