// File: /workspace/github_c_makefile_star2_O1/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, -0x54(%rbp)
movss %xmm0, -0x44(%rbp)
movl %r9d, %ebx
movq %r8, %r12
movq %rsi, -0xa8(%rbp)
movq %rdi, -0x90(%rbp)
movb 0x18(%rbp), %dil
movl 0x10(%rbp), %r8d
movzbl %cl, %eax
movl %eax, -0x38(%rbp)
movzbl %dil, %eax
movq %rax, -0xa0(%rbp)
movl %edx, -0x74(%rbp)
testl %edx, %edx
je 0x55c7
movq -0xa8(%rbp), %rdi
movl -0x38(%rbp), %esi
movl %r8d, %edx
movq -0xa0(%rbp), %rcx
movl $0x1, %r8d
callq 0x4a76
movl 0x10(%rbp), %r8d
movb 0x18(%rbp), %dil
testl %ebx, %ebx
jle 0x5a70
movslq %r8d, %r9
movl %r8d, %eax
movslq 0x28(%rbp), %rcx
movq %rcx, -0xd0(%rbp)
movslq 0x20(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movl %ebx, %r13d
xorl %ebx, %ebx
leaq 0xf(,%rax,4), %rcx
shlq $0x2, %rax
movq %rax, -0xb0(%rbp)
andq $-0x10, %rcx
movq %rcx, -0xb8(%rbp)
movss 0xcb42(%rip), %xmm4     # 0x12158
movl $0x0, -0x2c(%rbp)
movq %r9, -0x60(%rbp)
movq %r12, -0x88(%rbp)
movq %r13, -0x80(%rbp)
imulq $0x68, %rbx, %r15
cmpb $0x0, 0xc(%r12,%r15)
jne 0x5a62
addq %r12, %r15
testb %dil, %dil
je 0x5654
cmpq $0x0, 0x60(%r15)
je 0x5a62
testb %dil, %dil
jne 0x5663
movq 0x48(%r15), %rax
cmpq $0x0, (%rax,%r9,8)
je 0x5a62
movq %rsp, -0xc0(%rbp)
movq %rsp, %r14
subq -0xb8(%rbp), %r14
movq %r14, %rsp
testl %r8d, %r8d
jle 0x56a1
movq %r14, %rdi
xorl %esi, %esi
movq -0xb0(%rbp), %rdx
callq 0x2140
movss 0xcac3(%rip), %xmm4     # 0x12158
movq -0x60(%rbp), %r9
movl 0x10(%rbp), %r8d
movb 0x18(%rbp), %dil
movq %rbx, -0xc8(%rbp)
movq 0x50(%r15), %rax
cmpl $0x0, (%rax,%r9,4)
je 0x59ab
movq %r14, -0xd8(%rbp)
leaq 0x60(%r15), %rax
movq %rax, -0xe0(%rbp)
xorps %xmm0, %xmm0
movq $-0x1, %r10
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %r11d, %r11d
xorl %r12d, %r12d
movss %xmm4, -0x30(%rbp)
movss %xmm4, -0x34(%rbp)
movl $0x0, -0x40(%rbp)
movq $0x0, -0x50(%rbp)
movaps %xmm4, %xmm6
movq $-0x1, %rbx
movss -0x44(%rbp), %xmm3
movq -0xe0(%rbp), %rax
testb %dil, %dil
jne 0x571f
leaq (,%r9,8), %rax
addq 0x48(%r15), %rax
movq (%rax), %rax
movq 0x8(%rax), %rax
movss (%rax,%r13,4), %xmm7
ucomiss %xmm3, %xmm7
jbe 0x57af
movaps %xmm4, %xmm5
testb %dil, %dil
je 0x5747
movq 0x60(%r15), %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), %r10d
movl %r10d, %eax
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 0x5885
movq 0x8(%rcx), %rcx
movss (%rcx,%r13,4), %xmm1
movss %xmm1, -0x34(%rbp)
leal (%r10,%r14), %ecx
shrl %ecx
subl %ebx, %ecx
movq %rcx, -0x50(%rbp)
movaps %xmm7, %xmm6
movss %xmm5, -0x30(%rbp)
jmp 0x58b7
ucomiss %xmm4, %xmm7
jne 0x57b6
jnp 0x57d5
movq 0x48(%r15), %rax
movq (%rax,%r9,8), %rax
movq (%rax), %rax
movl (%rax,%r13,4), %eax
subq %r10, %rax
cmpq -0xd0(%rbp), %rax
jle 0x58b0
xorl %eax, %eax
ucomiss -0x54(%rbp), %xmm0
jb 0x58a1
cmpq $-0x1, %rbx
je 0x58a1
movq %r12, -0x40(%rbp)
movq %r10, %r12
subq %rbx, %r12
cmpq -0x98(%rbp), %r12
jl 0x5872
movq (%r15), %rdx
subq $0x8, %rsp
movq -0x90(%rbp), %rdi
movl -0x38(%rbp), %esi
movq %rbx, %rcx
movq %r10, %r8
movl -0x2c(%rbp), %ebx
movl %ebx, %r9d
movss -0x34(%rbp), %xmm1
movss -0x30(%rbp), %xmm2
pushq -0x50(%rbp)
movq %r10, -0x70(%rbp)
movq %r11, -0x68(%rbp)
movss %xmm7, -0x48(%rbp)
callq 0x536b
movss -0x48(%rbp), %xmm7
movq -0x68(%rbp), %r11
movq -0x70(%rbp), %r10
movss 0xc909(%rip), %xmm4     # 0x12158
movq -0x60(%rbp), %r9
movl 0x10(%rbp), %r8d
movb 0x18(%rbp), %dil
movss -0x44(%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
movq -0x40(%rbp), %r12
jmp 0x58b7
ucomiss %xmm7, %xmm6
jne 0x58b0
jp 0x58b0
movl -0x40(%rbp), %ecx
cmpl %ecx, %eax
jbe 0x58b5
leal (%r10,%r14), %ecx
shrl %ecx
subl %ebx, %ecx
movq %rcx, -0x50(%rbp)
jmp 0x58b7
xorps %xmm0, %xmm0
movq $-0x1, %rbx
movaps %xmm4, %xmm6
jmp 0x58b7
movl -0x40(%rbp), %eax
jmp 0x58b7
movl %ecx, %eax
movl %eax, -0x40(%rbp)
cmpb $0x0, -0x74(%rbp)
je 0x5954
xorl %eax, %eax
ucomiss %xmm3, %xmm7
seta %al
subq $0x8, %rsp
movq -0xa8(%rbp), %rdi
movl -0x38(%rbp), %esi
movq %r15, %rdx
movl %r14d, %ecx
movl 0x10(%rbp), %r8d
movl %r13d, %r9d
pushq %rax
pushq -0xa0(%rbp)
pushq -0xd8(%rbp)
pushq %r12
pushq %r11
movss %xmm0, -0x70(%rbp)
movq %r10, %r14
movq %r13, -0x68(%rbp)
movq %r15, %r13
movq %rbx, %r15
movq %r12, %rbx
movq %r11, %r12
movss %xmm6, -0x48(%rbp)
callq 0x5071
movss -0x48(%rbp), %xmm6
movq %r12, %r11
movq %rbx, %r12
movq %r15, %rbx
movq %r13, %r15
movq -0x68(%rbp), %r13
movq %r14, %r10
movss -0x70(%rbp), %xmm0
movss 0xc819(%rip), %xmm4     # 0x12158
movq -0x60(%rbp), %r9
movl 0x10(%rbp), %r8d
movb 0x18(%rbp), %dil
movss -0x44(%rbp), %xmm3
addq $0x30, %rsp
testl %r8d, %r8d
jne 0x5986
movq 0x28(%r15), %rax
movq 0x38(%r15), %rcx
movq (%rcx), %rcx
movl %r12d, %edx
movq (%rax), %rax
movl %r11d, %esi
movl (%rax,%rsi,4), %eax
cmpl %eax, (%rcx,%rdx,4)
jae 0x597a
incl %r12d
jmp 0x5986
sete %al
movzbl %al, %eax
addl %eax, %r12d
incl %r11d
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 0x5707
jmp 0x59ce
movq $0x0, -0x50(%rbp)
movq $-0x1, %rbx
xorps %xmm0, %xmm0
movq $-0x1, %r10
movss %xmm4, -0x34(%rbp)
movss %xmm4, -0x30(%rbp)
ucomiss -0x54(%rbp), %xmm0
jb 0x5a49
cmpq $-0x1, %rbx
movq -0x88(%rbp), %r12
movq -0x80(%rbp), %r13
je 0x5a54
movq %r10, %r14
subq %rbx, %r14
cmpq -0x98(%rbp), %r14
jl 0x5a54
movq (%r15), %rdx
subq $0x8, %rsp
movq -0x90(%rbp), %rdi
movl -0x38(%rbp), %esi
movq %rbx, %rcx
movq %r10, %r8
movl -0x2c(%rbp), %ebx
movl %ebx, %r9d
movss -0x34(%rbp), %xmm1
movss -0x30(%rbp), %xmm2
pushq -0x50(%rbp)
callq 0x536b
movss 0xc72d(%rip), %xmm4     # 0x12158
movq -0x60(%rbp), %r9
movl 0x10(%rbp), %r8d
movb 0x18(%rbp), %dil
addq $0x10, %rsp
movq 0x30(%rbp), %rax
addq %r14, (%rax)
incl %ebx
movl %ebx, -0x2c(%rbp)
jmp 0x5a54
movq -0x88(%rbp), %r12
movq -0x80(%rbp), %r13
movq -0xc0(%rbp), %rsp
movq -0xc8(%rbp), %rbx
incq %rbx
cmpq %r13, %rbx
jne 0x562c
jmp 0x5a77
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