// File: /workspace/github_c_makefile_star2_O2/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 $0xc8, %rsp
movl %r9d, 0x18(%rsp)
movl %r8d, %r14d
movl %ecx, 0x1c(%rsp)
movq %rdx, 0x20(%rsp)
movl %esi, %r15d
movq %rdi, %r12
movslq %r8d, %rcx
xorl %r13d, %r13d
testl %esi, %esi
movl $0x0, %eax
cmovgl %esi, %eax
imulq $0x68, %rax, %rbp
movq %rcx, 0x8(%rsp)
cmpq %r13, %rbp
je 0x2ed5
cmpb $0x0, 0xc(%r12,%r13)
jne 0x2ecf
movq 0x48(%r12,%r13), %rax
cmpq $0x0, (%rax,%rcx,8)
je 0x2ecf
movq 0x50(%r12,%r13), %rax
movl (%rax,%rcx,4), %ebx
pushq $0x10
popq %rdi
callq 0x2752
movq %rax, 0x60(%r12,%r13)
shlq $0x2, %rbx
movq %rbx, %rdi
callq 0x2752
movq 0x60(%r12,%r13), %rcx
movq %rax, (%rcx)
movq %rbx, %rdi
callq 0x2752
movq 0x60(%r12,%r13), %rcx
movq %rax, 0x8(%rcx)
movq 0x8(%rsp), %rcx
addq $0x68, %r13
jmp 0x2e77
leaq 0x38(%rsp), %rbx
andq $0x0, (%rbx)
movq %r12, %rdi
movl %r15d, 0x8(%rsp)
movl %r15d, %esi
movl %r14d, %edx
movq %rbx, %rcx
movl %r14d, 0x14(%rsp)
callq 0x2cd5
movq %rax, %r14
movq (%rbx), %r13
leaq (,%r13,8), %rdi
callq 0x2752
movq %rax, %rbx
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
leaq 0x28(%rsp), %r15
andq $0x0, (%r15)
movq %r14, %rdi
movq %r13, %rdx
movq %r15, %rcx
callq 0x2daf
movq %rax, %rbp
movq (%r15), %rcx
movq 0x20(%rsp), %r8
cmpq %r8, %rcx
setne %al
testb %al, 0x1c(%rsp)
jne 0x2fb8
movzbl 0x18(%rsp), %eax
movq %r12, %rdi
movl 0x8(%rsp), %esi
movl 0x14(%rsp), %edx
movq %r8, %rcx
movq %rbp, %r8
movq %rbx, %r9
pushq %rax
pushq %r13
callq 0x2973
popq %rax
popq %rcx
movq %rbx, %rdi
callq 0x2040
movq %rbp, %rdi
callq 0x2040
xorl %ebx, %ebx
cmpq $0x13fed1, %rbx         # imm = 0x13FED1
je 0x2f9f
movq (%r14,%rbx,8), %rdi
testq %rdi, %rdi
je 0x2f9a
movq 0x10(%rdi), %r15
callq 0x2040
movq %r15, %rdi
jmp 0x2f87
incq %rbx
jmp 0x2f7a
movq %r14, %rdi
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x2040
leaq 0xe39f(%rip), %rsi      # 0x1135e
leaq 0x40(%rsp), %rbx
movq %rbx, %rdi
movq %r8, %rdx
xorl %eax, %eax
callq 0x2290
pushq $0x21
popq %rsi
movq %rbx, %rdi
callq 0x2724
pushq $0x1
popq %rdi
callq 0x22a0