// File: /workspace/github_c_makefile_star2_O3/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 $0xb8, %rsp
movl %ecx, %ebx
movl %edx, %r9d
movq %rsi, %rdx
movl 0x20(%rdi), %eax
movl %eax, 0x24(%rsp)
movl 0x24(%rdi), %eax
movl %eax, 0x20(%rsp)
movq (%rdi), %r13
movq 0x10(%rdi), %rax
movq %rax, 0x68(%rsp)
movq 0x18(%rdi), %r14
movl 0x18(%r13), %eax
subl 0x10(%r13), %eax
movl 0x8(%r13), %r10d
movl 0x1c(%r13), %ebp
subl 0x14(%r13), %ebp
movq (%r13), %r11
cmpl %ebp, %eax
cmovlel %ebp, %eax
movslq %eax, %rsi
shlq $0x2, %rsi
movslq 0x30(%rdx), %rax
cmpq %rax, %rsi
movq %rdx, 0x28(%rsp)
movq %r9, 0x48(%rsp)
movq %r11, 0x40(%rsp)
jle 0x10cca
movq %rdx, %rdi
movq %r10, %r15
callq 0x10333
movq 0x40(%rsp), %r11
movq %r15, %r10
movq 0x48(%rsp), %r9
movq 0x28(%rsp), %rdx
movq %r14, 0x50(%rsp)
movl %ebx, 0x8(%rsp)
xorl %ebx, %ebx
movl $0x0, %r12d
cmpl $0x2, %r10d
jl 0x10d0b
xorl %r12d, %r12d
movl $0x1, %eax
xorl %ebx, %ebx
movzwl -0x2(%r11,%rax,2), %ecx
cmpl %ecx, %ebx
cmovlel %ecx, %ebx
movzwl (%r11,%rax,2), %ecx
cmpl %ecx, %r12d
cmovlel %ecx, %r12d
addq $0x2, %rax
cmpq %r10, %rax
jb 0x10ceb
cmpl $0x2, %r10d
cmovll %ebp, %r12d
movl %ebx, %r15d
andl $0x1, %r15d
leal (%r15,%rbx), %edi
leal (%r15,%rbx), %ebp
addl $0x3, %ebp
leal 0xc(,%rdi,4), %eax
leal (%r9,%r12), %ecx
addl $0x3, %ecx
movslq %ecx, %r14
leaq 0x8(,%r14,4), %rsi
imulq %rax, %rsi
movslq (%rdx), %rax
cmpq %rax, %rsi
movq %rdi, 0x30(%rsp)
jle 0x10d75
movq %rdx, %rdi
movq %r10, 0x38(%rsp)
callq 0x4220
movq 0x40(%rsp), %r11
movq 0x38(%rsp), %r10
movq 0x48(%rsp), %r9
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rdx
movq 0x8(%rdx), %rcx
leaq 0x10(%rcx), %rax
movq %rax, 0x90(%rsp)
movl %ebp, %eax
leaq (%rcx,%rax,8), %rdx
addq $0x10, %rdx
movq %rdx, 0x98(%rsp)
movl %edi, %eax
leaq (%rdx,%rax,8), %rsi
movslq %r12d, %rdi
leaq (%rsi,%rdi,4), %rsi
addq $0xc, %rsi
movq %rsi, (%rcx)
movq %rax, %rsi
shlq $0x4, %rsi
leaq (%rsi,%rdi,4), %rsi
leaq (%rsi,%r14,4), %rsi
shlq $0x2, %r14
addq %rcx, %rsi
addq $0x34, %rsi
leaq 0x2(%rax), %rdi
xorl %r8d, %r8d
movq %rsi, 0x8(%rcx,%r8,8)
addq %r14, %rsi
incq %r8
cmpq %r8, %rdi
jne 0x10dcc
movq 0x10(%rcx,%rax,8), %rsi
addq %r14, %rsi
movq %rsi, -0x10(%rdx)
movl %ebx, %edx
addq %rdx, %r15
movq 0x18(%rcx,%r15,8), %rdx
addq %r14, %rdx
leaq (%rcx,%rax,8), %rcx
addq $0x20, %rcx
addq $0x2, %rax
xorl %esi, %esi
movq %rdx, (%rcx,%rsi,8)
addq %r14, %rdx
incq %rsi
cmpq %rsi, %rax
jne 0x10e03
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x70(%rsp)
movq 0x68(%rsp), %rdi
movq %rdi, 0x80(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x88(%rsp)
movl 0x10(%r13), %r12d
movq %r13, 0x60(%rsp)
movl 0x14(%r13), %r8d
xorl %ebp, %ebp
cmpl $0x4, %r10d
jl 0x10f63
addl $-0x2, %r10d
movl %r12d, %eax
cltd
idivl %r9d
movl %r12d, %esi
subl %edx, %esi
xorl %ebp, %ebp
movl $0x1, %r14d
movl %r12d, 0x18(%rsp)
movl %r12d, %edx
movl %r8d, %eax
movq %r10, 0x38(%rsp)
movq 0x50(%rsp), %r13
movl %r8d, 0x14(%rsp)
movl %ebp, 0x10(%rsp)
leal (%rsi,%r9), %ecx
movl %ecx, 0xc(%rsp)
cmpl 0x24(%rsp), %ecx
jg 0x1109f
movzwl (%r11,%r14,2), %ecx
leal (%rax,%rcx), %r8d
movl %r8d, 0x5c(%rsp)
cmpl 0x20(%rsp), %r8d
jg 0x1109f
movslq %edx, %rdx
movq %rdi, %r15
addq %rdx, %rdi
addl %r9d, %esi
subl %edx, %esi
movslq %eax, %rdx
addq %r13, %rdx
movq 0x30(%rsp), %rbp
movl %ebp, (%rsp)
leaq 0x70(%rsp), %r8
movl 0x8(%rsp), %ebx
movl %ebx, %r9d
callq 0x110a9
movl 0xa0(%rsp), %r12d
movl 0xa4(%rsp), %ecx
movslq 0x18(%rsp), %rax
leaq (%r15,%rax), %rdi
movl %ecx, %r15d
movl %r12d, %esi
subl %eax, %esi
movslq 0x14(%rsp), %rax
leaq (%rax,%r13), %rdx
subl %eax, %ecx
movl %ebp, (%rsp)
leaq 0x70(%rsp), %r8
movl %ebx, %r9d
callq 0x1037f
testl %eax, %eax
js 0x11095
movl 0x10(%rsp), %ebp
addl %eax, %ebp
addq $0x2, %r14
movl %r15d, %r8d
movl %r12d, 0x18(%rsp)
movl 0xc(%rsp), %ebx
movl %ebx, %edx
movl 0x5c(%rsp), %ecx
movl %ecx, %eax
movl %ebx, %esi
movq 0x38(%rsp), %r10
cmpl %r14d, %r10d
movq 0x68(%rsp), %rdi
movq 0x48(%rsp), %r9
movq 0x40(%rsp), %r11
jg 0x10e80
jmp 0x10f6c
movl %r8d, %ecx
movl %r12d, %ebx
movl %r8d, %r15d
movl %r12d, 0x14(%rsp)
movl %r15d, 0x18(%rsp)
movq 0x60(%rsp), %rax
movl 0x18(%rax), %r15d
cmpl 0x24(%rsp), %r15d
jg 0x110a4
movl 0x1c(%rax), %r8d
cmpl 0x20(%rsp), %r8d
jg 0x110a4
movslq %ebx, %rax
movq %rdi, %rbx
addq %rax, %rdi
movl %r15d, %esi
movl %r15d, 0xc(%rsp)
subl %eax, %esi
movslq %ecx, %rax
movq 0x50(%rsp), %r14
leaq (%r14,%rax), %rdx
movl %r8d, 0x10(%rsp)
movl %r8d, %ecx
subl %eax, %ecx
movq 0x30(%rsp), %r15
movl %r15d, (%rsp)
leaq 0x70(%rsp), %r12
movq %r12, %r8
movl 0x8(%rsp), %r13d
movl %r13d, %r9d
callq 0x110a9
movq %r12, %r8
movslq 0x30(%r12), %r12
movslq 0x34(%r8), %rcx
movslq 0x14(%rsp), %rax
leaq (%rbx,%rax), %rdi
movl %r12d, %esi
subl %eax, %esi
movslq 0x18(%rsp), %rax
leaq (%r14,%rax), %rdx
movq %rcx, 0x18(%rsp)
subl %eax, %ecx
movl %r15d, (%rsp)
movl %r13d, %r9d
callq 0x1037f
testl %eax, %eax
js 0x11095
movl %eax, %r13d
addq %r12, %rbx
movl 0xc(%rsp), %esi
subl %r12d, %esi
movq 0x18(%rsp), %rax
addq %rax, %r14
movl 0x10(%rsp), %ecx
subl %eax, %ecx
movq 0x30(%rsp), %rax
movl %eax, (%rsp)
leaq 0x70(%rsp), %r8
movq %rbx, %rdi
movq %r14, %rdx
movl 0x8(%rsp), %r9d
callq 0x1037f
addl %r13d, %eax
js 0x11095
addl %ebp, %r13d
addl %eax, %r13d
movq 0x28(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x60(%rsp), %rdx
movq %rax, (%rdx)
movq 0x70(%rsp), %rcx
subq %rax, %rcx
shrq $0x2, %rcx
movl %ecx, 0x8(%rdx)
movl %r13d, 0xc(%rdx)
xorl %eax, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %edi
callq 0x1280
callq 0x141d
callq 0x13eb