// File: /workspace/github_c_makefile_star2_O1/ugobas[P]tnm/NeedlemanWunsch.c
// Function: TraceBack
static int TraceBack(int  **matrix,
                     XY   **dirn,
                     int  length1,
                     int  length2,
                     char *seq1,
                     char *seq2,
                     char *align1,
                     char *align2,
                     int  *align_len)
{
   int   i,    j,
         ai,
         BestI,BestJ;
   XY    nextCell;

   ai = SearchForBest(matrix, length1, length2, &BestI, &BestJ,
                       seq1, seq2, align1, align2);

   /* Now trace back to find the alignment                              */
   i            = BestI;
   j            = BestJ;
   align1[ai]   = seq1[i];
   align2[ai++] = seq2[j];

   while(i < length1-1 && j < length2-1)
   {
      nextCell.x = dirn[i][j].x;
      nextCell.y = dirn[i][j].y;
      if((nextCell.x == i+1) && (nextCell.y == j+1))
      {
         /* We are inheriting from the diagonal                         */
         i++;
         j++;
      }
      else if(nextCell.y == j+1)
      {
         /* We are inheriting from the off-diagonal inserting a gap in
            the y-sequence (seq2)
         */
         i++;
         j++;
         while((i < nextCell.x) && (i < length1-1))
         {
            align1[ai] = seq1[i++];
            align2[ai++] = '-';
         }
      }
      else if(nextCell.x == i+1)
      {
         /* We are inheriting from the off-diagonal inserting a gap in
            the x-sequence (seq1)
         */
         i++;
         j++;
         while((j < nextCell.y) && (j < length2-1))
         {
            align1[ai] = '-';
            align2[ai++] = seq2[j++];
         }
      }
      else
      {
         /* Cockup!                                                     */
         fprintf(stderr,"align.c/TraceBack() internal error\n");
      }

      align1[ai]   = seq1[i];
      align2[ai++] = seq2[j];
   }

   /* If one sequence finished first, fill in the end with insertions   */
   if(i < length1-1)
   {
      for(j=i+1; j<length1; j++)
      {
         align1[ai]   = seq1[j];
         align2[ai++] = '-';
      }
   }
   else if(j < length2-1)
   {
      for(i=j+1; i<length2; i++)
      {
         align1[ai]   = '-';
         align2[ai++] = seq2[i];
      }
   }

   *align_len = ai;

   return(matrix[BestI][BestJ]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, 0x10(%rsp)
xorl %r15d, %r15d
movl $0x0, %ebx
cmpl $0x2, %edx
jl 0x4d05d
movl %edx, %eax
xorl %ebp, %ebp
movl $0x1, %r11d
movq (%rdi,%r11,8), %rsi
movl (%rsi), %esi
movslq %ebp, %r10
movq (%rdi,%r10,8), %r10
movl %r11d, %ebx
cmpl (%r10), %esi
jg 0x4d053
movl %ebp, %ebx
incq %r11
movl %ebx, %ebp
cmpq %r11, %rax
jne 0x4d03c
movq %rdx, 0x20(%rsp)
cmpl $0x2, %ecx
jl 0x4d092
movq (%rdi), %rax
movl %ecx, %r14d
xorl %esi, %esi
movl $0x1, %edx
movl (%rax,%rdx,4), %r10d
movslq %esi, %r11
movl %edx, %r15d
cmpl (%rax,%r11,4), %r10d
jg 0x4d087
movl %esi, %r15d
incq %rdx
movl %r15d, %esi
cmpq %rdx, %r14
jne 0x4d074
movq 0x98(%rsp), %r12
movq 0x90(%rsp), %r13
movslq %ebx, %r10
movq (%rdi,%r10,8), %rax
movl (%rax), %eax
movq (%rdi), %rsi
movslq %r15d, %rdx
cmpl (%rsi,%rdx,4), %eax
jle 0x4d0dc
testl %ebx, %ebx
movq 0x20(%rsp), %r11
jle 0x4d102
xorl %eax, %eax
movb (%r8,%rax), %dl
movb %dl, (%r13,%rax)
movb $0x2d, (%r12,%rax)
incq %rax
cmpq %rax, %r10
jne 0x4d0c1
xorl %r15d, %r15d
jmp 0x4d10b
testl %r15d, %r15d
movq 0x20(%rsp), %r11
jle 0x4d107
xorl %eax, %eax
movb $0x2d, (%r13,%rax)
movb (%r9,%rax), %sil
movb %sil, (%r12,%rax)
incq %rax
cmpq %rax, %rdx
jne 0x4d0e8
xorl %ebx, %ebx
jmp 0x4d10b
xorl %r15d, %r15d
jmp 0x4d109
xorl %ebx, %ebx
xorl %eax, %eax
movslq %ebx, %rsi
movb (%r8,%rsi), %dl
movslq %eax, %rbp
movb %dl, (%r13,%rbp)
movslq %r15d, %rdx
movb (%r9,%rdx), %al
movb %al, (%r12,%rbp)
leal -0x1(%r11), %eax
movq %rcx, 0x38(%rsp)
leal -0x1(%rcx), %r14d
incl %ebp
movq %rdx, 0x40(%rsp)
cmpl %r14d, %edx
setl %cl
movq %rsi, 0x48(%rsp)
movl %eax, 0xc(%rsp)
cmpl %eax, %esi
setl %dl
jge 0x4d2ae
cmpl %r14d, %r15d
jge 0x4d2ae
leaq 0x1(%r8), %rax
movq %rax, 0x50(%rsp)
movq %r8, 0x18(%rsp)
movq 0x10(%rsp), %r11
movq %r9, 0x28(%rsp)
movslq %ebx, %rsi
movq (%r11,%rsi,8), %rcx
movslq %r15d, %rax
movl (%rcx,%rax,8), %r10d
movl 0x4(%rcx,%rax,8), %edx
leal 0x1(%rsi), %ecx
incl %eax
cmpl %ecx, %r10d
jne 0x4d19e
cmpl %eax, %edx
jne 0x4d19e
movl %eax, %r15d
movl %ecx, %ebx
jmp 0x4d25d
cmpl %eax, %edx
jne 0x4d1f3
movl 0xc(%rsp), %edx
cmpl %edx, %r10d
cmovgel %edx, %r10d
cmpl %r10d, %ecx
jge 0x4d194
leaq 0x1(%rsi), %rbx
movslq %ebp, %rcx
leaq (%rcx,%r13), %rdx
addq %r12, %rcx
movq 0x50(%rsp), %r8
addq %rsi, %r8
negl %r10d
addq %rsi, %r10
incq %r10
xorl %esi, %esi
movb (%r8,%rsi), %r11b
movb %r11b, (%rdx,%rsi)
movb $0x2d, (%rcx,%rsi)
incq %rsi
movl %r10d, %r11d
addl %esi, %r11d
jne 0x4d1d3
addl %esi, %ebp
addl %esi, %ebx
movl %eax, %r15d
jmp 0x4d247
cmpl %ecx, %r10d
jne 0x4d293
cmpl %r14d, %edx
cmovgel %r14d, %edx
cmpl %edx, %eax
jge 0x4d253
movslq %eax, %rsi
movslq %ebp, %r11
leaq (%r11,%r13), %r8
addq %r12, %r11
addq %r9, %rsi
negl %edx
movl %eax, %r9d
addq %rdx, %r9
xorl %edx, %edx
movb $0x2d, (%r8,%rdx)
movb (%rsi,%rdx), %r10b
movb %r10b, (%r11,%rdx)
incq %rdx
movl %r9d, %r10d
addl %edx, %r10d
jne 0x4d221
addl %edx, %ebp
addl %edx, %eax
movl %eax, %r15d
movl %ecx, %ebx
movq 0x28(%rsp), %r9
movq 0x18(%rsp), %r8
movq 0x10(%rsp), %r11
jmp 0x4d25d
movl %eax, %r15d
movl %ecx, %ebx
movq 0x18(%rsp), %r8
movslq %ebx, %rax
movb (%r8,%rax), %cl
movslq %ebp, %rbp
movb %cl, (%r13,%rbp)
movslq %r15d, %rcx
movb (%r9,%rcx), %dl
movb %dl, (%r12,%rbp)
incl %ebp
cmpl %r14d, %ecx
setl %cl
cmpl 0xc(%rsp), %eax
setl %dl
jge 0x4d2ae
cmpl %r14d, %r15d
jl 0x4d174
jmp 0x4d2ae
movq %rdi, 0x30(%rsp)
callq 0x22e0
movq 0x10(%rsp), %r11
movq 0x28(%rsp), %r9
movq 0x30(%rsp), %rdi
jmp 0x4d258
movq 0xa0(%rsp), %rax
testb %dl, %dl
je 0x4d2f2
movslq %ebx, %rcx
incq %rcx
movq 0x20(%rsp), %rsi
cmpl %esi, %ecx
jge 0x4d339
movslq %ebp, %rdx
addq %rdx, %r13
addq %rdx, %r12
addq %rcx, %r8
notl %ebx
addl %esi, %ebx
xorl %ecx, %ecx
movb (%r8,%rcx), %dl
movb %dl, (%r13,%rcx)
movb $0x2d, (%r12,%rcx)
incq %rcx
cmpl %ecx, %ebx
jne 0x4d2db
jmp 0x4d337
leal 0x1(%r15), %edx
movq 0x38(%rsp), %r8
cmpl %r8d, %edx
setge %sil
xorb $0x1, %cl
orb %sil, %cl
jne 0x4d339
movslq %edx, %rcx
movslq %ebp, %rdx
addq %rdx, %r13
addq %rdx, %r12
addq %rcx, %r9
notl %r15d
addl %r8d, %r15d
xorl %ecx, %ecx
movb $0x2d, (%r13,%rcx)
movb (%r9,%rcx), %dl
movb %dl, (%r12,%rcx)
incq %rcx
cmpl %ecx, %r15d
jne 0x4d321
addl %ecx, %ebp
movl %ebp, (%rax)
movq 0x48(%rsp), %rax
movq (%rdi,%rax,8), %rax
movq 0x40(%rsp), %rcx
movl (%rax,%rcx,4), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq