// File: /workspace/github_c_makefile_star2_O1/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 0x175854
movq %rsi, %r13
testq %rsi, %rsi
je 0x175854
movq %r8, %r15
movl %edx, %ebp
movq %rdi, %r14
movq 0x50(%rsp), %r12
cmpl $0x2, %edx
je 0x1756de
cmpl $0x1, %ebp
je 0x1756cd
testl %ebp, %ebp
jne 0x175859
leaq (%r12,%r12,8), %rax
leaq (,%rax,8), %rax
addq %r13, %rax
jmp 0x1756ed
leaq (%r12,%r12,8), %rax
leaq 0x18(,%rax,8), %rax
addq %r13, %rax
jmp 0x1756ed
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 0x17570d
movq %r14, %rdi
callq 0x126d42
decq %r15
cmpq %rbx, %r15
ja 0x1756fd
movq %r14, (%rsp)
testq %r12, %r12
je 0x175820
movq %r13, 0x10(%rsp)
movl 0xc(%rsp), %r15d
cmpl $0x3, %r15d
jae 0x175845
movq %rbx, %r14
cmpq $-0x1, %rbx
je 0x17584a
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 0x175787
cmpl $0x2, %ebp
je 0x1757e0
cmpl $0x1, %ebp
je 0x1757ca
testl %ebp, %ebp
movq (%rsp), %rdi
jne 0x17580f
callq 0x126d25
jmp 0x17580f
movq %r14, %r13
subq %rbx, %r13
jne 0x175795
movq (%rsp), %rdi
jmp 0x1757d9
jbe 0x17580f
cmpl $0x2, %ebp
je 0x1757f6
testl %ebp, %ebp
jne 0x17584f
movq (%rsp), %r13
movq %r13, %rdi
callq 0x126d25
movq %rbx, %rax
notq %rax
addq %rax, %r14
je 0x17580f
movq %r13, %rdi
callq 0x126d42
decq %r14
jne 0x1757bb
jmp 0x17580f
movq (%rsp), %r14
movq %r14, %rdi
callq 0x126d42
movq %r14, %rdi
callq 0x126d5f
jmp 0x17580f
movq (%rsp), %r14
movq %r14, %rdi
callq 0x126d5f
movq %r14, %rdi
callq 0x126d42
jmp 0x17580f
movq (%rsp), %r14
movq %r14, %rdi
callq 0x126d5f
movq %r14, %rdi
callq 0x126d42
decq %r13
jne 0x175802
movl %r15d, %ebp
decq %r12
movq 0x10(%rsp), %r13
jne 0x17571f
testq %rbx, %rbx
movq (%rsp), %r14
je 0x175836
movq %r14, %rdi
callq 0x126d42
decq %rbx
jne 0x175829
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x52353
callq 0x523c5
callq 0x5238c
callq 0x5231a
callq 0x523fe
nop