// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r8, 0x10(%rsp)
movl %r8d, %eax
movq %rdx, 0x28(%rsp)
movl %edx, 0x38(%rsp)
movq %rcx, 0x8(%rsp)
movl %ecx, 0x3c(%rsp)
movq %r9, 0x30(%rsp)
movq %rax, 0x18(%rsp)
cmpq %r9, %rax
ja 0x1a0bcd
movq 0xb0(%rsp), %rax
testq %rax, %rax
je 0x1a0bcd
movq %rsi, %rbx
movq 0xa8(%rsp), %r12
cmpq $0x2, %rax
jb 0x1a0903
movl $0x1, %ecx
movl 0x4(%r12,%rcx,8), %edx
cmpl %edx, -0x4(%r12,%rcx,8)
jb 0x1a08fb
jne 0x1a0bc3
movl -0x8(%r12,%rcx,8), %edx
cmpl (%r12,%rcx,8), %edx
ja 0x1a0bc3
incq %rcx
cmpq %rcx, %rax
jne 0x1a08da
movq (%r12), %rcx
movq %rcx, (%rsp)
testq %rbx, %rbx
je 0x1a0918
movq $0x0, 0x10(%rbx)
cmpq $0x2, %rax
movl %edi, 0x24(%rsp)
jl 0x1a0a1d
leaq (%r12,%rax,8), %rbp
movq 0x10(%rsp), %rax
decl %eax
movq %rax, 0x10(%rsp)
addq $0x10, %r12
xorl %r14d, %r14d
movzbl %dil, %r13d
movq 0x18(%rsp), %rax
xorl %r15d, %r15d
movl 0x4(%rsp), %ecx
movl -0x4(%r12), %edx
cmpl %edx, %ecx
jne 0x1a0989
movl (%rsp), %esi
incl %esi
cmpl -0x8(%r12), %esi
jne 0x1a096d
incq %rax
movl %esi, (%rsp)
jmp 0x1a09f4
cmpl %edx, %ecx
jne 0x1a0989
movl (%rsp), %edx
movq 0x10(%rsp), %rcx
leal (%rcx,%rdx), %esi
movl -0x8(%r12), %ecx
cmpl %ecx, %esi
jae 0x1a0a09
subq $0x8, %rsp
movl %r13d, %edi
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq 0xa8(%rsp), %r8
leaq 0x8(%rsp), %r9
pushq 0xe0(%rsp)
pushq 0x40(%rsp)
pushq %rax
callq 0x1a0cc5
addq $0x20, %rsp
testb %al, %al
je 0x1a09e6
incq %r14
cmpq $0x0, 0xc0(%rsp)
je 0x1a09e6
movq 0xc8(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1a0bd7
movb $0x1, %r15b
movq -0x8(%r12), %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rax
cmpq %rbp, %r12
jae 0x1a0a28
addq $0x8, %r12
testb $0x1, %r15b
je 0x1a0949
jmp 0x1a0a28
movl %ecx, %esi
subl %edx, %esi
jb 0x1a0bd2
incl %esi
addq %rsi, %rax
movl %ecx, (%rsp)
jmp 0x1a09f4
xorl %r14d, %r14d
movq 0x18(%rsp), %rax
xorl %r15d, %r15d
movq 0xb8(%rsp), %r12
testb $0x1, %r15b
jne 0x1a0a92
subq $0x8, %rsp
movzbl 0x2c(%rsp), %edi
leaq 0x8(%rsp), %r9
movq 0x30(%rsp), %rsi
movq 0x10(%rsp), %rdx
movq %rbx, %rcx
movq 0xa8(%rsp), %r8
pushq 0xe0(%rsp)
pushq 0x40(%rsp)
pushq %rax
callq 0x1a0cc5
addq $0x20, %rsp
testb %al, %al
je 0x1a0a92
incq %r14
cmpq $0x0, 0xc0(%rsp)
je 0x1a0a92
movq 0xc8(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x1a0bd7
testq %r12, %r12
je 0x1a0aa8
addq %r14, 0x20(%r12)
cmpq %r14, 0x38(%r12)
jae 0x1a0aa8
movq %r14, 0x38(%r12)
testq %rbx, %rbx
je 0x1a0bb4
movq 0xd0(%rsp), %r14
movq 0x10(%rbx), %rsi
cmpq $0x2, %rsi
jb 0x1a0ad7
movq (%rbx), %rdi
leaq 0x345(%rip), %rcx       # 0x1a0e12
movl $0xc, %edx
callq 0x17f60
testq %r14, %r14
je 0x1a0bb4
callq 0x1968ac
movq %rax, %r15
movq 0x10(%rbx), %rdi
callq 0x194f08
movq %rax, %r12
cmpq $0x0, 0x10(%rbx)
jle 0x1a0b6f
movq (%rbx), %rbp
movq $-0x1, %rax
leaq 0x40(%rsp), %r13
movl (%rbp), %edx
movl 0x8(%rbp), %ecx
movl %edx, %esi
subl %ecx, %esi
incl %esi
movq %rsi, 0x40(%rsp)
movq %rdx, 0x50(%rsp)
movl 0x4(%rbp), %esi
movl %esi, %edx
subl %ecx, %edx
incl %edx
movq %rdx, 0x48(%rsp)
movq %rsi, 0x58(%rsp)
cmpq $-0x1, %rax
je 0x1a0b42
cmpq %rdx, %rax
ja 0x1a0bc8
movq %rcx, 0x60(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x194ff7
movq 0x48(%rsp), %rax
addq $0xc, %rbp
movq 0x10(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x2, %rcx
addq (%rbx), %rcx
cmpq %rcx, %rbp
jb 0x1a0b0a
subq $0x8, %rsp
leaq 0x40(%rsp), %rax
leaq 0x2f0(%rip), %r10       # 0x1a0e6f
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
xorl %ecx, %ecx
movl $0x1, %r8d
movl $0x1, %r9d
pushq $0x0
pushq %rax
pushq %r10
callq 0x195127
addq $0x20, %rsp
movq %r12, %rdi
callq 0x194f6e
movq %r15, %rdi
callq 0x1968d3
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x5f468
callq 0x5f4da
callq 0x5f513
callq 0x5f4a1