// File: /workspace/github_c_makefile_star2_O3/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 $0xb8, %rsp
movss %xmm1, -0x4c(%rbp)
movss %xmm0, -0x3c(%rbp)
movl %r9d, %ebx
movq %r8, %r12
movq %rsi, -0xb0(%rbp)
movq %rdi, -0x98(%rbp)
movb 0x18(%rbp), %dil
movzbl %cl, %eax
movl %eax, -0x30(%rbp)
movzbl %dil, %eax
movq %rax, -0xa8(%rbp)
movl %edx, -0x90(%rbp)
testl %edx, %edx
je 0x5575
movq -0xb0(%rbp), %rdi
movl -0x30(%rbp), %esi
movl 0x10(%rbp), %edx
movq -0xa8(%rbp), %rcx
movl $0x1, %r8d
callq 0x4a33
movb 0x18(%rbp), %dil
testl %ebx, %ebx
jle 0x59b9
movl 0x10(%rbp), %eax
movslq %eax, %r9
movl %eax, %eax
movslq 0x28(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movslq 0x20(%rbp), %rcx
movq %rcx, -0xa0(%rbp)
movl %ebx, %ebx
xorl %r13d, %r13d
leaq 0xf(,%rax,4), %rcx
shlq $0x2, %rax
movq %rax, -0xc0(%rbp)
andq $-0x10, %rcx
movq %rcx, -0xd0(%rbp)
movl $0x0, -0x2c(%rbp)
movq %r9, -0x60(%rbp)
movq %r12, -0xc8(%rbp)
movq %rbx, -0x58(%rbp)
imulq $0x68, %r13, %r15
cmpb $0x0, 0xc(%r12,%r15)
jne 0x59ab
addq %r12, %r15
testb %dil, %dil
je 0x55f8
cmpq $0x0, 0x60(%r15)
jne 0x5607
jmp 0x59ab
movq 0x48(%r15), %rax
cmpq $0x0, (%rax,%r9,8)
je 0x59ab
movq %rsp, %r14
movq %rsp, %r10
subq -0xd0(%rbp), %r10
movq %r10, %rsp
cmpl $0x0, 0x10(%rbp)
movq %r10, -0x80(%rbp)
jle 0x563e
movq %r10, %rdi
xorl %esi, %esi
movq -0xc0(%rbp), %rdx
callq 0x2140
movq -0x80(%rbp), %r10
movq -0x60(%rbp), %r9
movb 0x18(%rbp), %dil
movq 0x50(%r15), %rax
cmpl $0x0, (%rax,%r9,4)
je 0x59a8
movq %r14, -0x70(%rbp)
movq %r13, -0xd8(%rbp)
leaq 0x60(%r15), %r11
xorps %xmm0, %xmm0
movq $-0x1, -0x48(%rbp)
xorl %r13d, %r13d
xorl %r14d, %r14d
movq $0x0, -0x88(%rbp)
movq $0x0, -0x68(%rbp)
movss 0xcac8(%rip), %xmm4     # 0x12150
movss %xmm4, -0x34(%rbp)
movss %xmm4, -0x38(%rbp)
xorl %r12d, %r12d
movq $0x0, -0x78(%rbp)
movaps %xmm4, %xmm6
movq $-0x1, %rbx
movss -0x3c(%rbp), %xmm3
movq %r11, -0xb8(%rbp)
movq %r11, %rax
testb %dil, %dil
jne 0x56c7
leaq (,%r9,8), %rax
addq 0x48(%r15), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movss (%rax,%r13,4), %xmm7
ucomiss %xmm3, %xmm7
jbe 0x574b
movaps %xmm4, %xmm5
testb %dil, %dil
je 0x56ee
movq (%r11), %rax
movq 0x8(%rax), %rax
movss (%rax,%r13,4), %xmm5
movq 0x48(%r15), %rax
movq (%rax,%r9,8), %rcx
movq (%rcx), %rax
movl (%rax,%r13,4), %eax
movq %rax, -0x48(%rbp)
subl %r14d, %eax
xorps %xmm1, %xmm1
cvtsi2ss %rax, %xmm1
movaps %xmm7, %xmm2
subss %xmm3, %xmm2
mulss %xmm1, %xmm2
addss %xmm2, %xmm0
cmpq $-0x1, %rbx
movl %r14d, %edx
cmoveq %rdx, %rbx
ucomiss %xmm6, %xmm7
jbe 0x580e
movq 0x8(%rcx), %rcx
movss (%rcx,%r13,4), %xmm1
movss %xmm1, -0x38(%rbp)
movaps %xmm7, %xmm6
movss %xmm5, -0x34(%rbp)
jmp 0x581a
ucomiss %xmm4, %xmm7
jne 0x5752
jnp 0x5772
movq 0x48(%r15), %rax
movq (%rax,%r9,8), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %eax
subq -0x48(%rbp), %rax
cmpq -0xe0(%rbp), %rax
jle 0x582b
xorl %eax, %eax
ucomiss -0x4c(%rbp), %xmm0
jb 0x57ff
cmpq $-0x1, %rbx
je 0x57ff
movq -0x48(%rbp), %r8
movq %r8, %r12
subq %rbx, %r12
cmpq -0xa0(%rbp), %r12
jl 0x57ff
movq (%r15), %rdx
subq $0x8, %rsp
movq -0x98(%rbp), %rdi
movl -0x30(%rbp), %esi
movq %rbx, %rcx
movl -0x2c(%rbp), %ebx
movl %ebx, %r9d
movss -0x38(%rbp), %xmm1
movss -0x34(%rbp), %xmm2
pushq -0x78(%rbp)
movss %xmm7, -0x40(%rbp)
callq 0x531e
movss -0x40(%rbp), %xmm7
movq -0xb8(%rbp), %r11
movq -0x80(%rbp), %r10
movss 0xc970(%rip), %xmm4     # 0x12150
movq -0x60(%rbp), %r9
movb 0x18(%rbp), %dil
movss -0x3c(%rbp), %xmm3
addq $0x10, %rsp
movq 0x30(%rbp), %rax
addq %r12, (%rax)
xorl %eax, %eax
incl %ebx
movl %ebx, -0x2c(%rbp)
xorps %xmm0, %xmm0
movq $-0x1, %rbx
movaps %xmm4, %xmm6
jmp 0x582e
ucomiss %xmm7, %xmm6
jne 0x582b
jp 0x582b
cmpl %r12d, %eax
jbe 0x582b
movq -0x48(%rbp), %rcx
addl %r14d, %ecx
shrl %ecx
subl %ebx, %ecx
movq %rcx, -0x78(%rbp)
jmp 0x582e
movl %r12d, %eax
movl %eax, %r12d
cmpb $0x0, -0x90(%rbp)
je 0x58b2
xorl %eax, %eax
ucomiss %xmm3, %xmm7
seta %al
subq $0x8, %rsp
movq -0xb0(%rbp), %rdi
movl -0x30(%rbp), %esi
movq %r15, %rdx
movl %r14d, %ecx
movl 0x10(%rbp), %r8d
movl %r13d, %r9d
pushq %rax
pushq -0xa8(%rbp)
pushq %r10
pushq -0x68(%rbp)
pushq -0x88(%rbp)
movss %xmm0, -0x40(%rbp)
movss %xmm6, -0x8c(%rbp)
callq 0x502e
movss -0x8c(%rbp), %xmm6
movq -0xb8(%rbp), %r11
movss -0x40(%rbp), %xmm0
movq -0x80(%rbp), %r10
movss 0xc8af(%rip), %xmm4     # 0x12150
movq -0x60(%rbp), %r9
movb 0x18(%rbp), %dil
movss -0x3c(%rbp), %xmm3
addq $0x30, %rsp
cmpl $0x0, 0x10(%rbp)
jne 0x58ff
movq 0x28(%r15), %rax
movq 0x38(%r15), %rcx
movq (%rcx), %rcx
movq -0x68(%rbp), %r14
movl %r14d, %edx
movq (%rax), %rax
movq -0x88(%rbp), %r8
movl %r8d, %esi
movl (%rax,%rsi,4), %eax
cmpl %eax, (%rcx,%rdx,4)
jae 0x58e8
incl %r14d
movq %r14, -0x68(%rbp)
jmp 0x58ff
sete %al
movzbl %al, %eax
addl %eax, %r14d
movq %r14, -0x68(%rbp)
incl %r8d
movq %r8, -0x88(%rbp)
movq 0x48(%r15), %rax
movq 0x50(%r15), %rcx
movq (%rax,%r9,8), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %r14d
incq %r13
movl (%rcx,%r9,4), %eax
cmpq %rax, %r13
jb 0x56b3
ucomiss -0x4c(%rbp), %xmm0
movq -0xc8(%rbp), %r12
movq -0xd8(%rbp), %r13
movq -0x70(%rbp), %r14
jb 0x59a4
cmpq $-0x1, %rbx
je 0x59a4
movq -0x48(%rbp), %rax
movq %rax, %r14
subq %rbx, %r14
cmpq -0xa0(%rbp), %r14
jl 0x599a
movq (%r15), %rdx
subq $0x8, %rsp
movq -0x98(%rbp), %rdi
movl -0x30(%rbp), %esi
movq %rbx, %rcx
movq %rax, %r8
movl -0x2c(%rbp), %ebx
movl %ebx, %r9d
movss -0x38(%rbp), %xmm1
movss -0x34(%rbp), %xmm2
pushq -0x78(%rbp)
callq 0x531e
movq -0x60(%rbp), %r9
movb 0x18(%rbp), %dil
addq $0x10, %rsp
movq 0x30(%rbp), %rax
addq %r14, (%rax)
incl %ebx
movl %ebx, -0x2c(%rbp)
movq -0x58(%rbp), %rbx
movq -0x70(%rbp), %r14
jmp 0x59a8
movq -0x58(%rbp), %rbx
movq %r14, %rsp
incq %r13
cmpq %rbx, %r13
jne 0x55d4
jmp 0x59c0
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq