// File: /workspace/github_c_makefile_star2_O2/jsh58[P]Genrich/Genrich.c
// Function: callPeaks
int callPeaks(File out, File log, bool logOpt, bool gzOut,
    Chrom* chrom, int chromLen, int n, float minPQval,
    bool qvalOpt, float minAUC, int minLen, int maxGap,
    uint64_t* peakBP) {

  if (logOpt)
    printLogHeader(log, gzOut, n, qvalOpt, true);

  // loop through chroms
  int count = 0;      // count of peaks
  for (int i = 0; i < chromLen; i++) {
    Chrom* chr = chrom + i;
    if (chr->skip || (qvalOpt && chr->qval == NULL)
        || (! qvalOpt && chr->pval[n] == NULL) )
      continue;

    // create indexes into arrays for logging purposes
    //   (expt/ctrl pileup [if n == 0] and p-value arrays [if n > 0])
    uint32_t j = 0, k = 0;  // indexes into chr->expt, chr->ctrl
    uint32_t idx[n];        // indexes into each pval array
    for (int r = 0; r < n; r++)
      idx[r] = 0;

    // initialize peak variables
    float auc = 0.0f;                     // area under the curve (signif.)
    int64_t peakStart = -1, peakEnd = -1; // ends of potential peak
    float summitVal = -1.0f;              // summit p/q value
    uint32_t summitPos = 0;               // distance from peakStart to summit
    uint32_t summitLen = 0;               // length of summit interval
    float summitPval = -1.0f, summitQval = -1.0f; // summit p- and q-values

    // loop through intervals (defined by chr->pval[n])
    uint32_t start = 0;    // start of interval
    for (uint32_t m = 0; m < chr->pvalLen[n]; m++) {

      bool sig = false;
      float pqval = qvalOpt ? chr->qval->cov[m]
        : chr->pval[n]->cov[m];
      if (pqval > minPQval) {

        // interval reaches significance
        sig = true;
        updatePeak(&peakStart, &peakEnd, start,
          chr->pval[n]->end[m], &auc, pqval,
          minPQval, chr->pval[n]->cov[m],
          qvalOpt ? chr->qval->cov[m] : SKIP,
          &summitVal, &summitPval, &summitQval,
          &summitPos, &summitLen);

      } else {

        // interval does not reach significance --
        //   check if interval is to be skipped
        //   OR distance is beyond maxGap from peak
        if (pqval == SKIP
            || chr->pval[n]->end[m] - peakEnd > maxGap) {
          // check if previous peak is valid
          checkPeak(out, gzOut, chr->name, peakStart,
            peakEnd, &count, auc, summitPval, summitQval,
            summitPos, minAUC, minLen, peakBP);

          // reset peak variables
          resetVars(&peakStart, &summitVal, &summitLen, &auc);
        }
      }

      // print stats for interval
      if (logOpt)
        printLog(log, gzOut, chr, start, n, m, j, k,
          idx, qvalOpt, sig);

      // update chr->expt and chr->ctrl indexes
      if (! n) {
        if (chr->ctrl->end[k] < chr->expt->end[j])
          k++;
        else {
          if (chr->ctrl->end[k] == chr->expt->end[j])
            k++;
          j++;
        }
      }

      start = chr->pval[n]->end[m];
    }

    // determine if last peak is valid
    checkPeak(out, gzOut, chr->name, peakStart, peakEnd,
      &count, auc, summitPval, summitQval, summitPos,
      minAUC, minLen, peakBP);
  }

  return count;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movss %xmm1, -0x4c(%rbp)
movl %r9d, %r15d
movq %r8, %r13
movq %rsi, -0x88(%rbp)
movq %rdi, -0x78(%rbp)
movl 0x28(%rbp), %r14d
movl 0x10(%rbp), %r9d
movzbl %cl, %eax
movl %eax, -0x2c(%rbp)
movzbl 0x18(%rbp), %eax
movq %rax, -0x80(%rbp)
movl %edx, -0x70(%rbp)
testl %edx, %edx
movss %xmm0, -0x30(%rbp)
je 0x4348
pushq $0x1
popq %r8
movq -0x88(%rbp), %rdi
movl -0x2c(%rbp), %esi
movl %r9d, %edx
movq -0x80(%rbp), %rcx
callq 0x381d
movl 0x10(%rbp), %r9d
movss -0x30(%rbp), %xmm0
leaq -0x40(%rbp), %rax
andl $0x0, (%rax)
movslq %r9d, %rbx
movl %r9d, %eax
testl %r9d, %r9d
movl $0x0, %edx
cmovgl %r9d, %edx
movslq %r14d, %rcx
movq %rcx, -0xc8(%rbp)
xorl %ecx, %ecx
testl %r15d, %r15d
cmovlel %ecx, %r15d
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
movq %rax, -0x98(%rbp)
movq %r15, -0xb0(%rbp)
movq %r13, -0xa8(%rbp)
movq %rdx, -0xa0(%rbp)
cmpq %r15, %rcx
je 0x46fb
imulq $0x68, %rcx, %r12
cmpb $0x0, 0xc(%r13,%r12)
jne 0x46f3
addq %r13, %r12
cmpb $0x0, 0x18(%rbp)
je 0x43cb
cmpq $0x0, 0x60(%r12)
jne 0x43db
jmp 0x46f3
movq 0x48(%r12), %rax
cmpq $0x0, (%rax,%rbx,8)
je 0x46f3
movq %rsp, -0xb8(%rbp)
movq %rsp, %rsi
subq -0x98(%rbp), %rsi
movq %rsi, %rsp
xorl %eax, %eax
cmpq %rax, %rdx
je 0x43ff
andl $0x0, (%rsi,%rax,4)
incq %rax
jmp 0x43f1
movq %rsi, -0xd0(%rbp)
movq %rcx, -0xc0(%rbp)
leaq 0x60(%r12), %rax
movq %rax, -0x90(%rbp)
xorl %r13d, %r13d
xorps %xmm4, %xmm4
pushq $-0x1
popq %rax
movq %rax, %r14
movq %rax, -0x48(%rbp)
movss 0xbd37(%rip), %xmm1     # 0x10168
movaps %xmm1, %xmm5
movq $0x0, -0x60(%rbp)
xorl %r10d, %r10d
movss %xmm1, -0x38(%rbp)
movss %xmm1, -0x34(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
xorl %r15d, %r15d
movq 0x50(%r12), %rax
movl (%rax,%rbx,4), %eax
cmpq %rax, %r13
jae 0x4688
movq -0x90(%rbp), %rax
cmpb $0x0, 0x18(%rbp)
jne 0x4487
leaq (,%rbx,8), %rax
addq 0x48(%r12), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movss (%rax,%r13,4), %xmm6
ucomiss %xmm0, %xmm6
jbe 0x4516
movss 0xbcc7(%rip), %xmm3     # 0x10168
cmpb $0x0, 0x18(%rbp)
je 0x44bb
movq -0x90(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movss (%rax,%r13,4), %xmm3
movq 0x48(%r12), %rax
movq (%rax,%rbx,8), %rcx
movq (%rcx), %rax
movl (%rax,%r13,4), %eax
movq %rax, -0x48(%rbp)
subl %r15d, %eax
cvtsi2ss %rax, %xmm1
movaps %xmm6, %xmm2
subss %xmm0, %xmm2
mulss %xmm1, %xmm2
addss %xmm2, %xmm4
cmpq $-0x1, %r14
movl %r15d, %edx
cmoveq %rdx, %r14
ucomiss %xmm5, %xmm6
jbe 0x45a8
movq 0x8(%rcx), %rcx
movss (%rcx,%r13,4), %xmm1
movss %xmm1, -0x38(%rbp)
movaps %xmm6, %xmm5
movss %xmm3, -0x34(%rbp)
jmp 0x45b4
ucomiss 0xbc4b(%rip), %xmm6     # 0x10168
jne 0x4521
jnp 0x4542
movq 0x48(%r12), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %eax
subq -0x48(%rbp), %rax
cmpq -0xc8(%rbp), %rax
jle 0x45c7
movq (%r12), %rdx
subq $0x8, %rsp
movq -0x78(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq %r14, %rcx
movq -0x48(%rbp), %r8
leaq -0x40(%rbp), %r9
movaps %xmm4, %xmm0
movss -0x38(%rbp), %xmm1
movss -0x34(%rbp), %xmm2
movss -0x4c(%rbp), %xmm3
pushq 0x30(%rbp)
movl 0x20(%rbp), %eax
pushq %rax
pushq -0x60(%rbp)
movss %xmm6, -0x3c(%rbp)
callq 0x4204
movss -0x3c(%rbp), %xmm6
movl 0x10(%rbp), %r9d
movss -0x30(%rbp), %xmm0
addq $0x20, %rsp
xorl %r10d, %r10d
xorps %xmm4, %xmm4
pushq $-0x1
popq %r14
movss 0xbbc2(%rip), %xmm5     # 0x10168
jmp 0x45c7
ucomiss %xmm6, %xmm5
jne 0x45c7
jp 0x45c7
cmpl %r10d, %eax
jbe 0x45c7
movq -0x48(%rbp), %rcx
addl %r15d, %ecx
shrl %ecx
subl %r14d, %ecx
movq %rcx, -0x60(%rbp)
movl %eax, %r10d
cmpb $0x0, -0x70(%rbp)
je 0x462b
xorl %eax, %eax
ucomiss %xmm0, %xmm6
seta %al
subq $0x8, %rsp
movq -0x88(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq %r12, %rdx
movl %r15d, %ecx
movl %r9d, %r8d
movl %r13d, %r9d
pushq %rax
pushq -0x80(%rbp)
pushq -0xd0(%rbp)
pushq -0x58(%rbp)
pushq -0x68(%rbp)
movss %xmm4, -0x3c(%rbp)
movss %xmm5, -0x6c(%rbp)
movl %r10d, %r15d
callq 0x3df3
movl %r15d, %r10d
movss -0x6c(%rbp), %xmm5
movss -0x3c(%rbp), %xmm4
movl 0x10(%rbp), %r9d
movss -0x30(%rbp), %xmm0
addq $0x30, %rsp
testl %r9d, %r9d
jne 0x4670
movq 0x28(%r12), %rax
movq 0x38(%r12), %rcx
movq (%rcx), %rcx
movq -0x58(%rbp), %rdi
movl %edi, %edx
movq (%rax), %rax
movq -0x68(%rbp), %r8
movl %r8d, %esi
movl (%rax,%rsi,4), %eax
cmpl %eax, (%rcx,%rdx,4)
jae 0x465d
incl %edi
movq %rdi, -0x58(%rbp)
jmp 0x4670
sete %al
movzbl %al, %eax
addl %eax, %edi
movq %rdi, -0x58(%rbp)
incl %r8d
movq %r8, -0x68(%rbp)
movq 0x48(%r12), %rax
movq (%rax,%rbx,8), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %r15d
incq %r13
jmp 0x445c
movq (%r12), %rdx
subq $0x8, %rsp
movq -0x78(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq %r14, %rcx
movq -0x48(%rbp), %r8
leaq -0x40(%rbp), %r9
movaps %xmm4, %xmm0
movss -0x38(%rbp), %xmm1
movss -0x34(%rbp), %xmm2
movss -0x4c(%rbp), %xmm3
pushq 0x30(%rbp)
movl 0x20(%rbp), %eax
pushq %rax
pushq -0x60(%rbp)
callq 0x4204
movl 0x10(%rbp), %r9d
movss -0x30(%rbp), %xmm0
addq $0x20, %rsp
movq -0xb8(%rbp), %rsp
movq -0xb0(%rbp), %r15
movq -0xa8(%rbp), %r13
movq -0xc0(%rbp), %rcx
movq -0xa0(%rbp), %rdx
incq %rcx
jmp 0x439c
movl -0x40(%rbp), %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq