// File: /workspace/github_c_makefile_star2_O1/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 0x5b18
movq %r14, %rdi
movl %ebx, %esi
callq 0x4815
incl (%r13)
movq %r15, %r12
testq %r15, %r15
jne 0x5b81
testl %ebx, %ebx
jle 0x5b7e
movl %ebx, %eax
xorl %ecx, %ecx
xorl %r12d, %r12d
imulq $0x68, %rcx, %rsi
cmpb $0x0, 0xc(%r14,%rsi)
jne 0x5b74
addq %r14, %rsi
movq 0x48(%rsi), %rdx
movslq (%r13), %rdi
cmpq $0x0, -0x8(%rdx,%rdi,8)
je 0x5b74
movl 0x8(%rsi), %edx
addq %rdx, %r12
movslq 0x18(%rsi), %rdx
testq %rdx, %rdx
jle 0x5b74
movq 0x10(%rsi), %rsi
xorl %edi, %edi
movl 0x4(%rsi,%rdi,4), %r8d
subl (%rsi,%rdi,4), %r8d
subq %r8, %r12
addq $0x2, %rdi
cmpq %rdx, %rdi
jb 0x5b5f
incq %rcx
cmpq %rax, %rcx
jne 0x5b2b
jmp 0x5b81
xorl %r12d, %r12d
cmpb $0x0, 0xe(%rsp)
jne 0x5c7c
testb %bpl, %bpl
je 0x5bb3
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 0x3fe0
cmpb $0x0, 0xf(%rsp)
je 0x5c39
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 0x554e
addq $0x30, %rsp
cmpb $0x0, 0xe(%rsp)
je 0x5c6d
movq 0x143d9(%rip), %rcx     # 0x19ff8
movq (%rcx), %rdi
movq 0x40(%rsp), %rcx
leaq 0xd9a0(%rip), %rsi      # 0x135ce
movl %eax, %edx
xorl %eax, %eax
callq 0x21d0
jmp 0x5c6d
cmpb $0x0, 0x1c(%rsp)
je 0x5c6d
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 0x51b5
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x14375(%rip), %rax     # 0x19ff8
movq (%rax), %rcx
cmpb $0x0, 0xf(%rsp)
je 0x5d4e
leaq 0xd873(%rip), %rdi      # 0x1350b
movl $0x19, %esi
movl $0x1, %edx
callq 0x22b0
movq 0x1434a(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xd86d(%rip), %rsi      # 0x13525
movq %r12, %rdx
xorl %eax, %eax
callq 0x21d0
movq 0x1432f(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movzbl %bpl, %edx
orl $0x70, %edx
cvtss2sd 0x10(%rsp), %xmm0
leaq 0xd85d(%rip), %rsi      # 0x1353d
movb $0x1, %al
callq 0x21d0
movq 0x1430a(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
xorps %xmm0, %xmm0
cvtss2sd 0x14(%rsp), %xmm0
leaq 0xd867(%rip), %rsi      # 0x13568
movb $0x1, %al
callq 0x21d0
cmpl $0x0, 0x20(%rsp)
je 0x5d2c
movq 0x142e2(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xd85a(%rip), %rsi      # 0x1357a
movq 0x20(%rsp), %rdx
xorl %eax, %eax
callq 0x21d0
movq 0x142c5(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
leaq 0xd857(%rip), %rsi      # 0x13594
movq 0x28(%rsp), %rdx
xorl %eax, %eax
callq 0x21d0
jmp 0x5b8c
movq %rcx, %rdi
movq %r12, %rsi
callq 0x2ac3
jmp 0x5b8c