// File: /workspace/github_c_makefile_star2_O1/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 0x1ca16(%rip), %rax     # 0x20260
movslq %r10d, %rbx
leaq (%rbx,%rbx,4), %rdx
movl 0x4(%rax,%rdx,8), %r11d
cmpl 0x1c963(%rip), %r11d    # 0x201c0
jl 0x39ac
cmpl %edi, 0x18(%r8)
jl 0x39ac
movl %esi, %r9d
subl 0x10(%rcx), %r9d
jl 0x39ac
movl 0x10(%r8), %eax
movl 0x1c96b(%rip), %r14d    # 0x201f0
movl %edi, %edx
subl %r14d, %edx
cmpl %edx, %eax
jg 0x39ac
addl %r14d, %esi
cmpl 0x18(%rcx), %esi
jg 0x39ac
subl %eax, %edi
leal (%rdi,%r14), %eax
decl %eax
cltd
idivl %r14d
testl %eax, %eax
je 0x39ac
movq (%r8), %r15
leal -0x1(%r14), %esi
leal (%rax,%rax), %ebp
movl 0x14(%r8), %edi
testl %eax, %eax
jle 0x38dc
movl %ebp, %eax
movl $0x1, %edx
movzwl (%r15,%rdx,2), %r12d
addl %r12d, %edi
addq $0x2, %rdx
cmpq %rax, %rdx
jb 0x38cb
addl %esi, %r9d
movl %r9d, %eax
cltd
idivl %r14d
addl %eax, %eax
movslq 0x8(%rcx), %r12
cmpl %r12d, %eax
jge 0x39ac
movslq %ebp, %rdx
movzwl -0x4(%r15,%rdx,2), %edx
movq (%rcx), %r15
movslq %eax, %r13
movzwl (%r15,%r13,2), %r9d
cmpw %dx, %r9w
cmovbel %edx, %r9d
movl 0x1c(%rcx), %edx
decq %r12
cmpl %eax, %r12d
jle 0x392c
movzwl (%r15,%r12,2), %eax
subl %eax, %edx
addq $-0x2, %r12
cmpq %r13, %r12
jg 0x391c
cmpl %edx, %edi
jge 0x39ac
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 0x1c846(%rip), %rdx     # 0x201a8
movq 0x1c837(%rip), %rsi     # 0x201a0
addq (%rsi,%rbx,8), %rdx
movzwl %r9w, %esi
movl %eax, %r9d
subl %edi, %r9d
jle 0x39b9
movl 0x1c849(%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 0x3989
cltd
idivl %r9d
movl %eax, %edx
jmp 0x39cc
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, 0x1c800(%rip)     # 0x201c8
setle %dil
movl %r10d, 0x1c8e5(%rip)    # 0x202b8
leaq 0x1c8de(%rip), %rax     # 0x202b8
movl %r8d, 0x1c8db(%rip)     # 0x202bc
movl %ecx, 0x1c8d9(%rip)     # 0x202c0
movl %r11d, 0x1c8d6(%rip)    # 0x202c4
movl %esi, 0x1c8d4(%rip)     # 0x202c8
movl %edi, 0x1c8d2(%rip)     # 0x202cc
movl %edx, 0x1c8d0(%rip)     # 0x202d0
jmp 0x39ae