// File: /workspace/github_c_makefile_star2_O2/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 $0x58, %rsp
movq %r9, %r10
movq %rdx, %r11
movl %r8d, %r9d
movl %r11d, 0x20(%rsp)
movq %rcx, 0x10(%rsp)
movl %ecx, 0x24(%rsp)
cmpq %r10, %r9
ja 0x142736
movq 0xa0(%rsp), %rax
testq %rax, %rax
je 0x142736
movl %r8d, %r14d
movq %rsi, %rbx
movq 0xc8(%rsp), %r12
movq 0x98(%rsp), %r13
pushq $0x1
popq %rcx
cmpq %rcx, %rax
je 0x1423dc
movl 0x4(%r13,%rcx,8), %edx
cmpl %edx, -0x4(%r13,%rcx,8)
jb 0x1423d7
jne 0x14269f
movl -0x8(%r13,%rcx,8), %edx
cmpl (%r13,%rcx,8), %edx
ja 0x14269f
incq %rcx
jmp 0x1423b0
movq (%r13), %rcx
movq %rcx, (%rsp)
testq %rbx, %rbx
je 0x1423ee
andq $0x0, 0x10(%rbx)
leaq (,%rax,8), %r15
addq %r13, %r15
decl %r14d
xorl %esi, %esi
movzbl %dil, %edi
movq $0x0, 0x8(%rsp)
movq %r9, 0x28(%rsp)
movl %edi, 0x1c(%rsp)
movq %rcx, %rdx
shrq $0x20, %rdx
movl (%rsp), %ebp
addq $0x8, %r13
movq %r9, %rax
cmpq %r15, %r13
jae 0x142500
testb $0x1, %sil
jne 0x142500
cmpl %edx, 0x4(%r13)
jne 0x14247c
leal 0x1(%rcx), %r8d
movl (%r13), %esi
cmpl %esi, %r8d
jne 0x142450
incq %rax
jmp 0x14246e
leal (%r14,%rcx), %r8d
cmpl %esi, %r8d
jb 0x14247c
movl %esi, %r8d
subl %ecx, %r8d
jb 0x1426cd
incl %r8d
addq %r8, %rax
movl %esi, %r8d
addq $0x8, %r13
xorl %esi, %esi
movl %r8d, %ebp
movl %r8d, %ecx
jmp 0x142425
movl %ebp, (%rsp)
subq $0x8, %rsp
movq %r11, %rbp
movq %r11, %rsi
movq 0x18(%rsp), %rdx
movq %rbx, %rcx
movq 0x98(%rsp), %r8
leaq 0x8(%rsp), %r9
pushq %r12
movq %r10, %r12
pushq %r10
pushq %rax
callq 0x1428ae
addq $0x20, %rsp
testb %al, %al
je 0x1424da
incq 0x8(%rsp)
cmpq $0x0, 0xb0(%rsp)
je 0x1424da
movq 0xb8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x142764
movb $0x1, %sil
jmp 0x1424dc
xorl %esi, %esi
movq %r12, %r10
movq %rbp, %r11
movq (%r13), %rcx
movq %rcx, (%rsp)
movq 0x28(%rsp), %r9
movq 0xc8(%rsp), %r12
movl 0x1c(%rsp), %edi
jmp 0x142414
movl %ebp, (%rsp)
testb $0x1, %sil
je 0x142513
movq 0xa8(%rsp), %r14
jmp 0x142570
subq $0x8, %rsp
leaq 0x8(%rsp), %r9
movq %r11, %rsi
movq 0x18(%rsp), %rdx
movq %rbx, %rcx
movq 0x98(%rsp), %r8
pushq %r12
pushq %r10
pushq %rax
callq 0x1428ae
addq $0x20, %rsp
testb %al, %al
movq 0xa8(%rsp), %r14
je 0x142570
movq 0x8(%rsp), %r15
incq %r15
cmpq $0x0, 0xb0(%rsp)
je 0x142575
movq 0xb8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x142764
jmp 0x142575
movq 0x8(%rsp), %r15
testq %r14, %r14
je 0x142588
addq %r15, 0x20(%r14)
cmpq %r15, 0x38(%r14)
jae 0x142588
movq %r15, 0x38(%r14)
testq %rbx, %rbx
movq 0xc0(%rsp), %rbp
je 0x142690
movq 0x10(%rbx), %rsi
cmpq $0x2, %rsi
jb 0x1425b5
movq (%rbx), %rdi
leaq 0x479(%rip), %rcx       # 0x142a26
pushq $0xc
popq %rdx
callq 0x17ed0
testq %rbp, %rbp
je 0x142690
callq 0x137715
movq %rax, %r14
movq 0x10(%rbx), %rdi
callq 0x136044
movq %rax, %r15
movq (%rbx), %rcx
pushq $-0x1
popq %rax
leaq 0x30(%rsp), %r12
movq %rcx, %r13
imulq $0xc, 0x10(%rbx), %rdx
addq %rcx, %rdx
cmpq %rdx, %r13
jae 0x142646
movl (%r13), %edx
movl 0x8(%r13), %ecx
movl %edx, %esi
subl %ecx, %esi
incl %esi
movq %rsi, 0x30(%rsp)
movq %rdx, 0x40(%rsp)
movl 0x4(%r13), %esi
movl %esi, %edx
subl %ecx, %edx
incl %edx
movq %rdx, 0x38(%rsp)
movq %rsi, 0x48(%rsp)
cmpq $-0x1, %rax
je 0x142628
cmpq %rdx, %rax
ja 0x1426fe
movq %rcx, 0x50(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x136157
movq 0x38(%rsp), %rax
addq $0xc, %r13
movq (%rbx), %rcx
jmp 0x1425e0
subq $0x20, %rsp
leaq 0x40(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x45c(%rip), %rax       # 0x142ab7
andq $0x0, 0x10(%rsp)
movq %rax, (%rsp)
pushq $0x1
popq %r8
movq %rbp, %rdi
movq %r14, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
movl %r8d, %r9d
callq 0x1362f6
addq $0x20, %rsp
movq %r15, %rdi
callq 0x13609e
movq %r14, %rdi
callq 0x137737
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x2f58c2(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1a2963(%rip), %rsi    # 0x2e5013
leaq 0x1ff23f(%rip), %rdx    # 0x3418f6
leaq 0x1ff215(%rip), %rcx    # 0x3418d3
leaq 0x1fd7f7(%rip), %r8     # 0x33febc
movl $0xbb3, %r9d            # imm = 0xBB3
jmp 0x14272a
movl %ebp, (%rsp)
movq 0x2f5891(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1a2932(%rip), %rsi    # 0x2e5013
leaq 0x1ff2cc(%rip), %rdx    # 0x3419b4
leaq 0x1ff1e4(%rip), %rcx    # 0x3418d3
leaq 0x1fd7c6(%rip), %r8     # 0x33febc
movl $0xbc9, %r9d            # imm = 0xBC9
jmp 0x14272a
movq 0x2f5863(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1a2904(%rip), %rsi    # 0x2e5013
leaq 0x1ff2bd(%rip), %rdx    # 0x3419d3
leaq 0x1ff1b6(%rip), %rcx    # 0x3418d3
leaq 0x1fd798(%rip), %r8     # 0x33febc
movl $0xc2f, %r9d            # imm = 0xC2F
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x2f582b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x1a28cc(%rip), %rsi    # 0x2e5013
leaq 0x1ff14a(%rip), %rdx    # 0x341898
leaq 0x1ff17e(%rip), %rcx    # 0x3418d3
leaq 0x1fd760(%rip), %r8     # 0x33febc
movl $0xbad, %r9d            # imm = 0xBAD
jmp 0x14272a