// File: /workspace/github_c_makefile_star2_O2/jsh58[P]Genrich/Genrich.c
// Function: findPeaks
void findPeaks(File out, File log, bool logOpt, bool gzOut,
    Chrom* chrom, int chromLen, int* sample,
    float minPQval, bool qvalOpt, int minLen, int maxGap,
    float minAUC, bool peaksOpt, uint64_t genomeLen,
    bool verbose) {

  // calculate combined p-values for multiple replicates
  if (*sample > 1) {
    combinePval(chrom, chromLen, *sample);
    (*sample)++;
  }

  // calculate genome length (only chroms that are not
  //   skipped and have had p-values calculated)
  bool genomeOpt = false;
  if (! genomeLen) {
    genomeOpt = true;
    for (int i = 0; i < chromLen; i++) {
      Chrom* chr = chrom + i;
      if (! chr->skip && chr->pval[*sample - 1] != NULL) {
        genomeLen += chr->len;
        for (int j = 0; j < chr->bedLen; j += 2)
          genomeLen -= chr->bed[j+1] - chr->bed[j];
      }
    }
  }

  if (verbose) {
    if (peaksOpt) {
      fprintf(stderr, "Peak-calling parameters:\n");
      fprintf(stderr, "  Genome length: %ldbp\n", genomeLen);
      fprintf(stderr, "  Significance threshold: -log(%c) > %.3f\n",
        qvalOpt ? 'q' : 'p', minPQval);
      fprintf(stderr, "  Min. AUC: %.3f\n", minAUC);
      if (minLen)
        fprintf(stderr, "  Min. peak length: %dbp\n", minLen);
      fprintf(stderr, "  Max. gap between sites: %dbp\n", maxGap);
    } else {
      fprintf(stderr, "- peak-calling skipped -\n");
      fprintf(stderr, "  Genome length: %ldbp\n", genomeLen);
    }
  }

  // compute q-values
  if (qvalOpt)
    computeQval(chrom, chromLen, genomeLen, genomeOpt,
      *sample - 1, verbose);

  // call peaks
  if (peaksOpt) {
    uint64_t peakBP = 0;
    int count = callPeaks(out, log, logOpt, gzOut, chrom,
      chromLen, *sample - 1, minPQval, qvalOpt, minAUC,
      minLen, maxGap, &peakBP);
    if (verbose)
      fprintf(stderr, "Peaks identified: %d (%ldbp)\n",
        count, peakBP);
  } else if (logOpt)
    // not calling peaks -- just log pileups and stats
    logIntervals(log, gzOut, chrom, chromLen, *sample - 1,
      qvalOpt);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movss %xmm1, 0xc(%rsp)
movss %xmm0, 0x8(%rsp)
movl %r9d, %ebx
movq %r8, %r14
movl %ecx, 0x10(%rsp)
movl %edx, 0x14(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x38(%rsp)
movb 0xb0(%rsp), %al
movb %al, 0x6(%rsp)
movq 0xa8(%rsp), %r15
movb 0xa0(%rsp), %al
movb %al, 0x7(%rsp)
movl 0x98(%rsp), %eax
movq %rax, 0x28(%rsp)
movl 0x90(%rsp), %eax
movq %rax, 0x20(%rsp)
movb 0x88(%rsp), %bpl
movq 0x80(%rsp), %r13
movl (%r13), %edx
cmpl $0x2, %edx
jl 0x47a2
movq %r14, %rdi
movl %ebx, %esi
callq 0x35d7
movl (%r13), %edx
incl %edx
movl %edx, (%r13)
movq %r15, %r12
testq %r15, %r15
je 0x48ab
movzbl %bpl, %r11d
cmpb $0x0, 0x6(%rsp)
jne 0x490e
testb %bpl, %bpl
je 0x47ea
xorl %ecx, %ecx
testq %r15, %r15
sete %cl
movl (%r13), %r8d
decl %r8d
movzbl 0x6(%rsp), %r9d
movq %r14, %rdi
movl %ebx, %esi
movq %r12, %rdx
movq %r11, %r15
callq 0x2e36
movq %r15, %r11
cmpb $0x0, 0x7(%rsp)
je 0x4869
leaq 0x40(%rsp), %rax
andq $0x0, (%rax)
movl (%r13), %r10d
decl %r10d
subq $0x8, %rsp
movzbl 0x1c(%rsp), %edx
movzbl 0x18(%rsp), %ecx
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %r14, %r8
movl %ebx, %r9d
movss 0x10(%rsp), %xmm0
movss 0x14(%rsp), %xmm1
pushq %rax
pushq 0x38(%rsp)
pushq 0x38(%rsp)
pushq %r11
pushq %r10
callq 0x42d9
addq $0x30, %rsp
cmpb $0x0, 0x6(%rsp)
je 0x489c
movq 0x127a9(%rip), %rcx     # 0x16ff8
movq (%rcx), %rdi
movq 0x40(%rsp), %rcx
leaq 0xccc0(%rip), %rsi      # 0x1151e
movl %eax, %edx
xorl %eax, %eax
callq 0x21c0
jmp 0x489c
cmpb $0x0, 0x14(%rsp)
je 0x489c
movl (%r13), %r8d
decl %r8d
movzbl 0x10(%rsp), %esi
movq 0x30(%rsp), %rdi
movq %r14, %rdx
movl %ebx, %ecx
movl %r11d, %r9d
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3f38
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %eax, %eax
testl %ebx, %ebx
movl $0x0, %ecx
cmovgl %ebx, %ecx
movslq %edx, %rdx
xorl %r12d, %r12d
cmpq %rcx, %rax
je 0x47ae
imulq $0x68, %rax, %rsi
cmpb $0x0, 0xc(%r14,%rsi)
jne 0x4909
addq %r14, %rsi
movq 0x48(%rsi), %rdi
cmpq $0x0, -0x8(%rdi,%rdx,8)
je 0x4909
movl 0x8(%rsi), %edi
addq %rdi, %r12
movslq 0x18(%rsi), %rdi
xorl %r8d, %r8d
cmpq %rdi, %r8
jge 0x4909
movq 0x10(%rsi), %r9
movl 0x4(%r9,%r8,4), %r10d
subl (%r9,%r8,4), %r10d
subq %r10, %r12
addq $0x2, %r8
jmp 0x48ee
incq %rax
jmp 0x48bd
movq %r11, 0x18(%rsp)
movq 0x126de(%rip), %rax     # 0x16ff8
movq (%rax), %rcx
cmpb $0x0, 0x7(%rsp)
je 0x49dc
leaq 0xcb2c(%rip), %rdi      # 0x1145b
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x22b0
movq 0x126b7(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xcb2a(%rip), %rsi      # 0x11475
movq %r12, %rdx
xorl %eax, %eax
callq 0x21c0
movq 0x1269c(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
movq 0x18(%rsp), %rax
leal 0x70(%rax), %edx
cvtss2sd 0x8(%rsp), %xmm0
leaq 0xcb19(%rip), %rsi      # 0x1148d
movb $0x1, %al
callq 0x21c0
movq 0x12676(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
cvtss2sd 0xc(%rsp), %xmm0
leaq 0xcb26(%rip), %rsi      # 0x114b8
movb $0x1, %al
callq 0x21c0
cmpl $0x0, 0x20(%rsp)
je 0x49bd
movq 0x12651(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xcb19(%rip), %rsi      # 0x114ca
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x21c0
movq 0x12634(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xcb16(%rip), %rsi      # 0x114e4
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x21c0
jmp 0x4a09
leaq 0xcb21(%rip), %rdi      # 0x11504
pushq $0x19
popq %rsi
pushq $0x1
popq %rdx
callq 0x22b0
movq 0x12603(%rip), %rax     # 0x16ff8
movq (%rax), %rdi
leaq 0xca76(%rip), %rsi      # 0x11475
movq %r12, %rdx
xorl %eax, %eax
callq 0x21c0
movq 0x18(%rsp), %r11
jmp 0x47bd