// File: /workspace/github_c_makefile_star2_O3/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 %edx, %ebp
movq %rsi, %r15
movq %rdi, %r12
movq (%rdi), %r13
movl 0x18(%r13), %eax
movl 0x1c(%r13), %ebx
movslq 0x10(%r13), %rdi
movl %eax, %r14d
subl %edi, %r14d
movslq 0x14(%r13), %rdx
movq %rdi, %rsi
addq 0x10(%r12), %rsi
movq %rsi, 0x10(%rsp)
subl %edx, %ebx
addq 0x18(%r12), %rdx
movq %rdx, 0x18(%rsp)
cmpl $0x4, %ebp
movq %rcx, 0x28(%rsp)
je 0xf5e3
cmpl $0x2, %ebp
je 0xf64d
cmpl $0x1, %ebp
jne 0xf7dc
addl %ecx, %eax
decl %eax
cltd
idivl %ecx
movl %eax, %esi
movl %edi, %eax
cltd
idivl %ecx
subl %eax, %esi
leal 0x4(,%rsi,4), %eax
cmpl 0x40(%r15), %eax
movq %rax, 0x20(%rsp)
jle 0xf656
movq %r13, 0x8(%rsp)
cvtsi2sd %eax, %xmm0
mulsd 0xa9fa(%rip), %xmm0     # 0x1a010
cvttsd2si %xmm0, %r13d
addl $0x2710, %r13d          # imm = 0x2710
movq 0x48(%r15), %rdi
movslq %r13d, %rsi
leaq 0xb078(%rip), %rdx      # 0x1a6a8
callq 0x12509
testq %rax, %rax
je 0xf822
movl %r13d, 0x40(%r15)
movq %rax, 0x48(%r15)
movq 0x8(%rsp), %r13
jmp 0xf656
movq $0x0, 0x20(%rsp)
movq 0x48(%r15), %rax
movq %rax, 0x8(%rsp)
cmpl %ebx, %r14d
movl %ebx, %esi
cmovgl %r14d, %esi
shll $0x4, %esi
addl $0x18, %esi
cmpl (%r15), %esi
jle 0xf67b
movq %r15, %rdi
callq 0x4220
cmpl %ebx, %r14d
movl %ebx, %eax
cmovgl %r14d, %eax
movq 0x8(%r15), %rcx
cltq
leaq (%rcx,%rax,4), %rdx
leaq (%rcx,%rax,4), %r8
addq $0x4, %r8
addl %eax, %eax
cltq
leaq (%rdx,%rax,4), %r9
addq $0x10, %r9
movq %r8, 0x68(%rsp)
movq %r9, 0x70(%rsp)
movdqu 0x10(%r12), %xmm0
movdqu %xmm0, 0x40(%rsp)
cmpl $0x3, %ebp
je 0xf708
cmpl $0x2, %ebp
jne 0xf73f
movl $0xffffffff, 0x60(%rsp) # imm = 0xFFFFFFFF
testl %r14d, %r14d
jle 0xf7fd
testl %ebx, %ebx
jle 0xf7fa
leaq 0x60(%rsp), %rax
leaq 0x64(%rsp), %r10
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
pushq %r10
pushq %rax
callq 0xf82c
addq $0x10, %rsp
movl %eax, %ebx
jmp 0xf7fd
leaq 0x30(%rsp), %r15
movq 0x8(%rsp), %rbp
movq %rbp, (%r15)
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
movq %r15, %r8
callq 0xfc1f
movl %eax, 0xc(%r13)
movq (%r15), %r15
subq %rbp, %r15
shrq $0x2, %r15
jmp 0xf7d2
movl 0x10(%r13), %eax
cltd
movq 0x28(%rsp), %r9
idivl %r9d
addl %eax, %eax
cltq
addq %rax, %rax
movq 0x8(%rsp), %rbp
movq %rbp, %rcx
subq %rax, %rcx
movq %rcx, 0x38(%rsp)
movq 0x20(%rsp), %rdx
movl %edx, %r15d
sarl %r15d
testl %r15d, %r15d
jle 0xf786
andl $-0x2, %edx
movq %rbp, %rdi
xorl %esi, %esi
movq %r9, %r12
callq 0x1130
movq %r12, %r9
leaq 0x30(%rsp), %r8
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq 0x18(%rsp), %rdx
movl %ebx, %ecx
callq 0xfd6d
movl %eax, 0xc(%r13)
movslq %r15d, %rax
movzwl -0x2(%rbp,%rax,2), %ecx
testw %cx, %cx
je 0xf7ce
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, %r15d
movl %r15d, 0x8(%r13)
movq %rbp, (%r13)
jmp 0xf811
cmpl %ebx, %r14d
jge 0xf7ed
leal (,%rbx,4), %eax
jmp 0xf5fa
leal (,%r14,4), %eax
jmp 0xf5fa
movl %r14d, %ebx
movl %ebx, 0xc(%r13)
movq $0x0, (%r13)
movl $0xffffffff, 0x8(%r13)  # imm = 0xFFFFFFFF
xorl %eax, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x1280