// File: /workspace/github_c_makefile_star2_O1/thegenemyers[P]DASCRUBBER/align.c
// Function: Compute_Alignment
int Compute_Alignment(Alignment *align, Work_Data *ework, int task, int tspace)
{ _Work_Data *work = (_Work_Data *) ework;
  Trace_Waves wave;

  int     L, D;
  int     asub, bsub;
  char   *aseq, *bseq;
  Path   *path;
  int    *trace;
  uint16 *strace;

  path = align->path;
  asub = path->aepos-path->abpos;
  bsub = path->bepos-path->bbpos;
  aseq = align->aseq+path->abpos;
  bseq = align->bseq+path->bbpos;

  L = 0;
  if (task != DIFF_ONLY)
    { if (task == DIFF_TRACE || task == PLUS_TRACE)
        L = 2*(((path->aepos + (tspace-1))/tspace - path->abpos/tspace) + 1)*sizeof(uint16);
      else if (asub < bsub)
        L = bsub*sizeof(int);
      else
        L = asub*sizeof(int);
      if (L > work->alnmax)
        if (enlarge_alnpts(work,L))
          EXIT(1);
    }

  trace  = ((int *) work->alnpts);
  strace = ((uint16 *) work->alnpts);

  if (asub > bsub)
    D = (4*asub+6)*sizeof(int);
  else
    D = (4*bsub+6)*sizeof(int);
  if (D > work->vecmax)
    if (enlarge_vector(work,D))
      EXIT(1);
  
  if (asub > bsub)
    { wave.VF = ((int *) work->vector) + (asub+1);
      wave.VB = wave.VF + (2*asub+3);
    }
  else
    { wave.VF = ((int *) work->vector) + (bsub+1);
      wave.VB = wave.VF + (2*bsub+3);
    }

  wave.Aabs = align->aseq;
  wave.Babs = align->bseq;

  if (task == DIFF_ONLY)
    { wave.mida = -1;
      if (asub <= 0)
        path->diffs = bsub;
      else if (bsub <= 0)
        path->diffs = asub;
      else
        path->diffs = split_nd(aseq,asub,bseq,bsub,&wave,&wave.mida,&wave.midb);
      path->trace = NULL;
      path->tlen  = -1;
      return (0);
    }

  else if (task < DIFF_ONLY && wave.mida >= 0)
    { int x = wave.mida;
      int y = wave.midb;

      if (task == PLUS_ALIGN)
        { wave.Stop = trace;
          dandc_nd(aseq,x,bseq,y,&wave);
          dandc_nd(aseq+x,asub-x,bseq+y,bsub-y,&wave);
          path->tlen = wave.Stop - trace;
        }
      else
        { int i, n;

          wave.Trace = strace - 2*(path->abpos/tspace);
          n  = L/sizeof(uint16);
          for (i = 0; i < n; i++)
            strace[i] = 0;

          trace_nd(aseq,x,bseq,y,&wave,tspace);
          trace_nd(aseq+x,asub-x,bseq+y,bsub-y,&wave,tspace);

          if (strace[n-1] != 0)   //  Last element is to capture all inserts on TP boundary
            { strace[n-3] += strace[n-1];
              strace[n-4] += strace[n-2];
            }
          path->tlen = n-2;

#ifdef DEBUG_SCRIPT
          printf("  Trace:\n");
          for (i = 0; i < path->tlen; i += 2)
            printf("    %3d  %3d\n",strace[i],strace[i+1]);
          fflush(stdout);
#endif
        }
    }

  else 
    { if (task == DIFF_ALIGN)
        { wave.Stop   = trace;
          path->diffs = dandc_nd(aseq,asub,bseq,bsub,&wave);
          path->tlen  = wave.Stop - trace;
        }
      else
        { int i, n;

          wave.Trace  = strace - 2*(path->abpos/tspace);
          n  = L/sizeof(uint16);
          for (i = 0; i < n; i++)
            strace[i] = 0;
          path->diffs = trace_nd(aseq,asub,bseq,bsub,&wave,tspace);

          if (strace[n-1] != 0)   //  Last element is to capture all inserts on TP boundary
            { strace[n-3] += strace[n-1];
              strace[n-4] += strace[n-2];
            }
          path->tlen = n-2;

#ifdef DEBUG_SCRIPT
          printf("  Trace:\n");
          for (i = 0; i < path->tlen; i += 2)
            printf("    %3d  %3d\n",strace[i],strace[i+1]);
          fflush(stdout);
#endif
        }
    }

  path->trace = trace;
  return (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, 0x8(%rsp)
movl %edx, %ebp
movq %rsi, %r13
movq %rdi, %r12
movq (%rdi), %r14
movl 0x18(%r14), %eax
movl 0x1c(%r14), %ebx
movslq 0x10(%r14), %rcx
movl %eax, %r15d
subl %ecx, %r15d
movslq 0x14(%r14), %rdx
movq %rcx, %rsi
addq 0x10(%rdi), %rsi
movq %rsi, 0x18(%rsp)
subl %edx, %ebx
addq 0x18(%rdi), %rdx
movq %rdx, 0x20(%rsp)
cmpl $0x4, %ebp
je 0xf6dc
cmpl $0x2, %ebp
je 0xf74b
cmpl $0x1, %ebp
jne 0xf8de
movq 0x8(%rsp), %rdi
addl %edi, %eax
decl %eax
cltd
idivl %edi
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %edi
subl %eax, %esi
leal 0x4(,%rsi,4), %eax
cmpl 0x40(%r13), %eax
movq %rax, 0x28(%rsp)
jle 0xf754
movq %r14, 0x10(%rsp)
cvtsi2sd %eax, %xmm0
mulsd 0xa8fc(%rip), %xmm0     # 0x1a010
cvttsd2si %xmm0, %r14d
addl $0x2710, %r14d          # imm = 0x2710
movq 0x48(%r13), %rdi
movslq %r14d, %rsi
leaq 0xaf4a(%rip), %rdx      # 0x1a678
callq 0x124f5
testq %rax, %rax
je 0xfa36
movl %r14d, 0x40(%r13)
movq %rax, 0x48(%r13)
movq 0x10(%rsp), %r14
jmp 0xf754
movq $0x0, 0x28(%rsp)
movq 0x48(%r13), %rax
movq %rax, 0x10(%rsp)
cmpl %ebx, %r15d
movl %ebx, %esi
cmovgl %r15d, %esi
shll $0x4, %esi
addl $0x18, %esi
cmpl (%r13), %esi
jle 0xf77a
movq %r13, %rdi
callq 0x4252
movq 0x8(%r13), %rax
cmpl %ebx, %r15d
movl %ebx, %ecx
cmovgl %r15d, %ecx
movslq %ecx, %rcx
leaq (%rax,%rcx,4), %rdx
leaq (%rax,%rcx,4), %rax
addq $0x4, %rax
movq %rax, 0x78(%rsp)
addl %ecx, %ecx
movslq %ecx, %rax
leaq (%rdx,%rax,4), %rax
addq $0x10, %rax
movq %rax, 0x80(%rsp)
movq 0x10(%r12), %rax
movq %rax, 0x50(%rsp)
movq 0x18(%r12), %rax
movq %rax, 0x58(%rsp)
cmpl $0x2, %ebp
jne 0xf810
movl $0xffffffff, 0x70(%rsp) # imm = 0xFFFFFFFF
testl %r15d, %r15d
jle 0xf9b2
testl %ebx, %ebx
jle 0xf9af
leaq 0x70(%rsp), %r9
leaq 0x74(%rsp), %rax
movq %rax, (%rsp)
leaq 0x40(%rsp), %r8
movq 0x18(%rsp), %rdi
movl %r15d, %esi
movq 0x20(%rsp), %rdx
movl %ebx, %ecx
callq 0xfa40
movl %eax, %ebx
jmp 0xf9b2
setl %cl
movl 0x70(%rsp), %eax
testl %eax, %eax
setns %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0xf8ef
movl %eax, %esi
movslq 0x74(%rsp), %rcx
testl %ebp, %ebp
movq 0x10(%rsp), %r13
movq %rcx, 0x38(%rsp)
movq %rsi, 0x30(%rsp)
je 0xf9c7
movl 0x10(%r14), %eax
cltd
idivl 0x8(%rsp)
addl %eax, %eax
cltq
addq %rax, %rax
movq %r13, %rdx
subq %rax, %rdx
movq %rdx, 0x48(%rsp)
movq 0x28(%rsp), %rdx
movl %edx, %ebp
sarl %ebp
testl %ebp, %ebp
jle 0xf886
andl $-0x2, %edx
movq %r13, %rdi
movq %rsi, %r13
xorl %esi, %esi
movq %rcx, %r12
callq 0x1130
movq %r13, %rsi
movq %r12, %rcx
leaq 0x40(%rsp), %r8
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq 0x20(%rsp), %r12
movq %r12, %rdx
movq 0x8(%rsp), %r9
callq 0xff91
movq 0x30(%rsp), %rax
addq %rax, %r13
subl %eax, %r15d
movq 0x38(%rsp), %rax
addq %rax, %r12
subl %eax, %ebx
movq %r13, %rdi
movq 0x10(%rsp), %r13
movl %r15d, %esi
movq %r12, %rdx
movl %ebx, %ecx
leaq 0x40(%rsp), %r8
movq 0x8(%rsp), %r9
callq 0xff91
jmp 0xf98a
cmpl %ebx, %r15d
jge 0xf926
leal (,%rbx,4), %eax
jmp 0xf6f8
cmpl $0x3, %ebp
movq 0x10(%rsp), %r13
jne 0xf933
leaq 0x40(%rsp), %r12
movq %r13, (%r12)
movq 0x18(%rsp), %rdi
movl %r15d, %esi
movq 0x20(%rsp), %rdx
movl %ebx, %ecx
movq %r12, %r8
callq 0xfe2e
movl %eax, 0xc(%r14)
movq (%r12), %rbp
jmp 0xfa14
leal (,%r15,4), %eax
jmp 0xf6f8
movl 0x10(%r14), %eax
cltd
idivl 0x8(%rsp)
addl %eax, %eax
cltq
addq %rax, %rax
movq %r13, %rcx
subq %rax, %rcx
movq %rcx, 0x48(%rsp)
movq 0x28(%rsp), %rdx
movl %edx, %ebp
sarl %ebp
testl %ebp, %ebp
jle 0xf968
andl $-0x2, %edx
movq %r13, %rdi
xorl %esi, %esi
callq 0x1130
leaq 0x40(%rsp), %r8
movq 0x18(%rsp), %rdi
movl %r15d, %esi
movq 0x20(%rsp), %rdx
movl %ebx, %ecx
movq 0x8(%rsp), %r9
callq 0xff91
movl %eax, 0xc(%r14)
movslq %ebp, %rax
movzwl -0x2(%r13,%rax,2), %ecx
testw %cx, %cx
je 0xf9aa
addw %cx, -0x6(%r13,%rax,2)
movzwl -0x4(%r13,%rax,2), %ecx
addw %cx, -0x8(%r13,%rax,2)
addl $-0x2, %ebp
jmp 0xfa1b
movl %r15d, %ebx
movl %ebx, 0xc(%r14)
movq $0x0, (%r14)
movl $0xffffffff, 0x8(%r14)  # imm = 0xFFFFFFFF
jmp 0xfa22
leaq 0x40(%rsp), %r8
movq %r13, (%r8)
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq 0x20(%rsp), %rbp
movq %rbp, %rdx
callq 0xfe2e
movq 0x30(%rsp), %rax
addq %rax, %r12
subl %eax, %r15d
movq 0x38(%rsp), %rax
addq %rax, %rbp
subl %eax, %ebx
movq %r12, %rdi
movl %r15d, %esi
movq %rbp, %rdx
movl %ebx, %ecx
leaq 0x40(%rsp), %rbx
movq %rbx, %r8
callq 0xfe2e
movq (%rbx), %rbp
subq %r13, %rbp
shrq $0x2, %rbp
movl %ebp, 0x8(%r14)
movq %r13, (%r14)
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x1280