// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DAMASKER/REPmask.c
// Function: blocks
static int *blocks(Overlap *ovls, int novl, int *ptrim)
{ static int    nmax = 0;
  static Event *ev = NULL;
  static int   *trim = NULL;
  static int   *flim;

  int ecnt, ntrim;

  if (novl > nmax)
    { nmax = novl*1.2 + 1000; 
      ev    = (Event *) Realloc(ev,sizeof(Event)*2*nmax,"Reallocating event vector");
      trim  = (int *) Realloc(trim,sizeof(int)*4*nmax,"Reallocating trim vector");
      flim  = trim + 2*nmax;
    }
 
  //  Set up and sort event queue

  { int i, ab, ae;

    ecnt = 0;
    for (i = 0; i < novl; i++)
      { ab = ovls[i].path.abpos+PEEL_BACK;
        ae = ovls[i].path.aepos-PEEL_BACK;

        if (ae < ab) 
          ab = ae = (ovls[i].path.abpos + ovls[i].path.aepos)/2;

        ev[ecnt].add = 1;
        ev[ecnt].pos = ab;
        ecnt += 1;
        ev[ecnt].add = 0;
        ev[ecnt].pos = ae;
        ecnt += 1;
      }

    qsort(ev,ecnt,sizeof(Event),EVENT_SORT);
  }

  //  Compute in - out intervals (over the contracted alignment intervals) with respect to
  //    coverage depth threshold MIN_COVER and also the max (in interavls) or min (out intervals)
  //    coverage.

  { int i;
    int cov, min, max;

    ntrim = 0;
    cov   = 0;
    min   = 0;
    max   = 0;
    for (i = 0; i < ecnt; i++)
      if (ev[i].add)
        { cov += 1;
          if (cov > max)
            max = cov;
          if (cov == MIN_COVER) 
            { trim[ntrim]   = ev[i].pos-PEEL_BACK;
              flim[ntrim++] = min;
              max = MIN_COVER;
#ifdef DEBUG_BLOCKS
              printf("    In %4d\n",ev[i].pos-PEEL_BACK);
#endif
            }
#ifdef DEBUG_BLOCKS
          printf("  Add %4d (%3d)\n",ev[i].pos,cov);
#endif
        }
      else
        { if (cov == MIN_COVER)
            { trim[ntrim]   = ev[i].pos+PEEL_BACK;
              flim[ntrim++] = max;
              min = MIN_COVER;
#ifdef DEBUG_BLOCKS
              printf("    Out %4d\n",ev[i].pos+PEEL_BACK);
#endif
            }
          cov -= 1;
          if (cov < min)
            min = cov;
#ifdef DEBUG_BLOCKS
          printf("  Del %4d (%3d)\n",ev[i].pos,cov);
#endif
        }
  }

  //  Merge intervals that overlap by more than 20bp and have a small "hill" to either
  //    the left or right.

  { int i, j;

    j = 2;
    for (i = 2; i < ntrim; i += 2)
      { int deep, over;

        deep = flim[i-1] - flim[i];
        if (deep > flim[i+1] - flim[i])
          deep = flim[i+1] - flim[i];
        over = trim[i-1] - trim[i];
#ifdef DEBUG_BLOCKS
        printf("  Trim [%5d,%5d] [%3d,%3d]",trim[i],trim[i+1],flim[i],flim[i+1]);
        printf("  DEEP %4d OVER %4d",deep,over);
#endif
        if (deep <= TINY_HILL || (deep < MIN_HILL && over > MAX_OVL))
          { trim[j-1] = trim[i+1];
            if (flim[i+1] > flim[j-1])
              flim[j-1] = flim[i+1];
#ifdef DEBUG_BLOCKS
            printf(" FOLD");
#endif
          }
        else
          { trim[j]   = trim[i];
            trim[j+1] = trim[i+1];
            flim[j]   = flim[i];
            flim[j+1] = flim[i+1];
            j += 2;
          }
#ifdef DEBUG_BLOCKS
        printf("\n");
#endif
      }
    if (ntrim > 0)
      ntrim = j;
  }

  *ptrim = ntrim;
  return (trim);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl -0xc(%rbp), %eax
cmpl 0x27720(%rip), %eax     # 0x2b4dc
jle 0x3e53
cvtsi2sdl -0xc(%rbp), %xmm0
movsd 0x22241(%rip), %xmm1    # 0x26010
mulsd %xmm1, %xmm0
movsd 0x22255(%rip), %xmm1    # 0x26030
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x276f3(%rip)     # 0x2b4dc
movq 0x276f0(%rip), %rdi     # 0x2b4e0
movslq 0x276e5(%rip), %rsi     # 0x2b4dc
shlq $0x4, %rsi
leaq 0x225aa(%rip), %rdx     # 0x263ac
callq 0x1a980
movq %rax, 0x276d2(%rip)     # 0x2b4e0
movq 0x276d3(%rip), %rdi     # 0x2b4e8
movslq 0x276c0(%rip), %rsi     # 0x2b4dc
shlq $0x4, %rsi
leaq 0x2259f(%rip), %rdx     # 0x263c6
callq 0x1a980
movq %rax, 0x276b5(%rip)     # 0x2b4e8
movq 0x276ae(%rip), %rax     # 0x2b4e8
movl 0x2769c(%rip), %ecx     # 0x2b4dc
shll %ecx
movslq %ecx, %rcx
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x2769d(%rip)     # 0x2b4f0
movl $0x0, -0x1c(%rbp)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x3f43
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
addl $0x12c, %eax            # imm = 0x12C
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
subl $0x12c, %eax            # imm = 0x12C
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x28(%rbp), %eax
jge 0x3edb
movq -0x8(%rbp), %rax
movslq -0x24(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x10(%rax), %eax
movq -0x8(%rbp), %rcx
movslq -0x24(%rbp), %rdx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
addl 0x18(%rcx), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movl %eax, -0x2c(%rbp)
movl %eax, -0x28(%rbp)
movq 0x275fe(%rip), %rax     # 0x2b4e0
movslq -0x1c(%rbp), %rcx
movl $0x1, (%rax,%rcx,8)
movl -0x28(%rbp), %edx
movq 0x275e9(%rip), %rax     # 0x2b4e0
movslq -0x1c(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movq 0x275d1(%rip), %rax     # 0x2b4e0
movslq -0x1c(%rbp), %rcx
movl $0x0, (%rax,%rcx,8)
movl -0x2c(%rbp), %edx
movq 0x275bc(%rip), %rax     # 0x2b4e0
movslq -0x1c(%rbp), %rcx
movl %edx, 0x4(%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3e61
movq 0x27596(%rip), %rdi     # 0x2b4e0
movslq -0x1c(%rbp), %rsi
movl $0x8, %edx
leaq 0x326(%rip), %rcx       # 0x4280
callq 0x20b0
movl $0x0, -0x20(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x4085
movq 0x2754b(%rip), %rax     # 0x2b4e0
movslq -0x30(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,8)
je 0x400a
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x3fb6
movl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x34(%rbp), %eax
cmpl 0x27439(%rip), %eax     # 0x2b3f8
jne 0x4008
movq 0x27518(%rip), %rax     # 0x2b4e0
movslq -0x30(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %edx
subl $0x12c, %edx            # imm = 0x12C
movq 0x2750b(%rip), %rax     # 0x2b4e8
movslq -0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x38(%rbp), %edx
movq 0x27502(%rip), %rax     # 0x2b4f0
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x273f3(%rip), %eax     # 0x2b3f8
movl %eax, -0x3c(%rbp)
jmp 0x4075
movl -0x34(%rbp), %eax
cmpl 0x273e5(%rip), %eax     # 0x2b3f8
jne 0x405c
movq 0x274c4(%rip), %rax     # 0x2b4e0
movslq -0x30(%rbp), %rcx
movl 0x4(%rax,%rcx,8), %edx
addl $0x12c, %edx            # imm = 0x12C
movq 0x274b7(%rip), %rax     # 0x2b4e8
movslq -0x20(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x3c(%rbp), %edx
movq 0x274ae(%rip), %rax     # 0x2b4f0
movl -0x20(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x20(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl 0x2739f(%rip), %eax     # 0x2b3f8
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0x4073
movl -0x34(%rbp), %eax
movl %eax, -0x38(%rbp)
jmp 0x4075
jmp 0x4077
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x3f82
movl $0x2, -0x44(%rbp)
movl $0x2, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x425b
movq 0x2744a(%rip), %rax     # 0x2b4f0
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x27437(%rip), %rcx     # 0x2b4f0
movslq -0x40(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq 0x27423(%rip), %rcx     # 0x2b4f0
movl -0x40(%rbp), %edx
addl $0x1, %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movq 0x27410(%rip), %rdx     # 0x2b4f0
movslq -0x40(%rbp), %rsi
subl (%rdx,%rsi,4), %ecx
cmpl %ecx, %eax
jle 0x410f
movq 0x273fe(%rip), %rax     # 0x2b4f0
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x273eb(%rip), %rcx     # 0x2b4f0
movslq -0x40(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, -0x48(%rbp)
movq 0x273d2(%rip), %rax     # 0x2b4e8
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x273bf(%rip), %rcx     # 0x2b4e8
movslq -0x40(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, -0x4c(%rbp)
cmpl $0x3, -0x48(%rbp)
jle 0x4145
cmpl $0xa, -0x48(%rbp)
jge 0x41be
cmpl $0x14, -0x4c(%rbp)
jle 0x41be
movq 0x2739c(%rip), %rax     # 0x2b4e8
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x27389(%rip), %rax     # 0x2b4e8
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq 0x2737e(%rip), %rax     # 0x2b4f0
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %eax
movq 0x2736b(%rip), %rcx     # 0x2b4f0
movl -0x44(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x41b9
movq 0x27356(%rip), %rax     # 0x2b4f0
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x27343(%rip), %rax     # 0x2b4f0
movl -0x44(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x424b
movq 0x27323(%rip), %rax     # 0x2b4e8
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x27315(%rip), %rax     # 0x2b4e8
movslq -0x44(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x27307(%rip), %rax     # 0x2b4e8
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x272f4(%rip), %rax     # 0x2b4e8
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq 0x272e9(%rip), %rax     # 0x2b4f0
movslq -0x40(%rbp), %rcx
movl (%rax,%rcx,4), %edx
movq 0x272db(%rip), %rax     # 0x2b4f0
movslq -0x44(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq 0x272cd(%rip), %rax     # 0x2b4f0
movl -0x40(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
movq 0x272ba(%rip), %rax     # 0x2b4f0
movl -0x44(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movl -0x44(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x44(%rbp)
jmp 0x424d
movl -0x40(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x40(%rbp)
jmp 0x4093
cmpl $0x0, -0x20(%rbp)
jle 0x4267
movl -0x44(%rbp), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, (%rax)
movq 0x27271(%rip), %rax     # 0x2b4e8
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax)