// File: /workspace/github_c_makefile_star2_O1/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, %ebx
movl %edx, %r14d
movq %rsi, %rdx
movl 0x20(%rdi), %eax
movl %eax, 0x34(%rsp)
movl 0x24(%rdi), %eax
movl %eax, 0x30(%rsp)
movq (%rdi), %r13
movq 0x10(%rdi), %rax
movq %rax, 0x58(%rsp)
movq 0x18(%rdi), %rax
movq %rax, 0x60(%rsp)
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, 0x38(%rsp)
movq %r11, 0x50(%rsp)
jle 0x10e4c
movq %rdx, %rdi
movq %r10, %r15
callq 0x1055f
movq 0x50(%rsp), %r11
movq %r15, %r10
movq 0x38(%rsp), %rdx
movl %ebx, 0x2c(%rsp)
xorl %ebx, %ebx
movl $0x0, %r12d
cmpl $0x2, %r10d
jl 0x10e88
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 0x10e68
cmpl $0x2, %r10d
cmovll %ebp, %r12d
movl %ebx, %r15d
andl $0x1, %r15d
leal (%r15,%rbx), %eax
leal (%r15,%rbx), %ebp
addl $0x3, %ebp
movq %rax, 0x40(%rsp)
leal 0xc(,%rax,4), %eax
movq %r14, 0x78(%rsp)
leal (%r14,%r12), %ecx
addl $0x3, %ecx
movslq %ecx, %r14
leaq 0x8(,%r14,4), %rsi
imulq %rax, %rsi
movslq (%rdx), %rax
cmpq %rax, %rsi
jle 0x10eed
movq %rdx, %rdi
movq %r10, 0x48(%rsp)
callq 0x4252
movq 0x50(%rsp), %r11
movq 0x48(%rsp), %r10
movq 0x38(%rsp), %rdx
movq 0x8(%rdx), %rax
leaq 0x10(%rax), %rcx
movq %rcx, 0xa0(%rsp)
movl %ebp, %ecx
leaq (%rax,%rcx,8), %rdx
addq $0x10, %rdx
movq %rdx, 0xa8(%rsp)
movq 0x40(%rsp), %r9
movl %r9d, %ecx
leaq (%rdx,%rcx,8), %rsi
movslq %r12d, %rdi
leaq (%rsi,%rdi,4), %rsi
addq $0xc, %rsi
movq %rsi, (%rax)
movq %rcx, %rsi
shlq $0x4, %rsi
leaq (%rsi,%rdi,4), %rsi
leaq (%rsi,%r14,4), %rsi
shlq $0x2, %r14
addq %rax, %rsi
addq $0x34, %rsi
leaq 0x2(%r9), %rdi
xorl %r8d, %r8d
movq %rsi, 0x8(%rax,%r8,8)
addq %r14, %rsi
incq %r8
cmpq %r8, %rdi
jne 0x10f4a
movq 0x10(%rax,%rcx,8), %rsi
addq %r14, %rsi
movq %rsi, -0x10(%rdx)
movl %ebx, %edx
addq %rdx, %r15
movq 0x18(%rax,%r15,8), %rdx
addq %r14, %rdx
leaq (%rax,%rcx,8), %rax
addq $0x20, %rax
leaq 0x2(%r9), %rcx
xorl %esi, %esi
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %r8
movq %rdx, (%rax,%rsi,8)
addq %r14, %rdx
incq %rsi
cmpq %rsi, %rcx
jne 0x10f8b
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x80(%rsp)
movq %r8, 0x90(%rsp)
movq %rdi, 0x98(%rsp)
movl 0x10(%r13), %r12d
movq %r13, 0x70(%rsp)
movl 0x14(%r13), %edi
cmpl $0x4, %r10d
jl 0x110ea
addl $-0x2, %r10d
movl %r12d, %eax
cltd
movq 0x78(%rsp), %r8
idivl %r8d
movl %r12d, %esi
subl %edx, %esi
movl $0x0, 0x14(%rsp)
movl $0x1, %ebp
movl %r12d, %edx
movl %edi, %eax
movq %r10, 0x48(%rsp)
movq 0x60(%rsp), %r13
movl %r12d, 0x1c(%rsp)
movl %edi, 0x20(%rsp)
leal (%rsi,%r8), %ecx
movl %ecx, 0x18(%rsp)
cmpl 0x34(%rsp), %ecx
jg 0x11239
movzwl (%r11,%rbp,2), %ecx
leal (%rax,%rcx), %edi
movl %edi, 0x6c(%rsp)
cmpl 0x30(%rsp), %edi
jg 0x11239
movslq %edx, %rdx
movq 0x58(%rsp), %r15
leaq (%r15,%rdx), %rdi
addl %r8d, %esi
subl %edx, %esi
movslq %eax, %rdx
addq %r13, %rdx
movq 0x40(%rsp), %r14
movl %r14d, (%rsp)
leaq 0x80(%rsp), %r8
movl 0x2c(%rsp), %r12d
movl %r12d, %r9d
callq 0x11243
movl 0xb0(%rsp), %ebx
movl 0xb4(%rsp), %ecx
movslq 0x1c(%rsp), %rax
leaq (%r15,%rax), %rdi
movl %ecx, %r15d
movl %ebx, %esi
subl %eax, %esi
movslq 0x20(%rsp), %rax
leaq (%rax,%r13), %rdx
subl %eax, %ecx
movl %r14d, (%rsp)
leaq 0x80(%rsp), %r8
movl %r12d, %r9d
callq 0x105ab
testl %eax, %eax
js 0x1122f
addl %eax, 0x14(%rsp)
addq $0x2, %rbp
movl %r15d, %edi
movl %ebx, %r12d
movl 0x18(%rsp), %r9d
movl %r9d, %edx
movl 0x6c(%rsp), %ecx
movl %ecx, %eax
movl %r9d, %esi
movq 0x48(%rsp), %r10
cmpl %ebp, %r10d
movq 0x78(%rsp), %r8
movq 0x50(%rsp), %r11
movl %ebx, %r14d
jg 0x11003
jmp 0x110fd
movl $0x0, 0x14(%rsp)
movl %edi, %ecx
movl %r12d, %r9d
movl %r12d, %r14d
movl %edi, %r15d
movl %r15d, 0x20(%rsp)
movq 0x70(%rsp), %rax
movl 0x18(%rax), %r15d
cmpl 0x34(%rsp), %r15d
jg 0x1123e
movl 0x1c(%rax), %r8d
cmpl 0x30(%rsp), %r8d
jg 0x1123e
movslq %r9d, %rax
movq 0x58(%rsp), %rbx
leaq (%rbx,%rax), %rdi
movl %r15d, %esi
movl %r15d, 0x18(%rsp)
subl %eax, %esi
movslq %ecx, %rax
movq 0x60(%rsp), %r12
leaq (%r12,%rax), %rdx
movl %r8d, 0x1c(%rsp)
movl %r8d, %ecx
subl %eax, %ecx
movq 0x40(%rsp), %r15
movl %r15d, (%rsp)
leaq 0x80(%rsp), %rbp
movq %rbp, %r8
movl 0x2c(%rsp), %r13d
movl %r13d, %r9d
callq 0x11243
movq %rbp, %r8
movslq 0x30(%rbp), %rbp
movslq 0x34(%r8), %rcx
movslq %r14d, %rax
movl %r13d, %r14d
leaq (%rbx,%rax), %rdi
movl %ebp, %esi
subl %eax, %esi
movslq 0x20(%rsp), %rax
leaq (%r12,%rax), %rdx
movq %rcx, 0x20(%rsp)
subl %eax, %ecx
movl %r15d, (%rsp)
movl %r13d, %r9d
callq 0x105ab
testl %eax, %eax
js 0x1122f
movl %eax, %r13d
addq %rbp, %rbx
movl 0x18(%rsp), %esi
subl %ebp, %esi
movq 0x20(%rsp), %rax
addq %rax, %r12
movl 0x1c(%rsp), %ecx
subl %eax, %ecx
movq 0x40(%rsp), %rax
movl %eax, (%rsp)
leaq 0x80(%rsp), %r8
movq %rbx, %rdi
movq %r12, %rdx
movl %r14d, %r9d
callq 0x105ab
addl %r13d, %eax
js 0x1122f
addl 0x14(%rsp), %r13d
addl %eax, %r13d
movq 0x38(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x70(%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
movl $0x1, %edi
callq 0x1280
callq 0x141d
callq 0x13eb