// File: /workspace/github_c_makefile_star2_O1/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, 0x20(%rsp)
movl %edx, 0x8(%rsp)
movl %esi, %ebp
movq %rdi, 0x30(%rsp)
movzbl 0xa8(%rsp), %eax
movl %eax, 0xc(%rsp)
movl %r8d, 0x10(%rsp)
testl %r8d, %r8d
je 0x7508
movq 0xa0(%rsp), %rdx
movq 0x20(%rsp), %rdi
movq %r9, %rsi
movl 0xc(%rsp), %ecx
callq 0x736b
testl %ebp, %ebp
jle 0x77d8
movl 0x8(%rsp), %eax
movl %eax, %ecx
movq %rcx, 0x38(%rsp)
leaq (,%rcx,8), %rcx
movq %rcx, 0x48(%rsp)
cltq
leaq 0x8(,%rax,8), %rcx
movq %rcx, 0x28(%rsp)
movq %rax, 0x18(%rsp)
leaq 0x4(,%rax,4), %rax
movq %rax, 0x40(%rsp)
movl %ebp, %eax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movq %rax, 0x58(%rsp)
imulq $0x68, %rax, %r13
movq 0x30(%rsp), %rax
cmpb $0x0, 0xc(%rax,%r13)
jne 0x77c5
addq 0x30(%rsp), %r13
movzbl 0x58(%r13), %eax
cmpl 0x8(%rsp), %eax
jge 0x75bb
movq 0x48(%r13), %rdi
movq 0x48(%rsp), %rsi
callq 0x3915
movq %rax, 0x48(%r13)
movzbl 0x58(%r13), %eax
cmpl 0x8(%rsp), %eax
jge 0x75b3
movq 0x38(%rsp), %rcx
movq 0x48(%r13), %rdx
movq $0x0, -0x8(%rdx,%rcx,8)
decq %rcx
cmpq %rax, %rcx
jg 0x759e
movl 0x8(%rsp), %eax
movb %al, 0x58(%r13)
cmpb $0x0, 0xd(%r13)
je 0x77a2
movq %r13, %rdi
callq 0x72e3
movl %eax, %ebp
movq 0x48(%r13), %rdi
movq 0x28(%rsp), %rsi
callq 0x3915
movq %rax, 0x48(%r13)
movl $0x10, %edi
callq 0x3903
movq 0x48(%r13), %rcx
movq 0x18(%rsp), %rbx
movq %rax, (%rcx,%rbx,8)
movl %ebp, %eax
movq %rax, 0x60(%rsp)
leaq (,%rax,4), %r15
movq %r15, %rdi
callq 0x3903
movq 0x48(%r13), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, (%rcx)
movq %r15, %rdi
callq 0x3903
movq 0x48(%r13), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, 0x8(%rcx)
movq 0x50(%r13), %rdi
movq 0x40(%rsp), %rsi
callq 0x3915
movq %rax, 0x50(%r13)
movl %ebp, (%rax,%rbx,4)
incb 0x58(%r13)
testl %ebp, %ebp
je 0x77c5
movq 0x48(%r13), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %r15
xorl %ebx, %ebx
xorl %r14d, %r14d
xorl %edi, %edi
xorl %ebp, %ebp
movq 0x28(%r13), %rcx
movq 0x38(%r13), %rax
movq (%rax), %rdx
movl %r14d, %r14d
movl (%rdx,%r14,4), %edx
movq (%rcx), %rsi
movl %edi, 0x14(%rsp)
movl %edi, %r12d
movl (%rsi,%r12,4), %esi
movq (%r15), %rdi
cmpl %esi, %edx
jae 0x76ff
movl %edx, (%rdi,%rbx,4)
movq 0x8(%rcx), %rcx
movss (%rcx,%r12,4), %xmm0
movq 0x8(%rax), %rax
movss (%rax,%r14,4), %xmm1
callq 0x71bd
movq 0x8(%r15), %rax
movss %xmm0, (%rax,%rbx,4)
cmpb $0x0, 0x10(%rsp)
je 0x76f3
movaps %xmm0, %xmm2
movq (%r15), %rax
movl (%rax,%rbx,4), %ecx
movq (%r13), %rsi
movq 0x28(%r13), %rax
movq 0x8(%rax), %rax
movss (%rax,%r12,4), %xmm0
movq 0x38(%r13), %rax
movq 0x8(%rax), %rax
movss (%rax,%r14,4), %xmm1
movq 0x20(%rsp), %rdi
movl %ebp, %edx
movl 0xc(%rsp), %r8d
callq 0x742d
incl %r14d
movl 0x14(%rsp), %edi
jmp 0x778c
movl %esi, (%rdi,%rbx,4)
movq 0x8(%rcx), %rcx
movss (%rcx,%r12,4), %xmm0
movq 0x8(%rax), %rax
movss (%rax,%r14,4), %xmm1
callq 0x71bd
movq 0x8(%r15), %rax
movss %xmm0, (%rax,%rbx,4)
cmpb $0x0, 0x10(%rsp)
je 0x7765
movaps %xmm0, %xmm2
movq (%r15), %rax
movl (%rax,%rbx,4), %ecx
movq (%r13), %rsi
movq 0x28(%r13), %rax
movq 0x8(%rax), %rax
movss (%rax,%r12,4), %xmm0
movq 0x38(%r13), %rax
movq 0x8(%rax), %rax
movss (%rax,%r14,4), %xmm1
movq 0x20(%rsp), %rdi
movl %ebp, %edx
movl 0xc(%rsp), %r8d
callq 0x742d
movq 0x28(%r13), %rax
movq 0x38(%r13), %rcx
movq (%rcx), %rcx
movl (%rcx,%r14,4), %ecx
movq (%rax), %rax
xorl %edx, %edx
cmpl (%rax,%r12,4), %ecx
sete %dl
addl %r14d, %edx
movl 0x14(%rsp), %edi
incl %edi
movl %edx, %r14d
movq (%r15), %rax
movl (%rax,%rbx,4), %ebp
incq %rbx
cmpq %rbx, 0x60(%rsp)
jne 0x7666
jmp 0x77c5
movq 0x48(%r13), %rdi
movq 0x28(%rsp), %rsi
callq 0x3915
movq %rax, 0x48(%r13)
movq 0x18(%rsp), %rcx
movq $0x0, (%rax,%rcx,8)
incb 0x58(%r13)
movq 0x58(%rsp), %rax
incq %rax
cmpq 0x50(%rsp), %rax
jne 0x7552
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq