// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movl %ecx, %r12d
movl %edx, %r8d
movq %rsi, %r13
movq (%rdi), %rdx
movl 0x18(%rdx), %eax
movl 0x1c(%rdx), %ebx
movslq 0x10(%rdx), %rcx
movl %eax, %r14d
subl %ecx, %r14d
movq %rdx, 0x28(%rsp)
movslq 0x14(%rdx), %r10
movq %rcx, %r15
addq 0x10(%rdi), %r15
subl %r10d, %ebx
addq 0x18(%rdi), %r10
cmpl $0x4, %r8d
je 0xe09c
cmpl $0x2, %r8d
je 0xe11b
cmpl $0x1, %r8d
jne 0xe2ce
addl %r12d, %eax
decl %eax
cltd
idivl %r12d
movl %eax, %esi
movl %ecx, %eax
cltd
idivl %r12d
subl %eax, %esi
leal 0x4(,%rsi,4), %eax
cmpl 0x40(%r13), %eax
movq %rax, 0x20(%rsp)
jle 0xe124
movq %rdi, 0x18(%rsp)
movl %r8d, 0x8(%rsp)
movq %r10, 0x10(%rsp)
cvtsi2sd %eax, %xmm0
mulsd 0x9f34(%rip), %xmm0     # 0x18010
cvttsd2si %xmm0, %ebp
addl $0x2710, %ebp           # imm = 0x2710
movq 0x48(%r13), %rdi
movslq %ebp, %rsi
leaq 0xa584(%rip), %rdx      # 0x18678
callq 0x10de9
testq %rax, %rax
je 0xe30e
movl %ebp, 0x40(%r13)
movq %rax, 0x48(%r13)
movq 0x10(%rsp), %r10
movl 0x8(%rsp), %r8d
movq 0x18(%rsp), %rdi
jmp 0xe124
movq $0x0, 0x20(%rsp)
movq 0x48(%r13), %rbp
cmpl %ebx, %r14d
movl %ebx, %esi
cmovgl %r14d, %esi
shll $0x4, %esi
addl $0x18, %esi
cmpl (%r13), %esi
jle 0xe175
movq %rdi, 0x18(%rsp)
movq %r13, %rdi
movq %r15, 0x10(%rsp)
movq %r12, %r15
movq %r10, %r12
movq %rbx, 0x8(%rsp)
movl %r8d, %ebx
callq 0x3017
movq 0x18(%rsp), %rdi
movl %ebx, %r8d
movq 0x8(%rsp), %rbx
movq %r12, %r10
movq %r15, %r12
movq 0x10(%rsp), %r15
cmpl %ebx, %r14d
movl %ebx, %eax
cmovgl %r14d, %eax
movq 0x8(%r13), %rcx
cltq
leaq (%rcx,%rax,4), %rdx
leaq (%rcx,%rax,4), %rcx
addq $0x4, %rcx
addl %eax, %eax
cltq
leaq (%rdx,%rax,4), %rax
addq $0x10, %rax
movq %rcx, 0x68(%rsp)
movq %rax, 0x70(%rsp)
movdqu 0x10(%rdi), %xmm0
movdqu %xmm0, 0x40(%rsp)
cmpl $0x3, %r8d
je 0xe202
cmpl $0x2, %r8d
movq 0x28(%rsp), %r13
jne 0xe237
orl $-0x1, 0x60(%rsp)
testl %r14d, %r14d
jle 0xe2ef
testl %ebx, %ebx
jle 0xe2ec
leaq 0x60(%rsp), %r9
leaq 0x64(%rsp), %rax
movq %rax, (%rsp)
leaq 0x30(%rsp), %r8
movq %r15, %rdi
movl %r14d, %esi
movq %r10, %rdx
movl %ebx, %ecx
callq 0xe316
movl %eax, %ebx
jmp 0xe2ef
leaq 0x30(%rsp), %r12
movq %rbp, (%r12)
movq %r15, %rdi
movl %r14d, %esi
movq %r10, %rdx
movl %ebx, %ecx
movq %r12, %r8
callq 0xe6dc
movq 0x28(%rsp), %r13
movl %eax, 0xc(%r13)
movq (%r12), %rsi
subq %rbp, %rsi
shrq $0x2, %rsi
jmp 0xe2c4
movl 0x10(%r13), %eax
cltd
idivl %r12d
addl %eax, %eax
cltq
addq %rax, %rax
movq %rbp, %rcx
subq %rax, %rcx
movq %rcx, 0x38(%rsp)
movq 0x20(%rsp), %rdx
sarl %edx
xorl %eax, %eax
testl %edx, %edx
movl $0x0, %ecx
cmovgl %edx, %ecx
cmpq %rax, %rcx
je 0xe274
andw $0x0, (%rbp,%rax,2)
incq %rax
jmp 0xe264
leaq 0x30(%rsp), %r8
movq %r15, %rdi
movq %rdx, %r15
movl %r14d, %esi
movq %r10, %rdx
movl %ebx, %ecx
movl %r12d, %r9d
callq 0xe829
movq %r15, %rsi
movl %eax, 0xc(%r13)
movslq %esi, %rax
movzwl -0x2(%rbp,%rax,2), %ecx
testw %cx, %cx
je 0xe2c1
movd -0x8(%rbp,%rax,2), %xmm0
movzwl -0x4(%rbp,%rax,2), %edx
movd %edx, %xmm1
pinsrw $0x1, %ecx, %xmm1
paddw %xmm0, %xmm1
movd %xmm1, -0x8(%rbp,%rax,2)
addl $-0x2, %esi
movl %esi, 0x8(%r13)
movq %rbp, (%r13)
jmp 0xe2fd
cmpl %ebx, %r14d
jge 0xe2df
leal (,%rbx,4), %eax
jmp 0xe0b6
leal (,%r14,4), %eax
jmp 0xe0b6
movl %r14d, %ebx
movl %ebx, 0xc(%r13)
andq $0x0, (%r13)
orl $-0x1, 0x8(%r13)
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
callq 0x1280