// File: /workspace/github_c_makefile_star2_O3/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, 0x14(%rsp)
movss %xmm0, 0x10(%rsp)
movl %r9d, %ebx
movq %r8, %r14
movl %ecx, 0x18(%rsp)
movl %edx, 0x1c(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, 0x38(%rsp)
movb 0xb0(%rsp), %al
movb %al, 0xe(%rsp)
movq 0xa8(%rsp), %r15
movb 0xa0(%rsp), %al
movb %al, 0xf(%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 0x5a67
movq %r14, %rdi
movl %ebx, %esi
callq 0x47d7
movl (%r13), %edx
incl %edx
movl %edx, (%r13)
movq %r15, %r12
testq %r15, %r15
jne 0x5ad0
testl %ebx, %ebx
jle 0x5acd
movl %ebx, %eax
movslq %edx, %rcx
xorl %edx, %edx
xorl %r12d, %r12d
imulq $0x68, %rdx, %rdi
cmpb $0x0, 0xc(%r14,%rdi)
jne 0x5ac3
addq %r14, %rdi
movq 0x48(%rdi), %rsi
cmpq $0x0, -0x8(%rsi,%rcx,8)
je 0x5ac3
movl 0x8(%rdi), %esi
addq %rsi, %r12
movslq 0x18(%rdi), %rsi
testq %rsi, %rsi
jle 0x5ac3
movq 0x10(%rdi), %rdi
xorl %r8d, %r8d
movl 0x4(%rdi,%r8,4), %r9d
subl (%rdi,%r8,4), %r9d
subq %r9, %r12
addq $0x2, %r8
cmpq %rsi, %r8
jb 0x5aae
incq %rdx
cmpq %rax, %rdx
jne 0x5a7d
jmp 0x5ad0
xorl %r12d, %r12d
cmpb $0x0, 0xe(%rsp)
jne 0x5bcb
testb %bpl, %bpl
je 0x5b02
xorl %ecx, %ecx
testq %r15, %r15
sete %cl
movl (%r13), %r8d
decl %r8d
movzbl 0xe(%rsp), %r9d
movq %r14, %rdi
movl %ebx, %esi
movq %r12, %rdx
callq 0x4007
cmpb $0x0, 0xf(%rsp)
je 0x5b88
leaq 0x40(%rsp), %rax
movq $0x0, (%rax)
movl (%r13), %r10d
decl %r10d
subq $0x8, %rsp
movzbl %bpl, %r11d
movzbl 0x24(%rsp), %edx
movzbl 0x20(%rsp), %ecx
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
movq %r14, %r8
movl %ebx, %r9d
movss 0x18(%rsp), %xmm0
movss 0x1c(%rsp), %xmm1
pushq %rax
pushq 0x38(%rsp)
pushq 0x38(%rsp)
pushq %r11
pushq %r10
callq 0x5501
addq $0x30, %rsp
cmpb $0x0, 0xe(%rsp)
je 0x5bbc
movq 0x1448a(%rip), %rcx     # 0x19ff8
movq (%rcx), %rdi
movq 0x40(%rsp), %rcx
leaq 0xda51(%rip), %rsi      # 0x135ce
movl %eax, %edx
xorl %eax, %eax
callq 0x21d0
jmp 0x5bbc
cmpb $0x0, 0x1c(%rsp)
je 0x5bbc
movl (%r13), %r8d
decl %r8d
movzbl 0x18(%rsp), %esi
movzbl %bpl, %r9d
movq 0x30(%rsp), %rdi
movq %r14, %rdx
movl %ebx, %ecx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5172
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x14426(%rip), %rax     # 0x19ff8
movq (%rax), %rcx
cmpb $0x0, 0xf(%rsp)
je 0x5c9d
leaq 0xd924(%rip), %rdi      # 0x1350b
movl $0x19, %esi
movl $0x1, %edx
callq 0x22b0
movq 0x143fb(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xd91e(%rip), %rsi      # 0x13525
movq %r12, %rdx
xorl %eax, %eax
callq 0x21d0
movq 0x143e0(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movzbl %bpl, %edx
orl $0x70, %edx
cvtss2sd 0x10(%rsp), %xmm0
leaq 0xd90e(%rip), %rsi      # 0x1353d
movb $0x1, %al
callq 0x21d0
movq 0x143bb(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
xorps %xmm0, %xmm0
cvtss2sd 0x14(%rsp), %xmm0
leaq 0xd918(%rip), %rsi      # 0x13568
movb $0x1, %al
callq 0x21d0
cmpl $0x0, 0x20(%rsp)
je 0x5c7b
movq 0x14393(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xd90b(%rip), %rsi      # 0x1357a
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x21d0
movq 0x14376(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xd908(%rip), %rsi      # 0x13594
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x21d0
jmp 0x5adb
movq %rcx, %rdi
movq %r12, %rsi
callq 0x2aec
jmp 0x5adb