// File: /workspace/github_c_makefile_star2_O3/jsh58[P]Genrich/Genrich.c
// Function: computeQval
void computeQval(Chrom* chrom, int chromLen,
    uint64_t genomeLen, bool genomeOpt, int n,
    bool verbose) {

  // create "pileup" arrays for q-values
  for (int i = 0; i < chromLen; i++) {
    Chrom* chr = chrom + i;
    if (chr->skip || chr->pval[n] == NULL)
      continue;
    uint32_t num = chr->pvalLen[n]; // use last p-value array length
    chr->qval = (Pileup*) memalloc(sizeof(Pileup));
    chr->qval->end = (uint32_t*) memalloc(num * sizeof(uint32_t));
    chr->qval->cov = (float*) memalloc(num * sizeof(float));
  }

  // save all p-values (genome-wide) to hashtable
  int64_t pLen = 0;
  Hash** table = hashPval(chrom, chromLen, n, &pLen);

  // collect p-values from hashtable
  uint64_t* pEnd = memalloc(pLen * sizeof(uint64_t));
  uint64_t checkLen = 0;  // should match genomeLen
  float* pVal = collectPval(table, &pEnd, pLen, &checkLen);

  // check that collected p-value lengths match genomeLen
  if (genomeOpt && checkLen != genomeLen) {
    char msg[MAX_ALNS];
    sprintf(msg, "Genome length (%ld) does not match p-value length (%ld)",
      genomeLen, checkLen);
    exit(error(msg, ERRISSUE));
  }

  // convert p-values to q-values
  saveQval(chrom, chromLen, n, genomeLen, pVal, pEnd,
    pLen, verbose);

  // free memory
  free(pEnd);
  free(pVal);
  for (int i = 0; i < HASH_SIZE; i++) {
    Hash* tmp;
    Hash* h = table[i];
    while (h != NULL) {
      tmp = h->next;
      free(h);
      h = tmp;
    }
  }
  free(table);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movl %r9d, 0x8(%rsp)
movl %r8d, (%rsp)
movl %ecx, 0xc(%rsp)
movq %rdx, 0x10(%rsp)
movq %rdi, %r12
testl %esi, %esi
jle 0x409c
movslq (%rsp), %r14
movl %esi, %eax
imulq $0x68, %rax, %r15
xorl %r13d, %r13d
cmpb $0x0, 0xc(%r12,%r13)
jne 0x4093
movq 0x48(%r12,%r13), %rax
cmpq $0x0, (%rax,%r14,8)
je 0x4093
movq 0x50(%r12,%r13), %rax
movl (%rax,%r14,4), %ebx
movl $0x10, %edi
movl %esi, %ebp
callq 0x3913
movq %rax, 0x60(%r12,%r13)
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x3913
movq 0x60(%r12,%r13), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x3913
movl %ebp, %esi
movq 0x60(%r12,%r13), %rcx
movq %rax, 0x8(%rcx)
addq $0x68, %r13
cmpq %r13, %r15
jne 0x403e
xorl %ebp, %ebp
leaq 0x28(%rsp), %rbx
movq %rbp, (%rbx)
movq %r12, %rdi
movl %esi, 0x4(%rsp)
movl (%rsp), %edx
movq %rbx, %rcx
callq 0x3eb8
movq %rax, %r14
movq (%rbx), %r13
leaq (,%r13,8), %rdi
callq 0x3913
movq %rax, %rbx
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x18(%rsp), %r15
movq %rbp, (%r15)
movq %r14, %rdi
movq %r13, %rdx
movq %r15, %rcx
callq 0x3f94
movq %rax, %rbp
movq (%r15), %rdx
movq 0x10(%rsp), %rcx
cmpq %rcx, %rdx
setne %al
testb %al, 0xc(%rsp)
jne 0x4175
movzbl 0x8(%rsp), %eax
movq %r12, %rdi
movl 0x4(%rsp), %esi
movl (%rsp), %edx
movq %rbp, %r8
movq %rbx, %r9
pushq %rax
pushq %r13
callq 0x3b05
addq $0x10, %rsp
movq %rbx, %rdi
callq 0x2040
movq %rbp, %rdi
callq 0x2040
xorl %ebx, %ebx
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x4150
movq 0x10(%rdi), %r15
callq 0x2040
movq %r15, %rdi
testq %r15, %r15
jne 0x413f
incq %rbx
cmpq $0x13fed1, %rbx         # imm = 0x13FED1
jne 0x4136
movq %r14, %rdi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
leaq 0x30(%rsp), %rdi
movq %rcx, %rsi
callq 0x2aa9