// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/diagonalbandalign_affinegapcost.c
// Function: diagonalband_fillDPtab_affine
static void diagonalband_fillDPtab_affine(GtAffinealignDPentry **Atabcolumn,
                                          const GtUchar *useq,
                                          GtUword ustart,
                                          GtUword ulen,
                                          const GtUchar *vseq,
                                          GtUword vstart,
                                          GtUword vlen,
                                          GtWord left_dist,
                                          GtWord right_dist,
                                          GtAffineAlignEdge from_edge,
                                          GtAffineAlignEdge edge,
                                          const GtScoreHandler *scorehandler)
{
  GtUword i,j, low_row, high_row, gap_opening, gap_extension;
  GtWord rcost, r_dist, d_dist, i_dist, minvalue;

  gt_assert(Atabcolumn && scorehandler);
  if ((left_dist > GT_MIN(0, (GtWord)vlen-(GtWord)ulen))||
      (right_dist < GT_MAX(0, (GtWord)vlen-(GtWord)ulen)))
  {
    gt_assert(false);
  }

  gap_opening = gt_scorehandler_get_gap_opening(scorehandler);
  gap_extension = gt_scorehandler_get_gapscore(scorehandler);
  low_row = 0;
  high_row = -left_dist;

  /* first entry */
   switch (edge) {
    case Affine_R:
      Atabcolumn[0][0].Rvalue = 0;
      Atabcolumn[0][0].Redge = from_edge;
      Atabcolumn[0][0].Dvalue = GT_WORD_MAX;
      Atabcolumn[0][0].Ivalue = GT_WORD_MAX;
      break;
    case Affine_D:
      Atabcolumn[0][0].Rvalue = GT_WORD_MAX;
      Atabcolumn[0][0].Dvalue = 0;
      Atabcolumn[0][0].Dedge = from_edge;
      Atabcolumn[0][0].Ivalue = GT_WORD_MAX;
      break;
    case Affine_I:
      Atabcolumn[0][0].Rvalue = GT_WORD_MAX;
      Atabcolumn[0][0].Dvalue = GT_WORD_MAX;
      Atabcolumn[0][0].Ivalue = 0;
      Atabcolumn[0][0].Iedge = from_edge;
      break;
    default:
      Atabcolumn[0][0].Rvalue = 0;
      Atabcolumn[0][0].Dvalue = gap_opening;
      Atabcolumn[0][0].Ivalue = gap_opening;
    }
  /* first column */
  for (i = 1; i <= high_row; i++)
  {
    Atabcolumn[i][0].Rvalue = GT_WORD_MAX;
    r_dist = add_safe_max(Atabcolumn[i-1][0].Rvalue,
                         gap_opening + gap_extension);
    d_dist = add_safe_max(Atabcolumn[i-1][0].Dvalue, gap_extension);
    i_dist = add_safe_max(Atabcolumn[i-1][0].Ivalue,
                         gap_opening + gap_extension);
    Atabcolumn[i][0].Dvalue = GT_MIN3(r_dist, d_dist, i_dist);
    Atabcolumn[i][0].Ivalue = GT_WORD_MAX;

    Atabcolumn[i][0].Redge = Affine_X;
    Atabcolumn[i][0].Dedge = gt_linearalign_affinegapcost_set_edge(r_dist,
                                                                   d_dist,
                                                                   i_dist);
    Atabcolumn[i][0].Iedge = Affine_X;
  }
  for (; i <= ulen; i++)
  {
    /* invalid values */
    Atabcolumn[i][0].Rvalue = GT_WORD_MAX;
    Atabcolumn[i][0].Dvalue = GT_WORD_MAX;
    Atabcolumn[i][0].Ivalue = GT_WORD_MAX;
  }

  /* next columns */
  for (j = 1; j <= vlen; j++)
  {
    /* below diagonal band*/
    for (i = 0; i <= low_row; i++)
    {
      if (j <= right_dist)
      {
        Atabcolumn[i][j].Redge = Affine_X;
        Atabcolumn[i][j].Dedge = Affine_X;
        r_dist = add_safe_max(Atabcolumn[i][j-1].Rvalue,
                               gap_extension + gap_opening);
        d_dist = add_safe_max(Atabcolumn[i][j-1].Dvalue,
                               gap_extension + gap_opening);
        i_dist = add_safe_max(Atabcolumn[i][j-1].Ivalue,gap_extension);

        minvalue = GT_MIN3(r_dist, d_dist, i_dist);
        Atabcolumn[i][j].Ivalue = minvalue;
        Atabcolumn[i][j].Rvalue = GT_WORD_MAX;
        Atabcolumn[i][j].Dvalue = GT_WORD_MAX;

        Atabcolumn[i][j].Iedge = gt_linearalign_affinegapcost_set_edge(r_dist,
                                                         d_dist,
                                                         i_dist);
      }
      else{
        Atabcolumn[i][j].Rvalue = GT_WORD_MAX;
        Atabcolumn[i][j].Dvalue = GT_WORD_MAX;
        Atabcolumn[i][j].Ivalue = GT_WORD_MAX;
        Atabcolumn[i][j].Iedge = Affine_X;
      }
    }
    if ( j > right_dist)
      low_row++;
    if (high_row < ulen)
      high_row ++;

    /* diagonalband */
    for (; i <= high_row; i++)
    {
      /* compute A_affine(i,j,I) */
      r_dist=add_safe_max(Atabcolumn[i][j-1].Rvalue,gap_extension+gap_opening);
      d_dist=add_safe_max(Atabcolumn[i][j-1].Dvalue,gap_extension+gap_opening);
      i_dist=add_safe_max(Atabcolumn[i][j-1].Ivalue,gap_extension);
      minvalue = GT_MIN3(r_dist, d_dist, i_dist);
      Atabcolumn[i][j].Ivalue = minvalue;
      Atabcolumn[i][j].Iedge = gt_linearalign_affinegapcost_set_edge(
                                                        r_dist, d_dist, i_dist);

      /* compute A_affine(i,j,R) */
      rcost = gt_scorehandler_get_replacement(scorehandler,
                                            useq[ustart+i-1], vseq[vstart+j-1]);
      r_dist = add_safe_max(Atabcolumn[i-1][j-1].Rvalue, rcost);
      d_dist = add_safe_max(Atabcolumn[i-1][j-1].Dvalue, rcost);
      i_dist = add_safe_max(Atabcolumn[i-1][j-1].Ivalue, rcost);
      minvalue = GT_MIN3(r_dist, d_dist, i_dist);
      Atabcolumn[i][j].Rvalue = minvalue;
      Atabcolumn[i][j].Redge = gt_linearalign_affinegapcost_set_edge(
                                                        r_dist, d_dist, i_dist);

      /* compute A_affine(i,j,D) */
      r_dist = add_safe_max(Atabcolumn[i-1][j].Rvalue,
                         gap_extension+gap_opening);
      d_dist = add_safe_max(Atabcolumn[i-1][j].Dvalue,gap_extension);
      i_dist = add_safe_max(Atabcolumn[i-1][j].Ivalue,
                          gap_extension+gap_opening);
      minvalue = GT_MIN3(r_dist, d_dist, i_dist);
      Atabcolumn[i][j].Dvalue = minvalue;
      Atabcolumn[i][j].Dedge = gt_linearalign_affinegapcost_set_edge(
                                                        r_dist, d_dist, i_dist);

    }
    /* above diagonal band */
    for (; i <= ulen; i++)
    {
      Atabcolumn[i][j].Rvalue = GT_WORD_MAX;
      Atabcolumn[i][j].Dvalue = GT_WORD_MAX;
      Atabcolumn[i][j].Ivalue = GT_WORD_MAX;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
testq %rdi, %rdi
je 0x134c20
movq %rcx, %r12
movq %r8, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %r9, 0x18(%rsp)
movq %rdx, 0x10(%rsp)
movq 0x98(%rsp), %r13
movq 0x90(%rsp), %rcx
subq %r12, %rcx
movq %rcx, %rdx
sarq $0x3f, %rdx
andq %rcx, %rdx
xorl %eax, %eax
testq %rcx, %rcx
cmovgq %rcx, %rax
cmpq %r13, %rdx
jl 0x134c25
cmpq 0xa0(%rsp), %rax
jg 0x134c25
movq %rdi, %rbp
movq 0xb8(%rsp), %rbx
movl 0xb0(%rsp), %r14d
movabsq $0x7fffffffffffffff, %r15 # imm = 0x7FFFFFFFFFFFFFFF
movq %rbx, %rdi
callq 0x171427
movq %rax, (%rsp)
movq %rbx, %rdi
callq 0x171437
movq %rax, 0x8(%rsp)
movq (%rbp), %rax
cmpl $0x2, %r14d
je 0x13480a
cmpl $0x1, %r14d
jne 0x134829
movq %r15, (%rax)
movq $0x0, 0x8(%rax)
movl 0xa8(%rsp), %ecx
movl %ecx, 0x24(%rax)
movq %r15, 0x10(%rax)
jmp 0x134823
movq %r15, (%rax)
movq %r15, 0x8(%rax)
movq $0x0, 0x10(%rax)
movl 0xa8(%rsp), %ecx
movl %ecx, 0x28(%rax)
movq (%rsp), %rcx
jmp 0x13483c
movq $0x0, (%rax)
movq (%rsp), %rcx
movq %rcx, 0x8(%rax)
movq %rcx, 0x10(%rax)
movq %r12, 0x20(%rsp)
negq %r13
movq %r13, %r14
jae 0x1348d7
movq 0x8(%rsp), %rdx
leaq (%rdx,%rcx), %r12
movl $0x1, %ebx
movl $0x3, %r13d
movq (%rbp,%rbx,8), %rax
movq %r15, (%rax)
movq -0x8(%rbp,%rbx,8), %rcx
movq (%rcx), %rdx
movq 0x8(%rcx), %r8
leaq (%rdx,%r12), %rdi
cmpq %r15, %rdx
cmoveq %r15, %rdi
movq 0x8(%rsp), %rdx
leaq (%r8,%rdx), %rsi
cmpq %r15, %r8
cmoveq %r15, %rsi
movq 0x10(%rcx), %rcx
leaq (%rcx,%r12), %rdx
cmpq %r15, %rcx
cmoveq %r15, %rdx
cmpq %rsi, %rdi
movq %rsi, %rcx
cmovlq %rdi, %rcx
cmpq %rdx, %rcx
cmovgeq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq %r15, 0x10(%rax)
movl %r13d, 0x20(%rax)
callq 0x159da4
movq (%rbp,%rbx,8), %rcx
movl %eax, 0x24(%rcx)
movl %r13d, 0x28(%rcx)
incq %rbx
cmpq %r14, %rbx
jbe 0x134861
jmp 0x1348dc
movl $0x1, %ebx
movq %r14, 0x38(%rsp)
movq 0x20(%rsp), %r9
cmpq %r9, %rbx
ja 0x134900
movq (%rbp,%rbx,8), %rax
movq %r15, (%rax)
movq %r15, 0x8(%rax)
movq %r15, 0x10(%rax)
incq %rbx
jmp 0x1348e6
cmpq $0x0, 0x90(%rsp)
movq 0xa0(%rsp), %rbx
je 0x134c11
movq 0x18(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %rdx
decq %rdx
movq 0x8(%rsp), %rax
addq %rax, (%rsp)
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rcx,%rax), %rsi
decq %rsi
movl $0x1, %edi
xorl %r12d, %r12d
movq %rdx, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movq %rbp, 0x40(%rsp)
leaq -0x1(%rdi), %r9
leaq (%rdi,%rdi,2), %r14
shlq $0x4, %r14
xorl %r13d, %r13d
movq %rdi, 0x10(%rsp)
movq %r9, 0x18(%rsp)
movq (%rbp,%r13,8), %rcx
cmpq %rbx, %rdi
jbe 0x134994
movq %r15, (%rcx,%r14)
movq %r15, 0x8(%rcx,%r14)
movq %r15, 0x10(%rcx,%r14)
movl $0x3, %eax
jmp 0x134a14
movabsq $0x300000003, %rax      # imm = 0x300000003
movq %rax, 0x20(%rcx,%r14)
leaq (%r9,%r9,2), %rax
shlq $0x4, %rax
movq (%rcx,%rax), %rdx
movq 0x8(%rcx,%rax), %r8
movq (%rsp), %rsi
leaq (%rdx,%rsi), %rdi
cmpq %r15, %rdx
cmoveq %r15, %rdi
addq %r8, %rsi
cmpq %r15, %r8
cmoveq %r15, %rsi
movq 0x10(%rcx,%rax), %rax
movq 0x8(%rsp), %rdx
addq %rax, %rdx
cmpq %r15, %rax
cmoveq %r15, %rdx
cmpq %rsi, %rdi
movq %rsi, %rax
cmovlq %rdi, %rax
cmpq %rdx, %rax
cmovgeq %rdx, %rax
movq %rax, 0x10(%rcx,%r14)
movq %r15, (%rcx,%r14)
movq %r15, 0x8(%rcx,%r14)
callq 0x159da4
movq 0x18(%rsp), %r9
movq 0x10(%rsp), %rdi
movq (%rbp,%r13,8), %rcx
movl %eax, 0x28(%rcx,%r14)
incq %r13
cmpq %r12, %r13
jbe 0x134972
movq %r14, 0x48(%rsp)
cmpq %rdi, %rbx
adcq $0x0, %r12
movq %r12, 0x50(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x20(%rsp), %rax
adcq $0x0, %rax
movq %rax, 0x38(%rsp)
cmpq %rax, %r13
ja 0x134bbf
movq 0x40(%rsp), %r14
movq (%r14,%r13,8), %rax
movq %r9, %rcx
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rbx
movq (%rax,%rbx), %rcx
movq 0x8(%rax,%rbx), %rdx
movq (%rsp), %rsi
leaq (%rcx,%rsi), %rdi
cmpq %r15, %rcx
cmoveq %r15, %rdi
addq %rdx, %rsi
cmpq %r15, %rdx
cmoveq %r15, %rsi
movq 0x10(%rax,%rbx), %rcx
movq 0x8(%rsp), %rdx
addq %rcx, %rdx
cmpq %r15, %rcx
cmoveq %r15, %rdx
cmpq %rsi, %rdi
movq %rsi, %rcx
cmovlq %rdi, %rcx
cmpq %rdx, %rcx
cmovgeq %rdx, %rcx
movq 0x10(%rsp), %rbp
movq %rbp, %r8
shlq $0x4, %r8
leaq (%r8,%r8,2), %r12
movq %rcx, 0x10(%rax,%r12)
callq 0x159da4
movq (%r14,%r13,8), %rcx
movl %eax, 0x28(%rcx,%r12)
movq 0x28(%rsp), %rax
movzbl (%rax,%r13), %esi
movq 0x30(%rsp), %rax
movzbl (%rax,%rbp), %edx
movq 0xb8(%rsp), %rdi
callq 0x171466
movq -0x8(%r14,%r13,8), %rcx
movq (%r14,%r13,8), %r8
movq (%rcx,%rbx), %rdx
movq 0x8(%rcx,%rbx), %r9
leaq (%rdx,%rax), %rdi
cmpq %r15, %rdx
cmoveq %r15, %rdi
leaq (%r9,%rax), %rsi
cmpq %r15, %r9
cmoveq %r15, %rsi
movq 0x10(%rcx,%rbx), %rcx
leaq (%rax,%rcx), %rdx
cmpq %r15, %rcx
cmoveq %r15, %rdx
cmpq %rsi, %rdi
movq %rsi, %rax
cmovlq %rdi, %rax
cmpq %rdx, %rax
cmovgeq %rdx, %rax
movq %rax, (%r8,%r12)
callq 0x159da4
movq (%r14,%r13,8), %rcx
movl %eax, 0x20(%rcx,%r12)
movq -0x8(%r14,%r13,8), %rax
movq (%rax,%r12), %rdx
movq 0x8(%rax,%r12), %r8
movq (%rsp), %r9
leaq (%rdx,%r9), %rdi
cmpq %r15, %rdx
cmoveq %r15, %rdi
movq 0x8(%rsp), %rdx
leaq (%r8,%rdx), %rsi
cmpq %r15, %r8
cmoveq %r15, %rsi
movq 0x10(%rax,%r12), %rax
leaq (%rax,%r9), %rdx
cmpq %r15, %rax
cmoveq %r15, %rdx
cmpq %rsi, %rdi
movq %rsi, %rax
cmovlq %rdi, %rax
cmpq %rdx, %rax
cmovgeq %rdx, %rax
movq %rax, 0x8(%rcx,%r12)
callq 0x159da4
movq 0x18(%rsp), %r9
movq (%r14,%r13,8), %rcx
movl %eax, 0x24(%rcx,%r12)
incq %r13
cmpq 0x38(%rsp), %r13
jbe 0x134a52
movq 0x20(%rsp), %r9
cmpq %r9, %r13
movq 0x40(%rsp), %rbp
movq 0x48(%rsp), %rcx
ja 0x134bee
movq (%rbp,%r13,8), %rax
movq %r15, (%rax,%rcx)
movq %r15, 0x8(%rax,%rcx)
movq %r15, 0x10(%rax,%rcx)
incq %r13
cmpq %r9, %r13
jbe 0x134bd3
movq 0x10(%rsp), %rdi
incq %rdi
cmpq 0x90(%rsp), %rdi
movq 0xa0(%rsp), %rbx
movq 0x50(%rsp), %r12
jbe 0x134959
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x3f3b2
callq 0x3f37b