// File: /workspace/github_c_makefile_star2_O1/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:
testl %esi, %esi
jle 0x4a75
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %r8d
movq %rdi, %rbx
movl %edx, %r14d
leal 0x1(%r8), %eax
movslq %eax, %rcx
leaq (,%rcx,8), %rdx
movq %rdx, -0x48(%rbp)
movslq %r8d, %rdx
movq %rdx, -0x40(%rbp)
shlq $0x2, %rcx
movq %rcx, -0x68(%rbp)
movl %esi, %r12d
xorl %r13d, %r13d
leaq 0xf(,%rax,4), %rcx
shlq $0x2, %rax
movq %rax, -0x50(%rbp)
andq $-0x10, %rcx
movq %rcx, -0x58(%rbp)
movq %r8, -0x38(%rbp)
movq %rdi, -0x70(%rbp)
movq %r14, -0x88(%rbp)
movq %r12, -0x60(%rbp)
imulq $0x68, %r13, %r15
cmpb $0x0, 0xc(%rbx,%r15)
jne 0x4a5b
addq %rbx, %r15
testl %r8d, %r8d
jle 0x48bc
movq 0x48(%r15), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx,%rax,8)
jne 0x48be
incq %rax
cmpq %rax, %r14
jne 0x48a8
movl %r14d, %eax
jmp 0x48be
xorl %eax, %eax
cmpl %r8d, %eax
jne 0x48e9
movq 0x48(%r15), %rdi
movq -0x48(%rbp), %rsi
callq 0x3915
movq -0x38(%rbp), %r8
movq %rax, 0x48(%r15)
movq -0x40(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
jmp 0x4a5b
movq %r13, -0x80(%rbp)
movq %r15, %rdi
movq %r15, -0x30(%rbp)
movl %r8d, %esi
callq 0x475c
movl %eax, %r15d
movq -0x30(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x3915
movq -0x30(%rbp), %rcx
movq %rax, 0x48(%rcx)
movl $0x10, %edi
callq 0x3903
movq -0x30(%rbp), %rcx
movq 0x48(%rcx), %rcx
movq -0x40(%rbp), %rbx
movq %rax, (%rcx,%rbx,8)
movl %r15d, %r12d
shlq $0x2, %r12
movq %r12, %rdi
callq 0x3903
movq -0x30(%rbp), %rcx
movq 0x48(%rcx), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, (%rcx)
movq %r12, %rdi
callq 0x3903
movq -0x30(%rbp), %rcx
movq 0x48(%rcx), %rcx
movq (%rcx,%rbx,8), %rcx
movq %rax, 0x8(%rcx)
movq -0x30(%rbp), %rax
movq 0x50(%rax), %rdi
movq -0x68(%rbp), %rsi
callq 0x3915
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %r8
movq %rsp, -0x78(%rbp)
movq %rax, 0x50(%rsi)
movl %r15d, (%rax,%rbx,4)
incb 0x58(%rsi)
movq %rsp, %r12
subq -0x58(%rbp), %r12
movq %r12, %rsp
testl %r8d, %r8d
js 0x49b5
movq %r12, %rdi
xorl %esi, %esi
movq -0x50(%rbp), %rdx
callq 0x2140
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %r8
cmpl $0x0, 0x8(%rsi)
je 0x4a4b
movl $0x1, %ebx
testl %r8d, %r8d
jle 0x4a40
xorl %r13d, %r13d
xorl %eax, %eax
movq 0x48(%rsi), %rdi
movq (%rdi,%r13,8), %rcx
testq %rcx, %rcx
je 0x4a38
movq (%rcx), %rcx
movl (%r12,%r13,4), %edx
cmpl %ebx, (%rcx,%rdx,4)
jne 0x4a38
testb $0x1, %al
jne 0x4a34
movq -0x40(%rbp), %r15
movq (%rdi,%r15,8), %rax
movq (%rax), %rax
movl (%r12,%r15,4), %r14d
movl %ebx, (%rax,%r14,4)
movl %r8d, %esi
movq %r12, %rdx
callq 0x46bf
movq -0x30(%rbp), %rsi
movq -0x38(%rbp), %r8
movq 0x48(%rsi), %rax
movq (%rax,%r15,8), %rax
movq 0x8(%rax), %rax
movss %xmm0, (%rax,%r14,4)
leal 0x1(%r14), %eax
movq -0x88(%rbp), %r14
movl %eax, (%r12,%r15,4)
movb $0x1, %al
incl (%r12,%r13,4)
incq %r13
cmpq %r13, %r14
jne 0x49ce
incl %ebx
cmpl 0x8(%rsi), %ebx
jbe 0x49c4
movq -0x78(%rbp), %rsp
movq -0x70(%rbp), %rbx
movq -0x60(%rbp), %r12
movq -0x80(%rbp), %r13
incq %r13
cmpq %r12, %r13
jne 0x488a
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq