// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/extended/reconstructalignment.c
// Function: gt_reconstructalignment_from_affineDtab
void gt_reconstructalignment_from_affineDtab(GtAlignment *align,
                                             const GtAffineDiagAlignentry *Dtab,
                                             GtAffineAlignEdge edge,
                                             GT_UNUSED const GtUchar *useq,
                                             GtUword ulen,
                                             GT_UNUSED const GtUchar *vseq,
                                             GtUword vlen)
{
  GtUword i,j;
  GtDiagAlignentry node, prevnode;
  GtAffineAlignEdge prevedge;
  gt_assert(align != NULL && Dtab != NULL);

  switch (edge) {
    case Affine_R:
      node = Dtab[vlen].val_R;
      break;
    case Affine_D:
      node = Dtab[vlen].val_D;
      break;
    case Affine_I:
      node = Dtab[vlen].val_I;
      break;
    default:
      gt_assert(false);
#ifdef NDEBUG
      exit(GT_EXIT_PROGRAMMING_ERROR);
#endif
  }

  for (j = ulen; j > node.currentrowindex; j--)
  {
    gt_alignment_add_deletion(align);
  }
  prevedge = edge;
  /*consider pairwise distance between prevnode and node */
  /*prevedge->prevnode, prevnode.edge->node, node.edge->nextnode*/
  for (i = vlen; i > 0; i--)
  {
    prevnode = node;
    switch (prevnode.last_type) {
      case Affine_R:
        node = Dtab[i-1].val_R;
        break;
      case Affine_D:
        node = Dtab[i-1].val_D;
        break;
      case Affine_I:
        node = Dtab[i-1].val_I;
        break;
      default:
        gt_assert(false);
#ifdef NDEBUG
        exit(GT_EXIT_PROGRAMMING_ERROR);
#endif
    }

    gt_assert(prevnode.currentrowindex != GT_UWORD_MAX);
    if (prevnode.currentrowindex == node.currentrowindex + 1)
    {
      if (prevedge == Affine_R)
      {
        gt_alignment_add_replacement(align);
      }
      else if (prevedge == Affine_D)
      {
         gt_alignment_add_deletion(align);
         gt_alignment_add_insertion(align);
      }
      else if (prevedge == Affine_I)
      {
         gt_alignment_add_insertion(align);
         gt_alignment_add_deletion(align);
      }
    }
    else if (prevnode.currentrowindex == node.currentrowindex)
    {
      gt_alignment_add_insertion(align);
    }
    else if (prevnode.currentrowindex > node.currentrowindex)
    {
      if (prevedge == Affine_R)
      {
        gt_alignment_add_replacement(align);

        for (j = 0; j < prevnode.currentrowindex - node.currentrowindex - 1;
             j++)
        {
          gt_alignment_add_deletion(align);
        }
      }
      else if (prevedge == Affine_I)
      {
        gt_alignment_add_insertion(align);
        for (j = 0; j < prevnode.currentrowindex - node.currentrowindex; j++)
        {
          gt_alignment_add_deletion(align);
        }
      }
      else
      {
        gt_assert(false);
      }
    }
    prevedge = prevnode.last_type;
  }
  for (j = node.currentrowindex; j > 0; j--)
  {
    gt_alignment_add_deletion(align);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0x16d5ce
movq %rsi, %r13
testq %rsi, %rsi
je 0x16d5ce
movq %r8, %r15
movl %edx, %ebp
movq %rdi, %r14
movq 0x50(%rsp), %r12
cmpl $0x2, %edx
je 0x16d458
cmpl $0x1, %ebp
je 0x16d447
testl %ebp, %ebp
jne 0x16d5d3
leaq (%r12,%r12,8), %rax
leaq (,%rax,8), %rax
addq %r13, %rax
jmp 0x16d467
leaq (%r12,%r12,8), %rax
leaq 0x18(,%rax,8), %rax
addq %r13, %rax
jmp 0x16d467
leaq (%r12,%r12,8), %rax
leaq 0x30(,%rax,8), %rax
addq %r13, %rax
movl 0x10(%rax), %ecx
movl %ecx, 0xc(%rsp)
movq 0x8(%rax), %rbx
cmpq %r15, %rbx
jae 0x16d487
movq %r14, %rdi
callq 0x120f4a
decq %r15
cmpq %rbx, %r15
ja 0x16d477
movq %r14, (%rsp)
testq %r12, %r12
je 0x16d59a
movq %r13, 0x10(%rsp)
movl 0xc(%rsp), %r15d
cmpl $0x3, %r15d
jae 0x16d5bf
movq %rbx, %r14
cmpq $-0x1, %rbx
je 0x16d5c4
movl %r15d, %eax
leaq (%rax,%rax,2), %rax
leaq (%r12,%r12,8), %rcx
leaq (,%rcx,8), %rcx
addq %r13, %rcx
movl -0x38(%rcx,%rax,8), %edx
movl %edx, 0xc(%rsp)
movq -0x40(%rcx,%rax,8), %rbx
leaq 0x1(%rbx), %rax
cmpq %rax, %r14
jne 0x16d501
cmpl $0x2, %ebp
je 0x16d55a
cmpl $0x1, %ebp
je 0x16d544
testl %ebp, %ebp
movq (%rsp), %rdi
jne 0x16d589
callq 0x120f2d
jmp 0x16d589
movq %r14, %r13
subq %rbx, %r13
jne 0x16d50f
movq (%rsp), %rdi
jmp 0x16d553
jbe 0x16d589
cmpl $0x2, %ebp
je 0x16d570
testl %ebp, %ebp
jne 0x16d5c9
movq (%rsp), %r13
movq %r13, %rdi
callq 0x120f2d
movq %rbx, %rax
notq %rax
addq %rax, %r14
je 0x16d589
movq %r13, %rdi
callq 0x120f4a
decq %r14
jne 0x16d535
jmp 0x16d589
movq (%rsp), %r14
movq %r14, %rdi
callq 0x120f4a
movq %r14, %rdi
callq 0x120f67
jmp 0x16d589
movq (%rsp), %r14
movq %r14, %rdi
callq 0x120f67
movq %r14, %rdi
callq 0x120f4a
jmp 0x16d589
movq (%rsp), %r14
movq %r14, %rdi
callq 0x120f67
movq %r14, %rdi
callq 0x120f4a
decq %r13
jne 0x16d57c
movl %r15d, %ebp
decq %r12
movq 0x10(%rsp), %r13
jne 0x16d499
testq %rbx, %rbx
movq (%rsp), %r14
je 0x16d5b0
movq %r14, %rdi
callq 0x120f4a
decq %rbx
jne 0x16d5a3
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x51425
callq 0x51497
callq 0x5145e
callq 0x513ec
callq 0x514d0