// File: /workspace/github_c_makefile_star2_O0/thegenemyers[P]DAMASKER/TANmask.c
// Function: TANDEM
static void TANDEM(int aread, Overlap *ovls, int novl)
{ static int  nmax = -1;
  static int *add = NULL;
  static int *del;

  int evnum;

  (void) aread;

  if (VERBOSE)
    { nreads += 1;
      totlen += DB->reads[aread].rlen;
    }

  if (novl == 0)
    { fwrite(&TN_INDEX,sizeof(int64),1,TN_AFILE);
      return;
    }

#ifdef DEBUG
  printf("\nAREAD %d:\n",aread);
#endif

  if (novl > nmax)
    { nmax = 1.2*novl + 500;
      add  = (int *) Realloc(add,4*sizeof(int)*nmax,"Allocating sort vector");
      if (add == NULL)
        exit (1);
      del = add + nmax;
    }

  //  For each overlapping LA record mask interval as an add and del event
  //    that are then sorted

  { int   i;
    Path *ipath;
 
    evnum = 0;
    for (i = 0; i < novl; i++)
      { ipath = &(ovls[i].path);
        if (ipath->abpos - ipath->bepos <= SEP_FUZZ)
          { if (ipath->aepos - ipath->bbpos > MIN_LEN)
              { add[evnum] = ipath->bbpos;
                del[evnum] = ipath->aepos;
                evnum += 1;
              }
          }
      }
    qsort(add,evnum,sizeof(int),ISORT);
    qsort(del,evnum,sizeof(int),ISORT);
  }

  //  Output the union of the mask intervals to the .tan track

  { int i, j, x, a;

    x = a = 0;
    i = j = 0;
    while (j < evnum)
      if (i < evnum && add[i] <= del[j])
        { if (x == 0)
            { fwrite(add+i,sizeof(int),1,TN_DFILE);
              TN_INDEX += sizeof(int);
#ifdef DEBUG
              printf("  + %5d: %3d\n",add[i],x);
#endif
              a = add[i];
            }
          x += 1;
          i += 1;
        }
      else
        { x -= 1;
          if (x == 0)
            { fwrite(del+j,sizeof(int),1,TN_DFILE);
              TN_INDEX += sizeof(int);
#ifdef DEBUG
              printf("  - %5d: %3d\n",del[j],x);
#endif
              if (VERBOSE)
                { masked += del[j]-a;
                  nmasks += 1;
                }
            }
          j += 1;
        }
#ifdef DEBUG
    printf("   %lld\n",TN_INDEX);
#endif
    fwrite(&TN_INDEX,sizeof(int64),1,TN_AFILE);
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
cmpl $0x0, 0x27cf3(%rip)     # 0x2b3fc
je 0x3745
movq 0x27cee(%rip), %rax     # 0x2b400
addq $0x1, %rax
movq %rax, 0x27ce3(%rip)     # 0x2b400
movq 0x27a64(%rip), %rax     # 0x2b188
movq 0x60(%rax), %rax
movslq -0x4(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movslq 0x4(%rax), %rax
addq 0x27cca(%rip), %rax     # 0x2b408
movq %rax, 0x27cc3(%rip)     # 0x2b408
cmpl $0x0, -0x14(%rbp)
jne 0x376d
movq 0x27cde(%rip), %rcx     # 0x2b430
leaq 0x27ce7(%rip), %rdi     # 0x2b440
movl $0x8, %esi
movl $0x1, %edx
callq 0x22b0
jmp 0x3a33
movl -0x14(%rbp), %eax
cmpl 0x27a22(%rip), %eax     # 0x2b198
jle 0x37f4
cvtsi2sdl -0x14(%rbp), %xmm0
movsd 0x2288b(%rip), %xmm1    # 0x26010
mulsd %xmm1, %xmm0
movsd 0x2288f(%rip), %xmm1    # 0x26020
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, 0x279f9(%rip)     # 0x2b198
movq 0x27d2a(%rip), %rdi     # 0x2b4d0
movslq 0x279eb(%rip), %rsi     # 0x2b198
shlq $0x4, %rsi
leaq 0x22bb0(%rip), %rdx     # 0x26368
callq 0x1a110
movq %rax, 0x27d0c(%rip)     # 0x2b4d0
cmpq $0x0, 0x27d04(%rip)     # 0x2b4d0
jne 0x37d8
movl $0x1, %edi
callq 0x22a0
movq 0x27cf1(%rip), %rax     # 0x2b4d0
movslq 0x279b2(%rip), %rcx     # 0x2b198
shlq $0x2, %rcx
addq %rcx, %rax
movq %rax, 0x27ce4(%rip)     # 0x2b4d8
movl $0x0, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x388f
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x28(%rbp), %rcx
subl 0x1c(%rcx), %eax
cmpl $0x14, %eax
jg 0x387f
movq -0x28(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x28(%rbp), %rcx
subl 0x14(%rcx), %eax
cmpl 0x27bb0(%rip), %eax     # 0x2b3f8
jle 0x387d
movq -0x28(%rbp), %rax
movl 0x14(%rax), %edx
movq 0x27c78(%rip), %rax     # 0x2b4d0
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movl 0x18(%rax), %edx
movq 0x27c6b(%rip), %rax     # 0x2b4d8
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x387f
jmp 0x3881
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3802
movq 0x27c3a(%rip), %rdi     # 0x2b4d0
movslq -0x18(%rbp), %rsi
movl $0x4, %edx
leaq 0x19a(%rip), %rcx       # 0x3a40
callq 0x20b0
movq 0x27c26(%rip), %rdi     # 0x2b4d8
movslq -0x18(%rbp), %rsi
movl $0x4, %edx
leaq 0x17e(%rip), %rcx       # 0x3a40
callq 0x20b0
movl $0x0, -0x38(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3a16
movl -0x2c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x3981
movq 0x27bce(%rip), %rax     # 0x2b4d0
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq 0x27bc8(%rip), %rcx     # 0x2b4d8
movslq -0x30(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jg 0x3981
cmpl $0x0, -0x34(%rbp)
jne 0x396a
movq 0x27baa(%rip), %rdi     # 0x2b4d0
movslq -0x2c(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x27b00(%rip), %rcx     # 0x2b438
movl $0x4, %esi
movl $0x1, %edx
callq 0x22b0
movq 0x27af2(%rip), %rax     # 0x2b440
addq $0x4, %rax
movq %rax, 0x27ae7(%rip)     # 0x2b440
movq 0x27b70(%rip), %rax     # 0x2b4d0
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x38(%rbp)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x3a11
movl -0x34(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x3a08
movq 0x27b41(%rip), %rdi     # 0x2b4d8
movslq -0x30(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rdi
movq 0x27a8f(%rip), %rcx     # 0x2b438
movl $0x4, %esi
movl $0x1, %edx
callq 0x22b0
movq 0x27a81(%rip), %rax     # 0x2b440
addq $0x4, %rax
movq %rax, 0x27a76(%rip)     # 0x2b440
cmpl $0x0, 0x27a2b(%rip)     # 0x2b3fc
je 0x3a06
movq 0x27afe(%rip), %rax     # 0x2b4d8
movslq -0x30(%rbp), %rcx
movl (%rax,%rcx,4), %eax
subl -0x38(%rbp), %eax
cltq
addq 0x27a23(%rip), %rax     # 0x2b410
movq %rax, 0x27a1c(%rip)     # 0x2b410
movq 0x27a1d(%rip), %rax     # 0x2b418
addq $0x1, %rax
movq %rax, 0x27a12(%rip)     # 0x2b418
jmp 0x3a08
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x38e3
movq 0x27a13(%rip), %rcx     # 0x2b430
leaq 0x27a1c(%rip), %rdi     # 0x2b440
movl $0x8, %esi
movl $0x1, %edx
callq 0x22b0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)