// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DASCRUBBER/DAStrim.c
// Function: HQ_BLOCKS
static Interval *HQ_BLOCKS(int aread, int *p_nblk)
{ int              nblk;
  static int      *alive = NULL;
  static Interval *block = NULL;

  int    alen, atick;
  uint8 *qvec;

  alen  = DB->reads[aread].rlen;
  atick = (alen + (TRACE_SPACING-1))/TRACE_SPACING;

  if (alive == NULL)
    { int max = DB->maxlen/TRACE_SPACING+2;
      alive = (int *) Malloc(max*sizeof(int),"Allocating alive vector");
      block = (Interval *) Malloc(max*sizeof(Interval),"Allocating block vector");
      if (alive == NULL || block == NULL)
        exit (1);
    }

  qvec = QV + QV_IDX[aread];
  nblk = 0;

  //  Find all blocks < BAD_QV with either len >= MIN_BLOCK or all <= GOOD_QV in block[0..nblk)
  //    Mark those satisfying 1. or 2. as "alive" (.alv)

  { int lmost = 0, rmost = 0, thr;
    int i, in;

    thr = (MIN_BLOCK-1)/TRACE_SPACING;
    in  = 0;
    for (i = 0; i <= atick; i++)
      { int q, alv;

        if (i < atick)
          q = qvec[i];
        else
          q = BAD_QV;
        if (in)
          { if (q >= BAD_QV)
              { alv = (lmost-rmost >= thr);
                if (alv)
                  { block[nblk].beg = rmost; 
                    block[nblk].end = lmost + 1;
                    alive[nblk] = alv;
                    nblk += 1;
                  }
                else
                  { int j, k;

                    for (j = rmost; j <= lmost; j = k)
                      { for (k = j+1; k <= lmost; k++)
                          if (qvec[k] > GOOD_QV)
                            break;
                        block[nblk].beg = j; 
                        block[nblk].end = k;
                        alive[nblk] = (k-j >= thr);
                        nblk += 1;
                        for ( ; k <= lmost; k++)
                          if (qvec[k] <= GOOD_QV)
                            break;
                      }
                  }
                in = 0;
              }
            else if (q <= GOOD_QV)
              lmost = i;
          }
        else
          { if (q <= GOOD_QV)
              { rmost = lmost = i;
                in = 1;
              }
          }
      }
  }

  //  Mark as alive all short, all-good blocks that satisfy 3.

  { int i, j;

    for (i = 0; i < nblk; i++)
      if (alive[i])
        { for (j = i-1; j >= 0 && ! alive[j]; j--)
            if (block[j+1].beg - block[j].end == 1)
              alive[j] = 1;  
            else
              break;
          for (j = i+1; j < nblk && ! alive[j]; j++)
            if (block[j].beg - block[j-1].end == 1)
              alive[j] = 1;  
            else
              break;
        }
  }

  //  Remove all blocks that are not alive

  { int i, j;

    j = 0;
    for (i = 0; i < nblk; i++)
      if (alive[i])
        { block[j].beg = block[i].beg * TRACE_SPACING;
          block[j].end = block[i].end * TRACE_SPACING;
          j += 1;
        }
    nblk = j;
    if (nblk > 0 && block[nblk-1].end > alen)
      block[nblk-1].end = alen;
  }

#ifdef DEBUG_HQ_BLOCKS
  { int i;

    printf("         %3d:",nblk);
    for (i = 0; i < nblk; i++)
      printf(" [%5d,%5d]",block[i].beg,block[i].end);
    printf("\n");
  }
#endif

  *p_nblk = nblk;
  return (block);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq 0x2b572(%rip), %rax     # 0x31188
movq 0x60(%rax), %rax
movslq -0x4(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl 0x2b8a4(%rip), %ecx     # 0x314d8
subl $0x1, %ecx
addl %ecx, %eax
cltd
idivl 0x2b898(%rip)           # 0x314d8
movl %eax, -0x1c(%rbp)
cmpq $0x0, 0x2b9a5(%rip)     # 0x315f0
jne 0x5cba
movq 0x2b534(%rip), %rax     # 0x31188
movl 0x20(%rax), %eax
cltd
idivl 0x2b87a(%rip)           # 0x314d8
addl $0x2, %eax
movl %eax, -0x2c(%rbp)
movslq -0x2c(%rbp), %rdi
shlq $0x2, %rdi
leaq 0x26adb(%rip), %rsi     # 0x2c74e
callq 0x1ffd0
movq %rax, 0x2b971(%rip)     # 0x315f0
movslq -0x2c(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x26ad8(%rip), %rsi     # 0x2c766
callq 0x1ffd0
movq %rax, 0x2b95e(%rip)     # 0x315f8
cmpq $0x0, 0x2b94e(%rip)     # 0x315f0
je 0x5cae
cmpq $0x0, 0x2b94c(%rip)     # 0x315f8
jne 0x5cb8
movl $0x1, %edi
callq 0x22a0
jmp 0x5cba
movq 0x2b74f(%rip), %rax     # 0x31410
movq 0x2b740(%rip), %rcx     # 0x31408
movslq -0x4(%rbp), %rdx
addq (%rcx,%rdx,8), %rax
movq %rax, -0x28(%rbp)
movl $0x0, -0x14(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x1f3, %eax            # imm = 0x1F3
cltd
idivl 0x2b7e3(%rip)           # 0x314d8
movl %eax, -0x38(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jg 0x5ec2
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x5d2b
movq -0x28(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movzbl (%rax,%rcx), %eax
movl %eax, -0x44(%rbp)
jmp 0x5d34
movl 0x2b6c7(%rip), %eax     # 0x313f8
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x40(%rbp)
je 0x5e95
movl -0x44(%rbp), %eax
cmpl 0x2b6b1(%rip), %eax     # 0x313f8
jl 0x5e80
movl -0x30(%rbp), %eax
subl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
setge %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x48(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x5dac
movl -0x34(%rbp), %edx
movq 0x2b887(%rip), %rax     # 0x315f8
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movl -0x30(%rbp), %edx
addl $0x1, %edx
movq 0x2b873(%rip), %rax     # 0x315f8
movslq -0x14(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x48(%rbp), %edx
movq 0x2b859(%rip), %rax     # 0x315f0
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x5e77
movl -0x34(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x5e75
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x5df2
movq -0x28(%rbp), %rax
movslq -0x50(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl 0x2b61b(%rip), %eax     # 0x313fc
jle 0x5de5
jmp 0x5df2
jmp 0x5de7
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x5dc7
movl -0x4c(%rbp), %edx
movq 0x2b7fc(%rip), %rax     # 0x315f8
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movl -0x50(%rbp), %edx
movq 0x2b7eb(%rip), %rax     # 0x315f8
movslq -0x14(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x50(%rbp), %eax
subl -0x4c(%rbp), %eax
cmpl -0x38(%rbp), %eax
setge %al
andb $0x1, %al
movzbl %al, %edx
movq 0x2b7c3(%rip), %rax     # 0x315f0
movslq -0x14(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x50(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0x5e68
movq -0x28(%rbp), %rax
movslq -0x50(%rbp), %rcx
movzbl (%rax,%rcx), %eax
cmpl 0x2b5a5(%rip), %eax     # 0x313fc
jg 0x5e5b
jmp 0x5e68
jmp 0x5e5d
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
jmp 0x5e3d
jmp 0x5e6a
movl -0x50(%rbp), %eax
movl %eax, -0x4c(%rbp)
jmp 0x5db2
jmp 0x5e77
movl $0x0, -0x40(%rbp)
jmp 0x5e93
movl -0x44(%rbp), %eax
cmpl 0x2b573(%rip), %eax     # 0x313fc
jg 0x5e91
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x5e93
jmp 0x5eb2
movl -0x44(%rbp), %eax
cmpl 0x2b55e(%rip), %eax     # 0x313fc
jg 0x5eb0
movl -0x3c(%rbp), %eax
movl %eax, -0x30(%rbp)
movl %eax, -0x34(%rbp)
movl $0x1, -0x40(%rbp)
jmp 0x5eb2
jmp 0x5eb4
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5d06
movl $0x0, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x5ffa
movq 0x2b714(%rip), %rax     # 0x315f0
movslq -0x54(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x5fea
movl -0x54(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x58(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x58(%rbp)
movb %al, -0x61(%rbp)
jl 0x5f15
movq 0x2b6eb(%rip), %rax     # 0x315f0
movslq -0x58(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
setne %al
xorb $-0x1, %al
movb %al, -0x61(%rbp)
movb -0x61(%rbp), %al
testb $0x1, %al
jne 0x5f1e
jmp 0x5f68
movq 0x2b6d3(%rip), %rax     # 0x315f8
movl -0x58(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,8), %eax
movq 0x2b6c0(%rip), %rcx     # 0x315f8
movslq -0x58(%rbp), %rdx
subl 0x4(%rcx,%rdx,8), %eax
cmpl $0x1, %eax
jne 0x5f59
movq 0x2b6a4(%rip), %rax     # 0x315f0
movslq -0x58(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x5f5b
jmp 0x5f68
jmp 0x5f5d
movl -0x58(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5ef3
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %ecx
xorl %eax, %eax
cmpl -0x14(%rbp), %ecx
movb %al, -0x62(%rbp)
jge 0x5f95
movq 0x2b66b(%rip), %rax     # 0x315f0
movslq -0x58(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
setne %al
xorb $-0x1, %al
movb %al, -0x62(%rbp)
movb -0x62(%rbp), %al
testb $0x1, %al
jne 0x5f9e
jmp 0x5fe8
movq 0x2b653(%rip), %rax     # 0x315f8
movslq -0x58(%rbp), %rcx
movl (%rax,%rcx,8), %eax
movq 0x2b645(%rip), %rcx     # 0x315f8
movl -0x58(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
subl 0x4(%rcx,%rdx,8), %eax
cmpl $0x1, %eax
jne 0x5fd9
movq 0x2b624(%rip), %rax     # 0x315f0
movslq -0x58(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
jmp 0x5fdb
jmp 0x5fe8
jmp 0x5fdd
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5f71
jmp 0x5fea
jmp 0x5fec
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x5ec9
movl $0x0, -0x60(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x607f
movq 0x2b5d9(%rip), %rax     # 0x315f0
movslq -0x5c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x6072
movq 0x2b5d0(%rip), %rax     # 0x315f8
movslq -0x5c(%rbp), %rcx
movl (%rax,%rcx,8), %edx
imull 0x2b4a2(%rip), %edx     # 0x314d8
movq 0x2b5bb(%rip), %rax     # 0x315f8
movslq -0x60(%rbp), %rcx
movl %edx, (%rax,%rcx,8)
movq 0x2b5ad(%rip), %rax     # 0x315f8
movslq -0x5c(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %edx
imull 0x2b47e(%rip), %edx     # 0x314d8
movq 0x2b597(%rip), %rax     # 0x315f8
movslq -0x60(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x6074
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x6008
movl -0x60(%rbp), %eax
movl %eax, -0x14(%rbp)
cmpl $0x0, -0x14(%rbp)
jle 0x60bb
movq 0x2b566(%rip), %rax     # 0x315f8
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl 0x4(%rax,%rcx,8), %eax
cmpl -0x18(%rbp), %eax
jle 0x60bb
movl -0x18(%rbp), %edx
movq 0x2b54a(%rip), %rax     # 0x315f8
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x14(%rbp), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq 0x2b52d(%rip), %rax     # 0x315f8
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)