// File: /workspace/github_c_makefile_star2_O2/jsh58[P]Genrich/Genrich.c
// Function: savePval
void savePval(Chrom* chrom, int chromLen, int n,
    File pile, bool pileOpt, char* exptName,
    char* ctrlName, bool gzOut) {

  // print log header
  if (pileOpt)
    printPileHeader(pile, exptName, ctrlName, gzOut);

  // create pileups for each chrom
  for (int i = 0; i < chromLen; i++) {
    Chrom* chr = chrom + i;
    if (chr->skip)
      continue;

    // fill in missing pval arrays from previous samples
    if (chr->sample < n) {
      chr->pval = (Pileup**) memrealloc(chr->pval,
        n * sizeof(Pileup*));
      for (int j = n - 1; j >= chr->sample; j--)
        chr->pval[j] = NULL;
      chr->sample = n;
    }

    // p-values not to be saved: append a NULL
    if (! chr->save) {
      chr->pval = (Pileup**) memrealloc(chr->pval,
        (n + 1) * sizeof(Pileup*));
      chr->pval[n] = NULL;
      chr->sample++;
      continue;
    }

    // create 'pileup' arrays for p-values
    uint32_t num = countIntervals(chr);
    chr->pval = (Pileup**) memrealloc(chr->pval,
      (n + 1) * sizeof(Pileup*));
    chr->pval[n] = (Pileup*) memalloc(sizeof(Pileup));
    chr->pval[n]->end = (uint32_t*) memalloc(num * sizeof(uint32_t));
    chr->pval[n]->cov = (float*) memalloc(num * sizeof(float));
    chr->pvalLen = (uint32_t*) memrealloc(chr->pvalLen,
      (n + 1) * sizeof(uint32_t));
    chr->pvalLen[n] = num;
    chr->sample++;

    // save p-values to arrays
    Pileup* p = chr->pval[n];
    uint32_t start = 0;    // start of interval
    uint32_t j = 0, k = 0;
    for (uint32_t m = 0; m < num; m++) {
      if (chr->ctrl->end[k] < chr->expt->end[j]) {
        p->end[m] = chr->ctrl->end[k];
        p->cov[m] = calcPval(chr->expt->cov[j],
          chr->ctrl->cov[k]);
        if (pileOpt)
          printPile(pile, chr->name, start, p->end[m],
            chr->expt->cov[j], chr->ctrl->cov[k],
            p->cov[m], gzOut);
        k++;
      } else {
        p->end[m] = chr->expt->end[j];
        p->cov[m] = calcPval(chr->expt->cov[j],
          chr->ctrl->cov[k]);
        if (pileOpt)
          printPile(pile, chr->name, start, p->end[m],
            chr->expt->cov[j], chr->ctrl->cov[k],
            p->cov[m], gzOut);
        if (chr->ctrl->end[k] == chr->expt->end[j])
          k++;
        j++;
      }
      start = p->end[m];
    }

  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rcx, 0x18(%rsp)
movl %edx, 0x4(%rsp)
movl %esi, %ebx
movq %rdi, 0x30(%rsp)
movzbl 0xa8(%rsp), %eax
movl %eax, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
testl %r8d, %r8d
je 0x606a
movq 0xa0(%rsp), %rdx
movq 0x18(%rsp), %rdi
movq %r9, %rsi
movl 0x8(%rsp), %ecx
callq 0x5ed1
movl 0x4(%rsp), %eax
movl %eax, %ecx
movq %rcx, 0x48(%rsp)
leaq (,%rcx,8), %rcx
movq %rcx, 0x40(%rsp)
cltq
leaq 0x8(,%rax,8), %rcx
movq %rcx, 0x20(%rsp)
movq %rax, 0x28(%rsp)
leaq 0x4(,%rax,4), %rax
movq %rax, 0x38(%rsp)
xorl %eax, %eax
testl %ebx, %ebx
cmovlel %eax, %ebx
movq %rbx, 0x50(%rsp)
cmpq 0x50(%rsp), %rax
je 0x632c
movq %rax, 0x58(%rsp)
imulq $0x68, %rax, %rbp
movq 0x30(%rsp), %rax
cmpb $0x0, 0xc(%rax,%rbp)
jne 0x631f
addq 0x30(%rsp), %rbp
movzbl 0x58(%rbp), %eax
cmpl 0x4(%rsp), %eax
jge 0x6117
movq 0x48(%rbp), %rdi
movq 0x40(%rsp), %rsi
callq 0x2776
movq %rax, 0x48(%rbp)
movzbl 0x58(%rbp), %eax
movq 0x48(%rsp), %rcx
cmpl %eax, %ecx
jle 0x6110
movq 0x48(%rbp), %rdx
andq $0x0, -0x8(%rdx,%rcx,8)
decq %rcx
jmp 0x60fd
movl 0x4(%rsp), %eax
movb %al, 0x58(%rbp)
cmpb $0x0, 0xd(%rbp)
je 0x6300
movq %rbp, %rdi
callq 0x5e6f
movl %eax, %r15d
movq 0x48(%rbp), %rdi
movq 0x20(%rsp), %rsi
callq 0x2776
movq %rax, 0x48(%rbp)
pushq $0x10
popq %rdi
callq 0x2752
movq 0x48(%rbp), %rcx
movq 0x28(%rsp), %rbx
movq %rax, (%rcx,%rbx,8)
movl %r15d, %eax
movq %rax, 0x60(%rsp)
leaq (,%rax,4), %r12
movq %r12, %rdi
callq 0x2752
movq 0x48(%rbp), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, (%rcx)
movq %r12, %rdi
callq 0x2752
movq 0x48(%rbp), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, 0x8(%rcx)
movq 0x50(%rbp), %rdi
movq 0x38(%rsp), %rsi
callq 0x2776
movq %rax, 0x50(%rbp)
movl %r15d, (%rax,%rbx,4)
incb 0x58(%rbp)
movq 0x48(%rbp), %rax
movq (%rax,%rbx,8), %r12
xorl %r14d, %r14d
xorl %eax, %eax
xorl %edi, %edi
xorl %r13d, %r13d
cmpq %r14, 0x60(%rsp)
je 0x631f
movl %eax, 0x10(%rsp)
movq 0x28(%rbp), %rcx
movq 0x38(%rbp), %rax
movq (%rax), %rdx
movl %r13d, %ebx
movl (%rdx,%rbx,4), %edx
movq (%rcx), %rsi
movl %edi, 0x14(%rsp)
movl %edi, %r15d
movl (%rsi,%r15,4), %esi
movq (%r12), %rdi
cmpl %esi, %edx
jae 0x6262
movl %edx, (%rdi,%r14,4)
movq 0x8(%rcx), %rcx
movss (%rcx,%r15,4), %xmm0
movq 0x8(%rax), %rax
movss (%rax,%rbx,4), %xmm1
callq 0x5d6b
movq 0x8(%r12), %rax
movss %xmm0, (%rax,%r14,4)
cmpb $0x0, 0xc(%rsp)
je 0x6256
movaps %xmm0, %xmm2
movq (%r12), %rax
movl (%rax,%r14,4), %ecx
movq (%rbp), %rsi
movq 0x28(%rbp), %rax
movq 0x8(%rax), %rax
movss (%rax,%r15,4), %xmm0
movq 0x38(%rbp), %rax
movq 0x8(%rax), %rax
movss (%rax,%rbx,4), %xmm1
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %edx
movl 0x8(%rsp), %r8d
callq 0x5f8f
incl %r13d
movl 0x14(%rsp), %edi
jmp 0x62f0
movl %esi, (%rdi,%r14,4)
movq 0x8(%rcx), %rcx
movss (%rcx,%r15,4), %xmm0
movq 0x8(%rax), %rax
movss (%rax,%rbx,4), %xmm1
callq 0x5d6b
movq 0x8(%r12), %rax
movss %xmm0, (%rax,%r14,4)
cmpb $0x0, 0xc(%rsp)
je 0x62cd
movaps %xmm0, %xmm2
movq (%r12), %rax
movl (%rax,%r14,4), %ecx
movq (%rbp), %rsi
movq 0x28(%rbp), %rax
movq 0x8(%rax), %rax
movss (%rax,%r15,4), %xmm0
movq 0x38(%rbp), %rax
movq 0x8(%rax), %rax
movss (%rax,%rbx,4), %xmm1
movq 0x18(%rsp), %rdi
movl 0x10(%rsp), %edx
movl 0x8(%rsp), %r8d
callq 0x5f8f
movq 0x28(%rbp), %rax
movq 0x38(%rbp), %rcx
movq (%rcx), %rcx
movl (%rcx,%rbx,4), %ecx
movq (%rax), %rax
xorl %edx, %edx
cmpl (%rax,%r15,4), %ecx
sete %dl
addl %edx, %r13d
movl 0x14(%rsp), %edi
incl %edi
movq (%r12), %rax
movl (%rax,%r14,4), %eax
incq %r14
jmp 0x61b5
movq 0x48(%rbp), %rdi
movq 0x20(%rsp), %rsi
callq 0x2776
movq %rax, 0x48(%rbp)
movq 0x28(%rsp), %rcx
andq $0x0, (%rax,%rcx,8)
incb 0x58(%rbp)
movq 0x58(%rsp), %rax
incq %rax
jmp 0x60af
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq