// File: /workspace/github_c_makefile_star2_O2/thegenemyers[P]DASCRUBBER/DASpatch.c
// Function: compute_patch
static Patch *compute_patch(int lft, int rgt, Overlap *lov, Overlap *rov)
{ static Patch ans;

  uint16  *tr;
  int      bread, bcomp, blen;
  int      bb, be;
  int      t, te;
  int      bl, br;
  uint8   *qb;
  int      avg, anc, bad;

  bread = lov->bread;
  bcomp = COMP(lov->flags);
  blen = DB->reads[bread].rlen;
  if (blen < HGAP_MIN)
    return (NULL);

  if (lft > lov->path.aepos || rgt < rov->path.abpos)   // Cannot anchor
    return (NULL);
  if (lov->path.abpos > lft-TRACE_SPACING || rgt+TRACE_SPACING > rov->path.aepos)
    return (NULL);

  //  Get max of left and right anchors as anchor score

  tr = (uint16 *) lov->path.trace;
  te = 2 * (((lft + (TRACE_SPACING-1)) - lov->path.abpos)/TRACE_SPACING);
  if (te == 0)
    return (NULL);
  anc = tr[te-2];

  bb = lov->path.bbpos;
  for (t = 1; t < te; t += 2)
    bb += tr[t];

  tr = (uint16 *) rov->path.trace;
  te = 2 * (((rgt + (TRACE_SPACING-1)) - rov->path.abpos)/TRACE_SPACING);
  if (te >= rov->path.tlen)
    return (NULL);
  if (tr[te] > anc)
    anc = tr[te];

  be = rov->path.bepos;
  for (t = rov->path.tlen-1; t > te; t -= 2)
    be -= tr[t];

  if (bb >= be)
    return (NULL);

  //  Compute metrics for b-read patch

  if (bcomp)
    { t  = blen - be;
      be = blen - bb;
      bb = t;
    }

  bl = bb/TRACE_SPACING;
  br = (be+(TRACE_SPACING-1))/TRACE_SPACING;
  qb = QV + QV_IDX[bread];
  if (bl >= br)
    { avg = qb[bl];
      if (avg >= BAD_QV)
        bad = 1;
      else
        bad = 0;
    }
  else
    { avg = 0;
      bad = 0;
      for (t = bl; t < br; t++)
        { avg += qb[t];
          if (qb[t] >= BAD_QV)
            bad += 1;
        }
      avg /= (br-bl);
    }

  ans.bread = bread;
  ans.comp  = bcomp;
  ans.beg   = bb;
  ans.end   = be;
  ans.anc   = anc;
  ans.bad   = bad;
  ans.avg   = avg;

  return (&ans);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rdx, %r8
movl 0x28(%rdx), %r10d
movq 0x1bbec(%rip), %rax     # 0x1e260
movslq %r10d, %r14
imulq $0x28, %r14, %rdx
movl 0x4(%rax,%rdx), %r11d
cmpl 0x1bb39(%rip), %r11d    # 0x1e1c0
jl 0x27ca
cmpl %edi, 0x18(%r8)
jl 0x27ca
movl %esi, %r9d
subl 0x10(%rcx), %r9d
jl 0x27ca
movl 0x10(%r8), %eax
movl 0x1bb41(%rip), %r15d    # 0x1e1f0
movl %edi, %edx
subl %r15d, %edx
cmpl %edx, %eax
jg 0x27ca
addl %r15d, %esi
cmpl 0x18(%rcx), %esi
jg 0x27ca
subl %eax, %edi
leal (%rdi,%r15), %eax
decl %eax
cltd
idivl %r15d
testl %eax, %eax
je 0x27ca
movl 0x20(%r8), %ebx
andl $0x1, %ebx
movq (%r8), %rdx
leal -0x1(%r15), %esi
addl %eax, %eax
cltq
movzwl -0x4(%rdx,%rax,2), %ebp
movl 0x14(%r8), %edi
movabsq $0x1, %r8
cmpq %rax, %r8
jge 0x2714
movzwl (%rdx,%r8,2), %r12d
addl %r12d, %edi
addq $0x2, %r8
jmp 0x2701
addl %esi, %r9d
movl %r9d, %eax
cltd
idivl %r15d
addl %eax, %eax
movslq 0x8(%rcx), %rdx
cmpl %edx, %eax
jge 0x27ca
movq (%rcx), %r9
movslq %eax, %r12
movzwl (%r9,%r12,2), %r8d
cmpw %bp, %r8w
cmovbel %ebp, %r8d
movl 0x1c(%rcx), %eax
decq %rdx
cmpq %r12, %rdx
jle 0x2757
movzwl (%r9,%rdx,2), %ecx
subl %ecx, %eax
addq $-0x2, %rdx
jmp 0x2745
cmpl %eax, %edi
jge 0x27ca
movl %r11d, %ecx
subl %eax, %ecx
subl %edi, %r11d
testl %ebx, %ebx
cmovel %eax, %r11d
cmovel %edi, %ecx
movl %ecx, %eax
cltd
idivl %r15d
movl %eax, %edi
addl %r11d, %esi
movl %esi, %eax
cltd
idivl %r15d
movq 0x1ba24(%rip), %rdx     # 0x1e1a8
movq 0x1ba15(%rip), %rsi     # 0x1e1a0
addq (%rsi,%r14,8), %rdx
movzwl %r8w, %esi
movl %eax, %r8d
subl %edi, %r8d
jle 0x27d5
movl 0x1ba26(%rip), %r9d     # 0x1e1c8
movslq %edi, %r14
movslq %eax, %r15
xorl %eax, %eax
xorl %edi, %edi
cmpq %r15, %r14
jge 0x27ea
movzbl (%rdx,%r14), %ebp
addl %ebp, %eax
xorl %r12d, %r12d
cmpl %ebp, %r9d
setle %r12b
addl %r12d, %edi
incq %r14
jmp 0x27ac
xorl %eax, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movslq %edi, %rax
movzbl (%rdx,%rax), %edx
xorl %edi, %edi
cmpl %edx, 0x1b9e4(%rip)     # 0x1e1c8
setle %dil
jmp 0x27f0
cltd
idivl %r8d
movl %eax, %edx
movl %r10d, 0x1bac1(%rip)    # 0x1e2b8
leaq 0x1baba(%rip), %rax     # 0x1e2b8
movl %ebx, 0x1bab8(%rip)     # 0x1e2bc
movl %ecx, 0x1bab6(%rip)     # 0x1e2c0
movl %r11d, 0x1bab3(%rip)    # 0x1e2c4
movl %esi, 0x1bab1(%rip)     # 0x1e2c8
movl %edi, 0x1baaf(%rip)     # 0x1e2cc
movl %edx, 0x1baad(%rip)     # 0x1e2d0
jmp 0x27cc