// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/align.c
// Function: Compute_Trace_MID
int Compute_Trace_MID(Alignment *align, Work_Data *ework, int trace_spacing, int mode)
{ _Work_Data *work = (_Work_Data *) ework;
  Trace_Waves wave;

  Path   *path;
  char   *aseq, *bseq;
  int     alen, blen;
  uint16 *points;
  int     tlen;
  int     ab, bb;
  int     ae, be;
  int     diffs, dmax;

  alen   = align->alen;
  blen   = align->blen;
  path   = align->path;
  aseq   = align->aseq;
  bseq   = align->bseq;
  tlen   = path->tlen;
  points = (uint16 *) path->trace;

  { int64 s;
    int   d;
    int   M, N;
    int   nmax;
    int   **PVF, **PHF;

    M = path->aepos-path->abpos;
    N = path->bepos-path->bbpos;
    if (M < N)
      s = N*sizeof(int);
    else
      s = M*sizeof(int);
    if (s > work->tramax)
      if (enlarge_trace(work,s))
        EXIT(1);

    nmax = 0;
    dmax = 0;
    for (d = 1; d < tlen; d += 2)
      { if (points[d-1] > dmax)
          dmax = points[d-1];
        if (points[d] > nmax)
          nmax = points[d];
      }
    if (tlen <= 1)
      nmax = N;
    if (dmax & 0x1)
      dmax += 1;

    s = (dmax+3)*4*((trace_spacing+nmax+3)*sizeof(int) + sizeof(int *));

    if (s > work->vecmax)
      if (enlarge_vector(work,s))
        EXIT(1);

    wave.PVF = PVF = ((int **) (work->vector)) + 2;
    wave.PHF = PHF = PVF + (dmax+3);

    s = trace_spacing+nmax+3;
    PVF[-2] = ((int *) (PHF + (dmax+1))) + (nmax+1);
    for (d = -1; d <= dmax; d++)
      PVF[d] = PVF[d-1] + s;
    PHF[-2] = PVF[dmax] + s;
    for (d = -1; d <= dmax; d++)
      PHF[d] = PHF[d-1] + s;
  }

  wave.Stop = ((int *) work->trace);
  wave.Aabs = aseq;
  wave.Babs = bseq;

  { int i, d;
    int as, bs;
    int af, bf;

    diffs = 0;
    ab = as = af = path->abpos;
    ae = (ab/trace_spacing)*trace_spacing;
    bb = bs = bf = path->bbpos;
    tlen -= 2;
    for (i = 1; i < tlen; i += 2) 
      { ae = ae + trace_spacing;
        be = bb + points[i];
        if (ae > alen || be > blen)
          { EPRINTF(EPLACE,"%s: %s\n",Prog_Name,TP_Error);
            EXIT(1);
          }
        if (middle_np(aseq+ab,ae-ab,bseq+bb,be-bb,&wave,mode,dmax))
          EXIT(1);
        af = wave.mida;
        bf = wave.midb;
        d  = iter_np(aseq+as,af-as,bseq+bs,bf-bs,&wave,mode,dmax);
        if (d < 0)
          EXIT(1);
        diffs += d;
        ab = ae;
        bb = be;
        as = af;
        bs = bf;
      }

    ae = path->aepos;
    be = path->bepos;

    if (ae > alen || be > blen)
      { EPRINTF(EPLACE,"%s: %s\n",Prog_Name,TP_Error);
        EXIT(1);
      }
    if (middle_np(aseq+ab,ae-ab,bseq+bb,be-bb,&wave,mode,dmax))
      EXIT(1);
    af = wave.mida;
    bf = wave.midb;
    d  = iter_np(aseq+as,af-as,bseq+bs,bf-bs,&wave,mode,dmax);
    if (d < 0)
      EXIT(1);
    diffs += d;
    as = af;
    bs = bf;
    
    d += iter_np(aseq+af,ae-as,bseq+bf,be-bs,&wave,mode,dmax);
    if (d < 0)
      EXIT(1);
    diffs += d;
  }

  path->trace = work->trace;
  path->tlen  = wave.Stop - ((int *) path->trace);
  path->diffs = diffs;

  return (0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %ecx, 0x1c(%rsp)
movq %rdx, 0x38(%rsp)
movq %rsi, %r13
movl 0x20(%rdi), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rdi), %eax
movl %eax, 0x20(%rsp)
movq (%rdi), %r12
movq 0x10(%rdi), %rax
movq %rax, 0x50(%rsp)
movq 0x18(%rdi), %r9
movl 0x18(%r12), %eax
subl 0x10(%r12), %eax
movslq 0x8(%r12), %r14
movl 0x1c(%r12), %ebx
subl 0x14(%r12), %ebx
movq (%r12), %rbp
cmpl %ebx, %eax
cmovlel %ebx, %eax
movslq %eax, %rsi
shlq $0x2, %rsi
movslq 0x30(%r13), %rax
cmpq %rax, %rsi
movq %r9, 0x30(%rsp)
jle 0xf762
movq %r13, %rdi
callq 0xedbc
movq 0x30(%rsp), %r9
xorl %eax, %eax
pushq $0x1
popq %rcx
xorl %r15d, %r15d
cmpq %r14, %rcx
jge 0xf78b
movzwl -0x2(%rbp,%rcx,2), %edx
cmpl %edx, %eax
cmovlel %edx, %eax
movzwl (%rbp,%rcx,2), %edx
cmpl %edx, %r15d
cmovlel %edx, %r15d
addq $0x2, %rcx
jmp 0xf76a
movq %rbp, 0x70(%rsp)
cmpl $0x2, %r14d
cmovll %ebx, %r15d
movl %eax, %ecx
andl $0x1, %ecx
leal (%rcx,%rax), %edi
leal (%rcx,%rax), %ebp
addl $0x3, %ebp
leal 0xc(,%rdi,4), %eax
movq 0x38(%rsp), %rcx
addl %r15d, %ecx
addl $0x3, %ecx
movslq %ecx, %rbx
leaq 0x8(,%rbx,4), %rsi
imulq %rax, %rsi
movslq (%r13), %rax
cmpq %rax, %rsi
movq %rdi, 0x28(%rsp)
jle 0xf7e7
movq %r13, %rdi
callq 0x3017
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %r9
movq 0x8(%r13), %rcx
leaq 0x10(%rcx), %rax
movq %rax, 0xa0(%rsp)
movl %ebp, %edx
leaq (%rcx,%rdx,8), %rsi
addq $0x10, %rsi
movq %rsi, 0xa8(%rsp)
movl %edi, %eax
leaq (%rsi,%rax,8), %rsi
movslq %r15d, %rdi
leaq 0xc(%rsi,%rdi,4), %rsi
movq %rsi, (%rcx)
pushq $-0x1
popq %rsi
shlq $0x2, %rbx
cmpq %rax, %rsi
jg 0xf838
movq 0x8(%rcx,%rsi,8), %rdi
addq %rbx, %rdi
movq %rdi, 0x10(%rcx,%rsi,8)
incq %rsi
jmp 0xf821
movq 0x10(%rcx,%rax,8), %rsi
addq %rbx, %rsi
leaq (%rcx,%rdx,8), %rcx
addq $0x8, %rcx
movq %rsi, -0x8(%rcx)
pushq $-0x1
popq %rdx
movq 0x50(%rsp), %rdi
cmpq %rax, %rdx
jg 0xf86a
movq (%rcx,%rdx,8), %rsi
addq %rbx, %rsi
movq %rsi, 0x8(%rcx,%rdx,8)
incq %rdx
jmp 0xf854
movq %r13, 0x68(%rsp)
movq 0x38(%r13), %rax
leaq 0x80(%rsp), %rcx
movq %rax, (%rcx)
movq %rdi, 0x10(%rcx)
movq %r9, 0x18(%rcx)
movl 0x10(%r12), %r13d
movq %r12, 0x48(%rsp)
movl 0x14(%r12), %r10d
movl %r13d, %eax
cltd
movq 0x38(%rsp), %rsi
idivl %esi
addl $-0x2, %r14d
movslq %r14d, %rax
movq %rax, 0x78(%rsp)
movl %r13d, %ecx
addl %esi, %ecx
subl %edx, %ecx
movl $0x0, 0x18(%rsp)
pushq $0x1
popq %rsi
movl %r13d, %ebp
movl %r10d, %r15d
movq 0x28(%rsp), %r14
movl 0x1c(%rsp), %r12d
movslq %r13d, %rax
movl %ecx, %r13d
movslq %r10d, %rdx
movslq %ebp, %rcx
movq %rcx, 0x58(%rsp)
movslq %r15d, %rcx
movq %rcx, 0x60(%rsp)
cmpq 0x78(%rsp), %rsi
jge 0xf9b5
cmpl 0x24(%rsp), %r13d
jg 0xfac7
movq 0x70(%rsp), %rcx
movzwl (%rcx,%rsi,2), %ecx
addl %ecx, %r10d
cmpl 0x20(%rsp), %r10d
jg 0xfac7
movq %rsi, 0x40(%rsp)
movl %r10d, 0x14(%rsp)
movq %rdi, %rbx
addq %rax, %rdi
movl %r13d, %esi
subl %eax, %esi
addq %r9, %rdx
movl %r14d, (%rsp)
leaq 0x80(%rsp), %r8
movl %r12d, %r9d
callq 0xfaf8
movl 0xb0(%rsp), %ebp
movl 0xb4(%rsp), %r15d
movq 0x58(%rsp), %rax
leaq (%rbx,%rax), %rdi
movl %ebp, %esi
subl %eax, %esi
movq 0x60(%rsp), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rax), %rdx
movl %r15d, %ecx
subl %eax, %ecx
movl %r14d, (%rsp)
leaq 0x80(%rsp), %r8
movl %r12d, %r9d
callq 0xee06
testl %eax, %eax
js 0xfaf0
addl %eax, 0x18(%rsp)
movq 0x40(%rsp), %rsi
addq $0x2, %rsi
movq 0x38(%rsp), %rax
leal (%rax,%r13), %ecx
movq 0x30(%rsp), %r9
movq 0x50(%rsp), %rdi
movl 0x14(%rsp), %r10d
jmp 0xf8ce
movq 0x48(%rsp), %rcx
movl 0x18(%rcx), %esi
cmpl 0x24(%rsp), %esi
jg 0xfac7
movl 0x1c(%rcx), %ecx
cmpl 0x20(%rsp), %ecx
jg 0xfac7
movq %rdi, %r14
addq %rax, %rdi
movl %esi, 0x40(%rsp)
subl %eax, %esi
leaq (%r9,%rdx), %rax
movl %ecx, 0x14(%rsp)
subl %edx, %ecx
movq 0x28(%rsp), %r13
movl %r13d, (%rsp)
leaq 0x80(%rsp), %r15
movq %rax, %rdx
movq %r15, %r8
movl 0x1c(%rsp), %r12d
movq %r9, %rbx
movl %r12d, %r9d
callq 0xfaf8
movq %r15, %r8
movslq 0x30(%r15), %rbp
movslq 0x34(%r15), %r15
movq 0x58(%rsp), %rax
leaq (%r14,%rax), %rdi
movl %ebp, %esi
subl %eax, %esi
movq 0x60(%rsp), %rax
leaq (%rbx,%rax), %rdx
movl %r15d, %ecx
subl %eax, %ecx
movl %r13d, (%rsp)
movl %r12d, %r9d
callq 0xee06
testl %eax, %eax
js 0xfaf0
movl %eax, %r13d
addq %rbp, %r14
movl 0x40(%rsp), %esi
subl %ebp, %esi
addq %r15, %rbx
movl 0x14(%rsp), %ecx
subl %r15d, %ecx
movq 0x28(%rsp), %rax
movl %eax, (%rsp)
leaq 0x80(%rsp), %r8
movq %r14, %rdi
movq %rbx, %rdx
movl %r12d, %r9d
callq 0xee06
addl %r13d, %eax
js 0xfaf0
addl 0x18(%rsp), %r13d
addl %eax, %r13d
movq 0x68(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x48(%rsp), %rdx
movq %rax, (%rdx)
movq 0x80(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl %ecx, 0x8(%rdx)
movl %r13d, 0xc(%rdx)
xorl %eax, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xe52a(%rip), %rax      # 0x1dff8
movq (%rax), %rdi
leaq 0xe818(%rip), %rax      # 0x1e2f0
movq (%rax), %rdx
leaq 0x8b7a(%rip), %rsi      # 0x1865c
leaq 0x8bd6(%rip), %rcx      # 0x186bf
xorl %eax, %eax
callq 0x11a0
pushq $0x1
popq %rdi
callq 0x1280