// File: /workspace/github_c_makefile_star2_O0/jsh58[P]Genrich/Genrich.c
// Function: saveQval
void saveQval(Chrom* chrom, int chromLen, int n,
    uint64_t genomeLen, float* pVal, uint64_t* pEnd,
    int64_t pLen, bool verbose) {

  // sort pileup by p-values
  quickSort(pVal, pEnd, 0, pLen - 1);

  // calculate q-values for each p-value: -log(q) = -log(p*N/k)
  uint64_t k = 1;  // 1 + number of bases with higher -log(p)
  float logN = -log10f(genomeLen);
  float* qVal = (float*) memalloc((pLen + 1) * sizeof(float));
  qVal[pLen] = FLT_MAX;
  for (int64_t i = pLen - 1; i > -1; i--) {
    // ensure monotonicity
    qVal[i] = MAX( MIN( pVal[i] + logN + log10f(k),
      qVal[i + 1]), 0.0f);
    k += pEnd[i];
  }

  // save pileups of q-values for each chrom
  for (int i = 0; i < chromLen; i++) {
    Chrom* chr = chrom + i;
    if (chr->skip || chr->pval[n] == NULL)
      continue;
    for (uint32_t j = 0; j < chr->pvalLen[n]; j++)
      if (chr->pval[n]->cov[j] == SKIP)
        chr->qval->cov[j] = SKIP; // skipped region
      else
        chr->qval->cov[j] = lookup(pVal, 0, pLen,
          qVal, chr->pval[n]->cov[j]);
  }

  // check if all q-values are 1
  if (verbose && qVal[pLen-1] == 0.0f)
    fprintf(stderr, "Warning! All q-values are 1\n");

  // free memory
  free(qVal);
}

// Assembly:
subq $0xa8, %rsp
movb 0xb8(%rsp), %al
movq 0xb0(%rsp), %r10
movq %rdi, 0xa0(%rsp)
movl %esi, 0x9c(%rsp)
movl %edx, 0x98(%rsp)
movq %rcx, 0x90(%rsp)
movq %r8, 0x88(%rsp)
movq %r9, 0x80(%rsp)
andb $0x1, %al
movb %al, 0x7f(%rsp)
movq 0x88(%rsp), %rdi
movq 0x80(%rsp), %rsi
movq 0xb0(%rsp), %rcx
decq %rcx
xorl %eax, %eax
movl %eax, %edx
callq 0x2c40
movq $0x1, 0x70(%rsp)
movq 0x90(%rsp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x3c(%rsp)
testq %rax, %rax
movss %xmm0, 0x40(%rsp)
js 0x2e78
movss 0x3c(%rsp), %xmm0
movss %xmm0, 0x40(%rsp)
movss 0x40(%rsp), %xmm0
callq 0x21d0
movd %xmm0, %eax
xorl $0x80000000, %eax       # imm = 0x80000000
movd %eax, %xmm0
movss %xmm0, 0x6c(%rsp)
movq 0xb0(%rsp), %rdi
addq $0x1, %rdi
shlq $0x2, %rdi
callq 0x2890
movq %rax, 0x60(%rsp)
movq 0x60(%rsp), %rax
movq 0xb0(%rsp), %rcx
movss 0x1b2cb(%rip), %xmm0    # 0x1e190
movss %xmm0, (%rax,%rcx,4)
movq 0xb0(%rsp), %rax
subq $0x1, %rax
movq %rax, 0x58(%rsp)
cmpq $-0x1, 0x58(%rsp)
jle 0x319a
movq 0x88(%rsp), %rax
movq 0x58(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x6c(%rsp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x30(%rsp)
movq 0x70(%rsp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x34(%rsp)
testq %rax, %rax
movss %xmm0, 0x38(%rsp)
js 0x2f47
movss 0x34(%rsp), %xmm0
movss %xmm0, 0x38(%rsp)
movss 0x38(%rsp), %xmm0
callq 0x21d0
movss 0x30(%rsp), %xmm1
addss %xmm0, %xmm1
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movss 0x4(%rax,%rcx,4), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x2ff5
movq 0x88(%rsp), %rax
movq 0x58(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x6c(%rsp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x24(%rsp)
movq 0x70(%rsp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x28(%rsp)
testq %rax, %rax
movss %xmm0, 0x2c(%rsp)
js 0x2fd5
movss 0x28(%rsp), %xmm0
movss %xmm0, 0x2c(%rsp)
movss 0x2c(%rsp), %xmm0
callq 0x21d0
movaps %xmm0, %xmm1
movss 0x24(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x20(%rsp)
jmp 0x300b
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movss 0x4(%rax,%rcx,4), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x314e
movq 0x88(%rsp), %rax
movq 0x58(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x6c(%rsp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x14(%rsp)
movq 0x70(%rsp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0x18(%rsp)
testq %rax, %rax
movss %xmm0, 0x1c(%rsp)
js 0x307d
movss 0x18(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movss 0x1c(%rsp), %xmm0
callq 0x21d0
movss 0x14(%rsp), %xmm1
addss %xmm0, %xmm1
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movss 0x4(%rax,%rcx,4), %xmm0
ucomiss %xmm1, %xmm0
jbe 0x312b
movq 0x88(%rsp), %rax
movq 0x58(%rsp), %rcx
movss (%rax,%rcx,4), %xmm0
movss 0x6c(%rsp), %xmm1
addss %xmm1, %xmm0
movss %xmm0, 0x8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, %rdx
shrq %rdx
movl %eax, %ecx
andl $0x1, %ecx
orq %rdx, %rcx
cvtsi2ss %rcx, %xmm0
addss %xmm0, %xmm0
cvtsi2ss %rax, %xmm1
movss %xmm1, 0xc(%rsp)
testq %rax, %rax
movss %xmm0, 0x10(%rsp)
js 0x310b
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x10(%rsp), %xmm0
callq 0x21d0
movaps %xmm0, %xmm1
movss 0x8(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x4(%rsp)
jmp 0x3141
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movss 0x4(%rax,%rcx,4), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rsp)
jmp 0x3158
xorps %xmm0, %xmm0
movss %xmm0, (%rsp)
jmp 0x3158
movss (%rsp), %xmm0
movq 0x60(%rsp), %rax
movq 0x58(%rsp), %rcx
movss %xmm0, (%rax,%rcx,4)
movq 0x80(%rsp), %rax
movq 0x58(%rsp), %rcx
movq (%rax,%rcx,8), %rax
addq 0x70(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x58(%rsp), %rax
addq $-0x1, %rax
movq %rax, 0x58(%rsp)
jmp 0x2edb
movl $0x0, 0x54(%rsp)
movl 0x54(%rsp), %eax
cmpl 0x9c(%rsp), %eax
jge 0x32e5
movq 0xa0(%rsp), %rax
movslq 0x54(%rsp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x48(%rsp)
movq 0x48(%rsp), %rax
testb $0x1, 0xc(%rax)
jne 0x31ef
movq 0x48(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x98(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x31f4
jmp 0x32d5
movl $0x0, 0x44(%rsp)
movl 0x44(%rsp), %eax
movq 0x48(%rsp), %rcx
movq 0x50(%rcx), %rcx
movslq 0x98(%rsp), %rdx
cmpl (%rcx,%rdx,4), %eax
jae 0x32d3
movq 0x48(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x98(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
movl 0x44(%rsp), %ecx
movss (%rax,%rcx,4), %xmm0
movss 0x1af50(%rip), %xmm1    # 0x1e194
ucomiss %xmm1, %xmm0
jne 0x326b
jp 0x326b
movq 0x48(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rax
movl 0x44(%rsp), %ecx
movss 0x1af30(%rip), %xmm0    # 0x1e194
movss %xmm0, (%rax,%rcx,4)
jmp 0x32c1
movq 0x88(%rsp), %rdi
movq 0xb0(%rsp), %rdx
movq 0x60(%rsp), %rcx
movq 0x48(%rsp), %rax
movq 0x48(%rax), %rax
movslq 0x98(%rsp), %rsi
movq (%rax,%rsi,8), %rax
movq 0x8(%rax), %rax
movl 0x44(%rsp), %esi
movss (%rax,%rsi,4), %xmm0
xorl %eax, %eax
movl %eax, %esi
callq 0x2cc0
movq 0x48(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x8(%rax), %rax
movl 0x44(%rsp), %ecx
movss %xmm0, (%rax,%rcx,4)
jmp 0x32c3
movl 0x44(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x44(%rsp)
jmp 0x31fc
jmp 0x32d5
movl 0x54(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x54(%rsp)
jmp 0x31a2
testb $0x1, 0x7f(%rsp)
je 0x3324
movq 0x60(%rsp), %rax
movq 0xb0(%rsp), %rcx
subq $0x1, %rcx
movss (%rax,%rcx,4), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0x3324
jp 0x3324
movq 0x1fce5(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0x1c254(%rip), %rsi     # 0x1f571
movb $0x0, %al
callq 0x21c0
movq 0x60(%rsp), %rdi
callq 0x2040
addq $0xa8, %rsp
retq
nopw %cs:(%rax,%rax)