// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/match/chain2dim.c
// Function: gt_chain2dim_evalmatchscore
static void gt_chain2dim_evalmatchscore(const GtChain2Dimmode *chainmode,
                                        GtChain2Dimmatchtable *matchtable,
                                        GtChain2DimMatchstore *matchstore,
                                        bool gapsL1,
                                        GtUword matchpointident,
                                        unsigned int presortdim)
{
  GtUword previous;
  GtChain2Dimpostype startpos2;
  GtChain2DimMatchpoint *qmatch2;
  GtChain2Dimscoretype score;

  startpos2 = GT_CHAIN2DIM_GETSTOREDSTARTPOINT(1-presortdim,matchpointident);
  if (startpos2 == 0)
  {
    qmatch2 = NULL;
  } else
  {
    GtChain2DimMatchpoint keymatch2;

    keymatch2.fpposition = startpos2 - 1;  /* it is a start position */
    keymatch2.fpident = MAKEENDPOINT(matchpointident);
                       /* but considered as endpoint */
    qmatch2 = (GtChain2DimMatchpoint *) gt_rbtree_previous_equal_key(
                                                 matchstore->dictroot,
                                                 &keymatch2,
                                                 gt_chain2dim_cmpendMatchpoint2,
                                                 NULL);
    if (qmatch2 != NULL)
    {
      if (chainmode->maxgapwidth != 0 &&
          !gt_chain2dim_checkmaxgapwidth(matchtable,
                                         chainmode->maxgapwidth,
                                         FRAGIDENT(qmatch2),
                                         matchpointident))
      {
        qmatch2 = NULL;
      }
    }
  }
  if (qmatch2 == NULL)
  {
    score = matchtable->matches[matchpointident].weight;
    if (chainmode->chainkind == GLOBALCHAININGWITHGAPCOST)
    {
      score -= GT_CHAIN2DIM_INITIALGAP(matchpointident);
    }
    previous = GT_CHAIN2DIM_UNDEFPREVIOUS;
  } else
  {
    score = matchtable->matches[FRAGIDENT(qmatch2)].score;
    if (chainmode->chainkind == GLOBALCHAINING)
    {
      score += matchtable->matches[matchpointident].weight;
      previous = FRAGIDENT(qmatch2);
    } else
    {
      GtChain2Dimscoretype tmpgc;

      if (gapsL1)
      {
        tmpgc = gapcostL1(matchtable,FRAGIDENT(qmatch2),matchpointident);
      } else
      {
        tmpgc = gapcostCc(matchtable,FRAGIDENT(qmatch2),matchpointident);
      }
      if (chainmode->chainkind == GLOBALCHAININGWITHGAPCOST || score > tmpgc)
      {
        score += (matchtable->matches[matchpointident].weight - tmpgc);
        previous = FRAGIDENT(qmatch2);
      } else
      {
        score = matchtable->matches[matchpointident].weight;
        previous = GT_CHAIN2DIM_UNDEFPREVIOUS;
      }
    }
  }
  matchtable->matches[matchpointident].score = score;
  matchtable->matches[matchpointident].previousinchain = previous;
  if (previous == GT_CHAIN2DIM_UNDEFPREVIOUS)
  {
    matchtable->matches[matchpointident].firstinchain = matchpointident;
  } else
  {
    matchtable->matches[matchpointident].firstinchain
      = matchtable->matches[previous].firstinchain;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, %rbx
movq %rsi, %r14
movq %rdi, %r15
leaq (%r8,%r8,4), %r13
shlq $0x4, %r13
movq (%rsi), %rax
addq %r13, %rax
movl $0x1, %esi
subl %r9d, %esi
movq (%rax,%rsi,8), %rax
testq %rax, %rax
je 0x196b55
movl %ecx, 0x4(%rsp)
decq %rax
leaq 0x8(%rsp), %rsi
movq %rax, 0x8(%rsi)
movq %rbx, (%rsi)
movq (%rdx), %rdi
leaq -0x7d(%rip), %rdx       # 0x196aa5
xorl %ebp, %ebp
xorl %ecx, %ecx
callq 0x16eb23
testq %rax, %rax
je 0x196b5c
movq %rax, %r12
movq 0x8(%r15), %rsi
testq %rsi, %rsi
je 0x196b59
movq (%r12), %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x196a57
xorl %ebp, %ebp
testb %al, %al
cmovneq %r12, %rbp
jmp 0x196b5c
xorl %ebp, %ebp
jmp 0x196b60
movq %r12, %rbp
movl 0x4(%rsp), %ecx
movq (%r14), %r8
movl (%r15), %edi
testq %rbp, %rbp
je 0x196b9c
movq (%rbp), %rsi
leaq (%rsi,%rsi,4), %rdx
shlq $0x4, %rdx
movq 0x48(%r8,%rdx), %r12
testl %edi, %edi
je 0x196bb3
testb %cl, %cl
je 0x196bbd
movq (%r8,%r13), %rax
addq 0x8(%r8,%r13), %rax
movq 0x10(%r8,%rdx), %rsi
addq 0x18(%r8,%rdx), %rsi
subq %rsi, %rax
jmp 0x196bc8
movq 0x30(%r8,%r13), %rax
cmpl $0x1, %edi
jne 0x196bad
addq %r13, %r8
subq 0x38(%r8), %rax
movq 0x18(%r14), %rsi
jmp 0x196bf2
addq 0x30(%r8,%r13), %r12
movq %r12, %rax
jmp 0x196bf2
movq %r14, %rdi
movq %rbx, %rdx
callq 0x196a05
cmpl $0x1, (%r15)
sete %cl
subq %rax, %r12
setg %dl
orb %cl, %dl
leaq 0x18(%r14), %rcx
xorl %eax, %eax
testb %dl, %dl
cmovneq %rbp, %rcx
cmovneq %r12, %rax
movq (%r14), %rdx
addq 0x30(%rdx,%r13), %rax
movq (%rcx), %rsi
movq (%r14), %rcx
movq %rax, 0x48(%rcx,%r13)
movq %rsi, 0x28(%rcx,%r13)
cmpq 0x18(%r14), %rsi
je 0x196c12
leaq (%rsi,%rsi,4), %rax
shlq $0x4, %rax
movq 0x20(%rcx,%rax), %rbx
movq %rbx, 0x20(%rcx,%r13)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq