// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DASCRUBBER/DAScover.c
// Function: HISTOGRAM_COVER
static void HISTOGRAM_COVER(int aread, Overlap *ovls, int novl)
{ static int    nmax = 0;
  static int   *local;
  static int   *cover;
  static int   *maskd;

  int  DBreads;
  int  alen, atick;
  int  bread, cssr;
  int  alow, ahigh;
  int  t2, t1;
  int  i, j, a, e;

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

  if (alen < HGAP_MIN)
    return;

#if defined(COVER_DEBUG)
  printf("AREAD %d",aread);
  if (novl == 0)
    printf(" EMPTY");
  printf("\n");
#endif

  //  COVERAGE
  //       Allocate or expand data structures for cover calculation as needed

  if (nmax == 0)
    { nmax = (DB->maxlen + (TRACE_SPACING-1))/TRACE_SPACING;

      local = (int *) Malloc(nmax*sizeof(int),"Allocating bread cover");
      cover = (int *) Malloc(nmax*sizeof(int),"Allocating aread cover");
      maskd = (int *) Malloc(nmax*sizeof(int),"Allocating aread cover");

      if (local == NULL || cover == NULL || maskd == NULL)
        exit (1);

      for (i = nmax-1; i >= 0; i--)
        local[i] = cover[i] = maskd[i] = 0;
    }

  //  For every segment, fill histogram of match diffs for every one of the
  //   atick intervals, building separate histograms, hist & cist, for forward
  //   and reverse B-hits

  t2 = TRACE_SPACING/2;
  t1 = t2-1;

  DBreads = DB->nreads;
  for (j = aread+1; j < DBreads; j++)
    if ((Reads[j].flags & DB_CCS) == 0)
      break;
  ahigh = j;
  for (j = aread; j >= 0; j--)
    if ((Reads[j].flags & DB_CCS) == 0)
      break;
  alow = j;

  for (i = 0; i < novl; i = j)
    { bread = ovls[i].bread;

      if (alow <= bread && bread < ahigh)
        { j += 1;
          continue;
        }

      for (j = bread+1; j < DBreads; j++)
        if ((Reads[j].flags & DB_CCS) == 0)
          break;
      cssr = j;

      for (j = i; j < novl; j++)
        if (ovls[j].bread < cssr)
          { e = (ovls[j].path.aepos + t2) / TRACE_SPACING;
            for (a = (ovls[j].path.abpos + t1) / TRACE_SPACING; a < e; a++)
              local[a] = 1;
          }
        else
          break;

      for (j = i; j < novl; j++)
        if (ovls[j].bread < cssr)
          { e = (ovls[j].path.aepos + t2) / TRACE_SPACING;
            for (a = (ovls[j].path.abpos + t1) / TRACE_SPACING; a < e; a++)
              if (local[a] > 0)
                { local[a] = 0;
                  cover[a] += 1;
                }
          }
        else
          break;
    }

  for (i = 0; i < NUM_MASK; i++)
    { Mask *m = (Mask *) (MASKS+i);
      int   k, u, e;

#ifdef COVER_DEBUG
      printf("  %s:",m->name);
#endif
      for (k = m->idx[aread]; k < m->idx[aread+1]; k += 2)
        { e = m->data[k+1];
#ifdef COVER_DEBUG
          printf(" [%d..%d]",m->data[k],e);
#endif
          e = (e + (TRACE_SPACING-1))/TRACE_SPACING;
          for (u = m->data[k]/TRACE_SPACING; u < e; u++) 
            maskd[u] = 1;
        }
#ifdef COVER_DEBUG
      printf("\n");
#endif
    }

#ifdef COVER_DEBUG
  printf("Mask: ");
  for (a = 0; a < atick; a++)
    printf("%d",maskd[a]);
  printf("\n");

  printf("Cover: ");
  for (a = 0; a < atick; a++)
    printf(" %d",cover[a]);
  printf("\n");
#endif

  for (a = 0; a < atick; a++)
    { if (maskd[a] == 0)
        { e = cover[a];
          if (e >= MAX_COVER)
            Cov_Hist[MAX_COVER] += 1;
          else
            Cov_Hist[e] += 1;
        }
      cover[a] = 0;
    }

  for (i = 0; i < NUM_MASK; i++)
    { Mask *m = (Mask *) (MASKS+i);
      int   k, u, e;

      for (k = m->idx[aread]; k < m->idx[aread+1]; k += 2)
        { e = m->data[k+1];
          e = (e + (TRACE_SPACING-1))/TRACE_SPACING;
          for (u = m->data[k]/TRACE_SPACING; u < e; u++) 
            maskd[u] = 0;
        }
    }

  if (VERBOSE)
    { nreads += 1;
      totlen += alen;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq 0x275cc(%rip), %rax     # 0x2b178
movq 0x60(%rax), %rax
movslq -0x4(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movl 0x297be(%rip), %ecx     # 0x2d388
subl $0x1, %ecx
addl %ecx, %eax
cltd
idivl 0x297b2(%rip)           # 0x2d388
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x2781e(%rip), %eax     # 0x2b400
jge 0x3be9
jmp 0x4227
cmpl $0x0, 0x29834(%rip)     # 0x2d424
jne 0x3cef
movq 0x2757b(%rip), %rax     # 0x2b178
movl 0x20(%rax), %eax
movl 0x29782(%rip), %ecx     # 0x2d388
subl $0x1, %ecx
addl %ecx, %eax
cltd
idivl 0x29776(%rip)           # 0x2d388
movl %eax, 0x2980c(%rip)     # 0x2d424
movslq 0x29805(%rip), %rdi     # 0x2d424
shlq $0x2, %rdi
leaq 0x228d3(%rip), %rsi     # 0x264fd
callq 0x1a850
movq %rax, 0x297f2(%rip)     # 0x2d428
movslq 0x297e7(%rip), %rdi     # 0x2d424
shlq $0x2, %rdi
leaq 0x228cc(%rip), %rsi     # 0x26514
callq 0x1a850
movq %rax, 0x297dc(%rip)     # 0x2d430
movslq 0x297c9(%rip), %rdi     # 0x2d424
shlq $0x2, %rdi
leaq 0x228ae(%rip), %rsi     # 0x26514
callq 0x1a850
movq %rax, 0x297c6(%rip)     # 0x2d438
cmpq $0x0, 0x297ae(%rip)     # 0x2d428
je 0x3c90
cmpq $0x0, 0x297ac(%rip)     # 0x2d430
je 0x3c90
cmpq $0x0, 0x297aa(%rip)     # 0x2d438
jne 0x3c9a
movl $0x1, %edi
callq 0x2280
movl 0x29784(%rip), %eax     # 0x2d424
subl $0x1, %eax
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jl 0x3ced
movq 0x29785(%rip), %rax     # 0x2d438
movslq -0x3c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x2976b(%rip), %rax     # 0x2d430
movslq -0x3c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x29751(%rip), %rax     # 0x2d428
movslq -0x3c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3ca6
jmp 0x3cef
movl 0x29693(%rip), %eax     # 0x2d388
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x38(%rbp)
movq 0x27468(%rip), %rax     # 0x2b178
movl 0x30(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3d55
movq 0x276ea(%rip), %rax     # 0x2b418
movslq -0x40(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x3d48
jmp 0x3d55
jmp 0x3d4a
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3d1f
movl -0x40(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x40(%rbp)
cmpl $0x0, -0x40(%rbp)
jl 0x3d95
movq 0x276aa(%rip), %rax     # 0x2b418
movslq -0x40(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x3d88
jmp 0x3d95
jmp 0x3d8a
movl -0x40(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3d61
movl -0x40(%rbp), %eax
movl %eax, -0x2c(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3f9e
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %eax
movl %eax, -0x24(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jg 0x3de1
movl -0x24(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x3de1
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3f93
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3e20
movq 0x2761f(%rip), %rax     # 0x2b418
movslq -0x40(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movl 0x20(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
jne 0x3e13
jmp 0x3e20
jmp 0x3e15
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3dea
movl -0x40(%rbp), %eax
movl %eax, -0x28(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3ec6
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %eax
cmpl -0x28(%rbp), %eax
jge 0x3eb4
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addl -0x34(%rbp), %eax
cltd
idivl 0x2951d(%rip)           # 0x2d388
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addl -0x38(%rbp), %eax
cltd
idivl 0x294fe(%rip)           # 0x2d388
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x3eb2
movq 0x2958c(%rip), %rax     # 0x2d428
movslq -0x44(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3e8d
jmp 0x3eb6
jmp 0x3ec6
jmp 0x3eb8
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3e2c
movl -0x3c(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x3f91
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x28(%rax), %eax
cmpl -0x28(%rbp), %eax
jge 0x3f7f
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
addl -0x34(%rbp), %eax
cltd
idivl 0x29479(%rip)           # 0x2d388
movl %eax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addl -0x38(%rbp), %eax
cltd
idivl 0x2945a(%rip)           # 0x2d388
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x3f7d
movq 0x294e8(%rip), %rax     # 0x2d428
movslq -0x44(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jle 0x3f70
movq 0x294d7(%rip), %rax     # 0x2d428
movslq -0x44(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movq 0x294cd(%rip), %rax     # 0x2d430
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x3f72
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3f31
jmp 0x3f81
jmp 0x3f91
jmp 0x3f83
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3ecc
jmp 0x3f93
movl -0x40(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x3da2
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x27456(%rip), %eax     # 0x2b404
jge 0x4085
movq 0x2744d(%rip), %rax     # 0x2b408
movslq -0x3c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movslq -0x54(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x4(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0x4075
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x54(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl 0x29370(%rip), %ecx     # 0x2d388
subl $0x1, %ecx
addl %ecx, %eax
cltd
idivl 0x29364(%rip)           # 0x2d388
movl %eax, -0x5c(%rbp)
movq -0x50(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x54(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cltd
idivl 0x2934b(%rip)           # 0x2d388
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jge 0x4065
movq 0x293e9(%rip), %rax     # 0x2d438
movslq -0x58(%rbp), %rcx
movl $0x1, (%rax,%rcx,4)
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x4040
jmp 0x4067
movl -0x54(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x54(%rbp)
jmp 0x3fdd
jmp 0x4077
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3fa5
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x4113
movq 0x2939d(%rip), %rax     # 0x2d438
movslq -0x44(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x40f3
movq 0x29384(%rip), %rax     # 0x2d430
movslq -0x44(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x48(%rbp)
cmpl $0x3e8, -0x48(%rbp)     # imm = 0x3E8
jl 0x40d3
movq 0x2929a(%rip), %rax     # 0x2d360
addq $0x1, %rax
movq %rax, 0x2928f(%rip)     # 0x2d360
jmp 0x40f1
movslq -0x48(%rbp), %rcx
leaq 0x27342(%rip), %rax     # 0x2b420
movq (%rax,%rcx,8), %rdx
addq $0x1, %rdx
leaq 0x27333(%rip), %rax     # 0x2b420
movq %rdx, (%rax,%rcx,8)
jmp 0x40f3
movq 0x29336(%rip), %rax     # 0x2d430
movslq -0x44(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x408c
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl 0x272e1(%rip), %eax     # 0x2b404
jge 0x41fa
movq 0x272d8(%rip), %rax     # 0x2b408
movslq -0x3c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x6c(%rbp)
movslq -0x6c(%rbp), %rax
movq -0x68(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x4(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
cmpq (%rcx,%rdx,8), %rax
jge 0x41ea
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x6c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movl 0x291fb(%rip), %ecx     # 0x2d388
subl $0x1, %ecx
addl %ecx, %eax
cltd
idivl 0x291ef(%rip)           # 0x2d388
movl %eax, -0x74(%rbp)
movq -0x68(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x6c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cltd
idivl 0x291d6(%rip)           # 0x2d388
movl %eax, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x74(%rbp), %eax
jge 0x41da
movq 0x29274(%rip), %rax     # 0x2d438
movslq -0x70(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x41b5
jmp 0x41dc
movl -0x6c(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x6c(%rbp)
jmp 0x4152
jmp 0x41ec
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x411a
cmpl $0x0, 0x2720f(%rip)     # 0x2b410
je 0x4227
movq 0x29186(%rip), %rax     # 0x2d390
addq $0x1, %rax
movq %rax, 0x2917b(%rip)     # 0x2d390
movslq -0x1c(%rbp), %rax
addq 0x29178(%rip), %rax     # 0x2d398
movq %rax, 0x29171(%rip)     # 0x2d398
addq $0x80, %rsp
popq %rbp
retq