// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
movl %edi, -0xc(%rbp)
movl %esi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl 0x20(%rax), %eax
andl $0x1, %eax
movl %eax, -0x30(%rbp)
movq 0x271c8(%rip), %rax     # 0x2b188
movq 0x60(%rax), %rax
movslq -0x2c(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x27442(%rip), %eax     # 0x2b420
jge 0x3fed
movq $0x0, -0x8(%rbp)
jmp 0x42c8
movl -0xc(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jg 0x4005
movl -0x10(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x4012
movq $0x0, -0x8(%rbp)
jmp 0x42c8
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl -0xc(%rbp), %ecx
subl 0x2742e(%rip), %ecx     # 0x2b450
cmpl %ecx, %eax
jg 0x4038
movl -0x10(%rbp), %eax
addl 0x27421(%rip), %eax     # 0x2b450
movq -0x20(%rbp), %rcx
cmpl 0x18(%rcx), %eax
jle 0x4045
movq $0x0, -0x8(%rbp)
jmp 0x42c8
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %eax
movl 0x273f7(%rip), %ecx     # 0x2b450
subl $0x1, %ecx
addl %ecx, %eax
movq -0x18(%rbp), %rcx
subl 0x10(%rcx), %eax
cltd
idivl 0x273e4(%rip)           # 0x2b450
shll %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jne 0x4084
movq $0x0, -0x8(%rbp)
jmp 0x42c8
movq -0x28(%rbp), %rax
movl -0x44(%rbp), %ecx
subl $0x2, %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x60(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x38(%rbp)
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x40ce
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x40(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x40(%rbp)
jmp 0x40a9
movq -0x20(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl -0x10(%rbp), %eax
movl 0x2736e(%rip), %ecx     # 0x2b450
subl $0x1, %ecx
addl %ecx, %eax
movq -0x20(%rbp), %rcx
subl 0x10(%rcx), %eax
cltd
idivl 0x2735b(%rip)           # 0x2b450
shll %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jl 0x4113
movq $0x0, -0x8(%rbp)
jmp 0x42c8
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
cmpl -0x60(%rbp), %eax
jle 0x4133
movq -0x28(%rbp), %rax
movslq -0x44(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
movl %eax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movl 0x1c(%rax), %eax
movl %eax, -0x3c(%rbp)
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x44(%rbp), %eax
jle 0x4171
movq -0x28(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzwl (%rax,%rcx,2), %ecx
movl -0x3c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x40(%rbp)
jmp 0x414a
movl -0x38(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jl 0x4186
movq $0x0, -0x8(%rbp)
jmp 0x42c8
cmpl $0x0, -0x30(%rbp)
je 0x41a4
movl -0x34(%rbp), %eax
subl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %eax
subl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x40(%rbp), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cltd
idivl 0x272a2(%rip)           # 0x2b450
movl %eax, -0x48(%rbp)
movl -0x3c(%rbp), %eax
movl 0x27296(%rip), %ecx     # 0x2b450
subl $0x1, %ecx
addl %ecx, %eax
cltd
idivl 0x2728a(%rip)           # 0x2b450
movl %eax, -0x4c(%rbp)
movq 0x27238(%rip), %rax     # 0x2b408
movq 0x27229(%rip), %rcx     # 0x2b400
movslq -0x2c(%rbp), %rdx
addq (%rcx,%rdx,8), %rax
movq %rax, -0x58(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jl 0x4217
movq -0x58(%rbp), %rax
movslq -0x48(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl 0x27225(%rip), %eax     # 0x2b428
jl 0x420e
movl $0x1, -0x64(%rbp)
jmp 0x4215
movl $0x0, -0x64(%rbp)
jmp 0x427e
movl $0x0, -0x5c(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x426f
movq -0x58(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movq -0x58(%rbp), %rax
movslq -0x40(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl 0x271d1(%rip), %eax     # 0x2b428
jl 0x4262
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x4264
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x422b
movl -0x4c(%rbp), %ecx
subl -0x48(%rbp), %ecx
movl -0x5c(%rbp), %eax
cltd
idivl %ecx
movl %eax, -0x5c(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, 0x27291(%rip)     # 0x2b518
movl -0x30(%rbp), %eax
movl %eax, 0x2728c(%rip)     # 0x2b51c
movl -0x38(%rbp), %eax
movl %eax, 0x27287(%rip)     # 0x2b520
movl -0x3c(%rbp), %eax
movl %eax, 0x27282(%rip)     # 0x2b524
movl -0x60(%rbp), %eax
movl %eax, 0x2727d(%rip)     # 0x2b528
movl -0x64(%rbp), %eax
movl %eax, 0x27278(%rip)     # 0x2b52c
movl -0x5c(%rbp), %eax
movl %eax, 0x27273(%rip)     # 0x2b530
leaq 0x27254(%rip), %rax     # 0x2b518
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
popq %rbp
retq
nop