// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x98(%rbp), %rcx
subl 0x10(%rcx), %eax
movl %eax, -0x7c(%rbp)
movq -0x98(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x98(%rbp), %rcx
subl 0x14(%rcx), %eax
movl %eax, -0x80(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x98(%rbp), %rcx
movslq 0x10(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x98(%rbp), %rcx
movslq 0x14(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x74(%rbp)
cmpl $0x2, -0x1c(%rbp)
je 0x153f4
cmpl $0x4, -0x1c(%rbp)
je 0x15364
cmpl $0x1, -0x1c(%rbp)
jne 0x153a7
movq -0x98(%rbp), %rax
movl 0x18(%rax), %eax
movl -0x20(%rbp), %ecx
subl $0x1, %ecx
addl %ecx, %eax
cltd
idivl -0x20(%rbp)
movl %eax, -0xc4(%rbp)
movq -0x98(%rbp), %rax
movl 0x10(%rax), %eax
cltd
idivl -0x20(%rbp)
movl %eax, %ecx
movl -0xc4(%rbp), %eax
subl %ecx, %eax
addl $0x1, %eax
shll %eax
cltq
shlq %rax
movl %eax, -0x74(%rbp)
jmp 0x153c9
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jge 0x153bc
movslq -0x80(%rbp), %rax
shlq $0x2, %rax
movl %eax, -0x74(%rbp)
jmp 0x153c7
movslq -0x7c(%rbp), %rax
shlq $0x2, %rax
movl %eax, -0x74(%rbp)
jmp 0x153c9
movl -0x74(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jle 0x153f2
movq -0x28(%rbp), %rdi
movl -0x74(%rbp), %esi
callq 0x159b0
cmpl $0x0, %eax
je 0x153f0
movl $0x1, %edi
callq 0x2290
jmp 0x153f2
jmp 0x153f4
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0x28(%rbp), %rax
movq 0x48(%rax), %rax
movq %rax, -0xa8(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jle 0x1542e
movl -0x7c(%rbp), %eax
shll $0x2, %eax
addl $0x6, %eax
cltq
shlq $0x2, %rax
movl %eax, -0x78(%rbp)
jmp 0x15440
movl -0x80(%rbp), %eax
shll $0x2, %eax
addl $0x6, %eax
cltq
shlq $0x2, %rax
movl %eax, -0x78(%rbp)
movl -0x78(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl (%rcx), %eax
jle 0x15468
movq -0x28(%rbp), %rdi
movl -0x78(%rbp), %esi
callq 0x5220
cmpl $0x0, %eax
je 0x15466
movl $0x1, %edi
callq 0x2290
jmp 0x15468
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jle 0x154a8
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x7c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl -0x7c(%rbp), %ecx
shll %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
jmp 0x154de
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x80(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl -0x80(%rbp), %ecx
shll %ecx
addl $0x3, %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
cmpl $0x2, -0x1c(%rbp)
jne 0x15598
movl $0xffffffff, -0x40(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, -0x7c(%rbp)
jg 0x1551c
movl -0x80(%rbp), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x15570
cmpl $0x0, -0x80(%rbp)
jg 0x15531
movl -0x7c(%rbp), %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x1556e
movq -0x88(%rbp), %rdi
movl -0x7c(%rbp), %esi
movq -0x90(%rbp), %rdx
movl -0x80(%rbp), %ecx
leaq -0x70(%rbp), %r9
addq $0x30, %r9
leaq -0x70(%rbp), %rax
addq $0x34, %rax
leaq -0x70(%rbp), %r8
movq %rax, (%rsp)
callq 0x15a30
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0xc(%rax)
jmp 0x15570
movq -0x98(%rbp), %rax
movq $0x0, (%rax)
movq -0x98(%rbp), %rax
movl $0xffffffff, 0x8(%rax)  # imm = 0xFFFFFFFF
movl $0x0, -0x4(%rbp)
jmp 0x1599d
cmpl $0x2, -0x1c(%rbp)
jge 0x157dd
cmpl $0x0, -0x40(%rbp)
jl 0x157dd
movl -0x40(%rbp), %eax
movl %eax, -0xac(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0xb0(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x15656
movq -0xa0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x88(%rbp), %rdi
movl -0xac(%rbp), %esi
movq -0x90(%rbp), %rdx
movl -0xb0(%rbp), %ecx
leaq -0x70(%rbp), %r8
callq 0x160e0
movq -0x88(%rbp), %rdi
movslq -0xac(%rbp), %rax
addq %rax, %rdi
movl -0x7c(%rbp), %esi
subl -0xac(%rbp), %esi
movq -0x90(%rbp), %rdx
movslq -0xb0(%rbp), %rax
addq %rax, %rdx
movl -0x80(%rbp), %ecx
subl -0xb0(%rbp), %ecx
leaq -0x70(%rbp), %r8
callq 0x160e0
movq -0x70(%rbp), %rax
movq -0xa0(%rbp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x157d8
movq -0xa8(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x98(%rbp), %rax
movl 0x10(%rax), %eax
cltd
idivl -0x20(%rbp)
movl %eax, %ecx
movq -0xd0(%rbp), %rax
shll %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movslq -0x74(%rbp), %rax
shrq %rax
movl %eax, -0xb8(%rbp)
movl $0x0, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0xb8(%rbp), %eax
jge 0x156d9
movq -0xa8(%rbp), %rax
movslq -0xb4(%rbp), %rcx
movw $0x0, (%rax,%rcx,2)
movl -0xb4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb4(%rbp)
jmp 0x156a6
movq -0x88(%rbp), %rdi
movl -0xac(%rbp), %esi
movq -0x90(%rbp), %rdx
movl -0xb0(%rbp), %ecx
movl -0x20(%rbp), %r9d
leaq -0x70(%rbp), %r8
callq 0x162b0
movq -0x88(%rbp), %rdi
movslq -0xac(%rbp), %rax
addq %rax, %rdi
movl -0x7c(%rbp), %esi
subl -0xac(%rbp), %esi
movq -0x90(%rbp), %rdx
movslq -0xb0(%rbp), %rax
addq %rax, %rdx
movl -0x80(%rbp), %ecx
subl -0xb0(%rbp), %ecx
movl -0x20(%rbp), %r9d
leaq -0x70(%rbp), %r8
callq 0x162b0
movq -0xa8(%rbp), %rax
movl -0xb8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
je 0x157c5
movq -0xa8(%rbp), %rax
movl -0xb8(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %esi
movq -0xa8(%rbp), %rax
movl -0xb8(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %edx
addl %esi, %edx
movw %dx, (%rax,%rcx,2)
movq -0xa8(%rbp), %rax
movl -0xb8(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %esi
movq -0xa8(%rbp), %rax
movl -0xb8(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %edx
addl %esi, %edx
movw %dx, (%rax,%rcx,2)
movl -0xb8(%rbp), %ecx
subl $0x2, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x15983
cmpl $0x3, -0x1c(%rbp)
jne 0x1583a
movq -0xa0(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x88(%rbp), %rdi
movl -0x7c(%rbp), %esi
movq -0x90(%rbp), %rdx
movl -0x80(%rbp), %ecx
leaq -0x70(%rbp), %r8
callq 0x160e0
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x70(%rbp), %rax
movq -0xa0(%rbp), %rcx
subq %rcx, %rax
sarq $0x2, %rax
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x15981
movq -0xa8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x98(%rbp), %rax
movl 0x10(%rax), %eax
cltd
idivl -0x20(%rbp)
movl %eax, %ecx
movq -0xd8(%rbp), %rax
shll %ecx
movslq %ecx, %rdx
xorl %ecx, %ecx
subq %rdx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movslq -0x74(%rbp), %rax
shrq %rax
movl %eax, -0xc0(%rbp)
movl $0x0, -0xbc(%rbp)
movl -0xbc(%rbp), %eax
cmpl -0xc0(%rbp), %eax
jge 0x158bd
movq -0xa8(%rbp), %rax
movslq -0xbc(%rbp), %rcx
movw $0x0, (%rax,%rcx,2)
movl -0xbc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xbc(%rbp)
jmp 0x1588a
movq -0x88(%rbp), %rdi
movl -0x7c(%rbp), %esi
movq -0x90(%rbp), %rdx
movl -0x80(%rbp), %ecx
movl -0x20(%rbp), %r9d
leaq -0x70(%rbp), %r8
callq 0x162b0
movl %eax, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0xa8(%rbp), %rax
movl -0xc0(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
je 0x1596e
movq -0xa8(%rbp), %rax
movl -0xc0(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %esi
movq -0xa8(%rbp), %rax
movl -0xc0(%rbp), %ecx
subl $0x3, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %edx
addl %esi, %edx
movw %dx, (%rax,%rcx,2)
movq -0xa8(%rbp), %rax
movl -0xc0(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %esi
movq -0xa8(%rbp), %rax
movl -0xc0(%rbp), %ecx
subl $0x4, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %edx
addl %esi, %edx
movw %dx, (%rax,%rcx,2)
movl -0xc0(%rbp), %ecx
subl $0x2, %ecx
movq -0x98(%rbp), %rax
movl %ecx, 0x8(%rax)
jmp 0x15983
jmp 0x15985
movq -0xa0(%rbp), %rcx
movq -0x98(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0xe0, %rsp
popq %rbp
retq
nopl (%rax)