// File: /workspace/github_c_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
movq %rdx, %r8
movl 0x28(%rdx), %r10d
movq 0x1ca1f(%rip), %rax     # 0x20260
movslq %r10d, %rbx
leaq (%rbx,%rbx,4), %rdx
movl 0x4(%rax,%rdx,8), %r11d
cmpl 0x1c96c(%rip), %r11d    # 0x201c0
jl 0x39a0
cmpl %edi, 0x18(%r8)
jl 0x39a0
movl %esi, %r9d
subl 0x10(%rcx), %r9d
jl 0x39a0
movl 0x10(%r8), %eax
movl 0x1c974(%rip), %r14d    # 0x201f0
movl %edi, %edx
subl %r14d, %edx
cmpl %edx, %eax
jg 0x39a0
addl %r14d, %esi
cmpl 0x18(%rcx), %esi
jg 0x39a0
subl %eax, %edi
leal (%rdi,%r14), %eax
decl %eax
cltd
idivl %r14d
testl %eax, %eax
je 0x39a0
movq (%r8), %r15
leal -0x1(%r14), %esi
leal (%rax,%rax), %edx
movslq %edx, %r12
movl 0x14(%r8), %edi
testl %eax, %eax
jle 0x38d3
movl $0x1, %eax
movzwl (%r15,%rax,2), %edx
addl %edx, %edi
addq $0x2, %rax
cmpq %r12, %rax
jl 0x38c3
addl %esi, %r9d
movl %r9d, %eax
cltd
idivl %r14d
addl %eax, %eax
movslq 0x8(%rcx), %r13
cmpl %r13d, %eax
jge 0x39a0
movzwl -0x4(%r15,%r12,2), %edx
movq (%rcx), %r15
movslq %eax, %r12
movzwl (%r15,%r12,2), %r9d
cmpw %dx, %r9w
cmovbel %edx, %r9d
movl 0x1c(%rcx), %edx
decq %r13
cmpl %eax, %r13d
jle 0x3920
movzwl (%r15,%r13,2), %eax
subl %eax, %edx
addq $-0x2, %r13
cmpq %r12, %r13
jg 0x3910
cmpl %edx, %edi
jge 0x39a0
movl 0x20(%r8), %r8d
andl $0x1, %r8d
movl %r11d, %ecx
subl %edx, %ecx
subl %edi, %r11d
testl %r8d, %r8d
cmovel %edx, %r11d
cmovel %edi, %ecx
movl %ecx, %eax
cltd
idivl %r14d
movl %eax, %edi
addl %r11d, %esi
movl %esi, %eax
cltd
idivl %r14d
movq 0x1c852(%rip), %rdx     # 0x201a8
movq 0x1c843(%rip), %rsi     # 0x201a0
addq (%rsi,%rbx,8), %rdx
movzwl %r9w, %esi
movl %eax, %r9d
subl %edi, %r9d
jle 0x39ad
movl 0x1c855(%rip), %ebx     # 0x201c8
movslq %edi, %r14
movslq %eax, %r15
xorl %edi, %edi
xorl %eax, %eax
movzbl (%rdx,%r14), %ebp
addl %ebp, %eax
xorl %r12d, %r12d
cmpl %ebp, %ebx
setle %r12b
addl %r12d, %edi
incq %r14
cmpq %r14, %r15
jne 0x397d
cltd
idivl %r9d
movl %eax, %edx
jmp 0x39c0
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %edi, %rax
movzbl (%rdx,%rax), %edx
xorl %edi, %edi
cmpl %edx, 0x1c80c(%rip)     # 0x201c8
setle %dil
movl %r10d, 0x1c8f1(%rip)    # 0x202b8
leaq 0x1c8ea(%rip), %rax     # 0x202b8
movl %r8d, 0x1c8e7(%rip)     # 0x202bc
movl %ecx, 0x1c8e5(%rip)     # 0x202c0
movl %r11d, 0x1c8e2(%rip)    # 0x202c4
movl %esi, 0x1c8e0(%rip)     # 0x202c8
movl %edi, 0x1c8de(%rip)     # 0x202cc
movl %edx, 0x1c8dc(%rip)     # 0x202d0
jmp 0x39a2