// File: /workspace/github_c_makefile_star2_O0/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 %r14
pushq %rbx
subq $0xc0, %rsp
movq 0x30(%rbp), %rax
movl 0x28(%rbp), %eax
movl 0x20(%rbp), %eax
movb 0x18(%rbp), %al
movl 0x10(%rbp), %r10d
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
andb $0x1, %dl
movb %dl, -0x21(%rbp)
andb $0x1, %cl
movb %cl, -0x22(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movss %xmm0, -0x38(%rbp)
andb $0x1, %al
movb %al, -0x39(%rbp)
movss %xmm1, -0x40(%rbp)
testb $0x1, -0x21(%rbp)
je 0x5fc3
movb -0x22(%rbp), %cl
movl 0x10(%rbp), %edx
movb -0x39(%rbp), %al
movq -0x20(%rbp), %rdi
movl $0x1, %r8d
andb $0x1, %cl
andb $0x1, %al
movzbl %cl, %esi
movzbl %al, %ecx
callq 0x4a30
movl $0x0, -0x44(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x651d
movq -0x30(%rbp), %rax
movslq -0x48(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
testb $0x1, 0xc(%rax)
jne 0x6024
testb $0x1, -0x39(%rbp)
je 0x600b
movq -0x50(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x6024
testb $0x1, -0x39(%rbp)
jne 0x6029
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movslq 0x10(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x6029
jmp 0x650f
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl 0x10(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x60(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0xb0(%rbp)
movq %rcx, %rsp
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x608d
movq -0xb0(%rbp), %rax
movslq -0x6c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0x6068
xorps %xmm0, %xmm0
movss %xmm0, -0x70(%rbp)
movq $-0x1, -0x78(%rbp)
movq $-0x1, -0x80(%rbp)
movss 0x180e7(%rip), %xmm0    # 0x1e194
movss %xmm0, -0x84(%rbp)
movl $0x0, -0x88(%rbp)
movl $0x0, -0x8c(%rbp)
movss 0x180c3(%rip), %xmm0    # 0x1e194
movss %xmm0, -0x90(%rbp)
movss 0x180b3(%rip), %xmm0    # 0x1e194
movss %xmm0, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
movq -0x50(%rbp), %rcx
movq 0x50(%rcx), %rcx
movslq 0x10(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x64a1
movb $0x0, -0x9d(%rbp)
testb $0x1, -0x39(%rbp)
je 0x6146
movq -0x50(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rax
movl -0x9c(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0xb4(%rbp)
jmp 0x616d
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movl -0x9c(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0xb4(%rbp)
movss -0xb4(%rbp), %xmm0
movss %xmm0, -0xa4(%rbp)
movss -0xa4(%rbp), %xmm0
ucomiss -0x38(%rbp), %xmm0
jbe 0x62c1
movb $0x1, -0x9d(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0xc8(%rbp)
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x9c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0xc4(%rbp)
movss -0xa4(%rbp), %xmm0
movss %xmm0, -0xc0(%rbp)
movss -0x38(%rbp), %xmm0
movss %xmm0, -0xbc(%rbp)
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movl -0x9c(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0xb8(%rbp)
testb $0x1, -0x39(%rbp)
je 0x622f
movq -0x50(%rbp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rax
movl -0x9c(%rbp), %ecx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0xcc(%rbp)
jmp 0x6241
movss 0x17f5d(%rip), %xmm0    # 0x1e194
movss %xmm0, -0xcc(%rbp)
jmp 0x6241
movss -0xb8(%rbp), %xmm2
movss -0xbc(%rbp), %xmm1
movss -0xc0(%rbp), %xmm0
movl -0xc4(%rbp), %ecx
movl -0xc8(%rbp), %edx
movss -0xcc(%rbp), %xmm3
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
leaq -0x70(%rbp), %r8
leaq -0x84(%rbp), %r9
leaq -0x90(%rbp), %rbx
leaq -0x94(%rbp), %r11
leaq -0x88(%rbp), %r10
leaq -0x8c(%rbp), %rax
subq $0x20, %rsp
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movq %r10, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x5df0
addq $0x20, %rsp
jmp 0x638b
movss -0xa4(%rbp), %xmm0
movss 0x17ec3(%rip), %xmm1    # 0x1e194
ucomiss %xmm1, %xmm0
jne 0x62da
jp 0x62da
jmp 0x6307
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x9c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
subq -0x80(%rbp), %rax
movslq 0x28(%rbp), %rcx
cmpq %rcx, %rax
jle 0x6389
movb -0x22(%rbp), %sil
movq -0x50(%rbp), %rax
movq (%rax), %rdx
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %r8
movss -0x70(%rbp), %xmm0
movss -0x90(%rbp), %xmm1
movss -0x94(%rbp), %xmm2
movl -0x88(%rbp), %r11d
movss -0x40(%rbp), %xmm3
movl 0x20(%rbp), %r10d
movq 0x30(%rbp), %rax
movq -0x18(%rbp), %rdi
leaq -0x44(%rbp), %r9
andb $0x1, %sil
subq $0x20, %rsp
movzbl %sil, %esi
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x5cb0
addq $0x20, %rsp
leaq -0x78(%rbp), %rdi
leaq -0x84(%rbp), %rsi
leaq -0x8c(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x5da0
jmp 0x638b
testb $0x1, -0x21(%rbp)
je 0x63fe
movq -0xb0(%rbp), %r11
movb -0x22(%rbp), %sil
movq -0x50(%rbp), %rdx
movl -0x98(%rbp), %ecx
movl 0x10(%rbp), %r8d
movl -0x9c(%rbp), %r9d
movl -0x54(%rbp), %r14d
movl -0x58(%rbp), %ebx
movb -0x39(%rbp), %r10b
movb -0x9d(%rbp), %al
movq -0x20(%rbp), %rdi
andb $0x1, %sil
andb $0x1, %r10b
andb $0x1, %al
subq $0x30, %rsp
movzbl %sil, %esi
movl %r14d, (%rsp)
movl %ebx, 0x8(%rsp)
movq %r11, 0x10(%rsp)
movzbl %r10b, %r10d
movl %r10d, 0x18(%rsp)
movzbl %al, %eax
movl %eax, 0x20(%rsp)
callq 0x5300
addq $0x30, %rsp
cmpl $0x0, 0x10(%rbp)
jne 0x646b
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movl -0x58(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x50(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
movl -0x54(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jae 0x6433
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x6469
movq -0x50(%rbp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movl -0x58(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0x50(%rbp), %rcx
movq 0x28(%rcx), %rcx
movq (%rcx), %rcx
movl -0x54(%rbp), %edx
cmpl (%rcx,%rdx,4), %eax
jne 0x6460
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x646b
movq -0x50(%rbp), %rax
movq 0x48(%rax), %rax
movslq 0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movl -0x9c(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movl %eax, -0x98(%rbp)
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x60fd
movb -0x22(%rbp), %sil
movq -0x50(%rbp), %rax
movq (%rax), %rdx
movq -0x78(%rbp), %rcx
movq -0x80(%rbp), %r8
movss -0x70(%rbp), %xmm0
movss -0x90(%rbp), %xmm1
movss -0x94(%rbp), %xmm2
movl -0x88(%rbp), %r11d
movss -0x40(%rbp), %xmm3
movl 0x20(%rbp), %r10d
movq 0x30(%rbp), %rax
movq -0x18(%rbp), %rdi
leaq -0x44(%rbp), %r9
andb $0x1, %sil
subq $0x20, %rsp
movzbl %sil, %esi
movl %r11d, (%rsp)
movl %r10d, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x5cb0
addq $0x20, %rsp
movq -0x60(%rbp), %rax
movq %rax, %rsp
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x5fd1
movl -0x44(%rbp), %eax
leaq -0x10(%rbp), %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopl (%rax)