// File: /workspace/github_c_makefile_star2_O0/jsh58[P]Genrich/Genrich.c
// Function: combinePval
void combinePval(Chrom* chrom, int chromLen, int n) {

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

    // make sure at least one pval array exists
    int j;
    for (j = 0; j < n; j++)
      if (chr->pval[j] != NULL)
        break;
    if (j == n) {
      // none exists: append another NULL
      chr->pval = (Pileup**) memrealloc(chr->pval,
        (n + 1) * sizeof(Pileup*));
      chr->pval[n] = NULL;
      continue;
    }

    // create additional 'pileup' array for combined p-values
    uint32_t num = countIntervals2(chr, n);
    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 combined p-values
    uint32_t idx[n + 1];  // indexes into each pval array
    for (int j = 0; j <= n; j++)
      idx[j] = 0;
    for (uint32_t k = 1; k <= chr->len; k++) {
      bool add = false;
      for (int j = 0; j < n; j++)
        if (chr->pval[j] != NULL
            && chr->pval[j]->end[idx[j]] == k) {
          if (! add) {
            chr->pval[n]->end[idx[n]] = k;
            chr->pval[n]->cov[idx[n]]
              = multPval(chr->pval, n, idx);
            idx[n]++;
            add = true;
          }
          idx[j]++;
        }

    }

  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x4a1f
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
testb $0x1, 0xc(%rax)
je 0x4757
jmp 0x4a11
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x4788
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x24(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x477b
jmp 0x4788
jmp 0x477d
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x475e
movl -0x24(%rbp), %eax
cmpl -0x10(%rbp), %eax
jne 0x47ce
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl -0x10(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x3, %rsi
callq 0x28e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x10(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x4a11
movq -0x20(%rbp), %rdi
movl -0x10(%rbp), %esi
callq 0x45f0
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movslq -0x10(%rbp), %rax
leaq 0x8(,%rax,8), %rsi
callq 0x28e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x48(%rax)
movl $0x10, %edi
callq 0x2890
movq %rax, %rdx
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x10(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x28(%rbp), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x2890
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x10(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, (%rax)
movl -0x28(%rbp), %eax
movl %eax, %edi
shlq $0x2, %rdi
callq 0x2890
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x10(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq %rcx, 0x8(%rax)
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rdi
movslq -0x10(%rbp), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x28e0
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x50(%rax)
movl -0x28(%rbp), %edx
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x10(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
movb 0x58(%rax), %cl
incb %cl
movb %cl, 0x58(%rax)
movl -0x10(%rbp), %eax
incl %eax
movq %rsp, %rcx
movq %rcx, -0x30(%rbp)
leaq 0xf(,%rax,4), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x50(%rbp)
movq %rcx, %rsp
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x48fb
movq -0x50(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x48d9
movl $0x1, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x4a0a
movb $0x0, -0x41(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x49fa
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x48(%rbp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x49ea
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x48(%rbp), %rdx
movq (%rax,%rdx,8), %rax
movq (%rax), %rax
movslq -0x48(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x40(%rbp), %eax
jne 0x49ea
testb $0x1, -0x41(%rbp)
jne 0x49d9
movq -0x50(%rbp), %rdx
movl -0x40(%rbp), %esi
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x10(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movslq -0x10(%rbp), %rcx
movl (%rdx,%rcx,4), %ecx
movl %esi, (%rax,%rcx,4)
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rdi
movl -0x10(%rbp), %esi
callq 0x4460
movq -0x50(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x48(%rcx), %rcx
movslq -0x10(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x8(%rcx), %rcx
movslq -0x10(%rbp), %rdx
movl (%rax,%rdx,4), %edx
movss %xmm0, (%rcx,%rdx,4)
movslq -0x10(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movb $0x1, -0x41(%rbp)
movq -0x50(%rbp), %rax
movslq -0x48(%rbp), %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
jmp 0x49ec
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x491d
jmp 0x49fc
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x4902
movq -0x30(%rbp), %rax
movq %rax, %rsp
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x4729
movq %rbp, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)