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

  // create pileup for each chrom
  double fragLen = 0.0;  // weighted fragment length
  for (int i = 0; i < chromLen; i++) {
    Chrom* chr = chrom + i;
    if (chr->skip || ! chr->save)
      continue;

    // if no read coverage, save constant pileup of 0
    if (chr->diff == NULL) {
      saveConst(chr->expt, &chr->exptLen, &chr->exptMem,
        chr->len, 0.0f);
      continue;
    }

    // determine number of pileup intervals
    int bedIdx = 0;     // index into chr->bed array
    uint32_t bedPos = bedIdx < chr->bedLen ?
      chr->bed[bedIdx] : chr->len + 1;  // position of BED interval
    bool save = true;
    if (bedPos == 0) {
      // first BED interval starts at 0 (should be skipped)
      save = false;
      bedIdx++;
      bedPos = bedIdx < chr->bedLen ?
        chr->bed[bedIdx] : chr->len + 1;
    }
    Diff* d = chr->diff;
    uint32_t num = 1;   // number of intervals
    for (uint32_t j = 1; j < chr->len; j++)
      if (j == bedPos) {
        num++;
        save = ! save;
        bedIdx++;
        bedPos = bedIdx < chr->bedLen ?
          chr->bed[bedIdx] : chr->len + 1;
      } else if (save && (d->cov[j] || d->frac[j]))
        num++;

    // expand pileup arrays (if necessary)
    if (num > chr->exptMem) {
      chr->expt->end = (uint32_t*) memrealloc(chr->expt->end,
        num * sizeof(uint32_t));
      chr->expt->cov = (float*) memrealloc(chr->expt->cov,
        num * sizeof(float));
      chr->exptMem = num;
    }
    chr->exptLen = num;

    // reset BED interval values
    bedIdx = 0; // index into chr->bed array
    bedPos = bedIdx < chr->bedLen ?
      chr->bed[bedIdx] : chr->len + 1;
    save = true;
    if (bedPos == 0) {
      save = false;
      bedIdx++;
      bedPos = bedIdx < chr->bedLen ?
        chr->bed[bedIdx] : chr->len + 1;
    }

    // initialize pileup values
    int32_t cov = 0;      // current pileup value
    uint8_t frac = 0;     // current pileup value (fraction part)
    float val = updateVal(d->cov[0], d->frac[0], &cov, &frac);

    // save pileup values along the chrom
    uint32_t start = 0;   // beginning coordinate of interval
    uint32_t pos = 0;     // position in pileup arrays
    uint32_t j;
    for (j = 1; j < chr->len; j++) {

      if (j == bedPos || (save && (d->cov[j] || d->frac[j]))) {
        // save end of interval and pileup value
        chr->expt->end[pos] = j;
        if (save) {
          chr->expt->cov[pos] = val;
          fragLen += (j - start) * val; // frag. length weighted by val
        } else
          chr->expt->cov[pos] = 0.0f;
        pos++;
        start = j;
      }

      // update pileup value
      if (d->cov[j] || d->frac[j])
        val = updateVal(d->cov[j], d->frac[j], &cov, &frac);

      // update 'save' status (from BED intervals)
      if (j == bedPos) {
        save = ! save;
        bedIdx++;
        bedPos = bedIdx < chr->bedLen ?
          chr->bed[bedIdx] : chr->len + 1;
      }

    }

    // save final interval
    chr->expt->end[pos] = j;
    if (save) {
      chr->expt->cov[pos] = val;
      fragLen += (j - start) * val;
    } else
      chr->expt->cov[pos] = 0.0f;

    // verify array length
    if (pos + 1 != chr->exptLen) {
      char msg[MAX_ALNS];
      sprintf(msg, "%s (%s)", errMsg[ERRARR], chr->name);
      exit(error(msg, ERRISSUE));
    }

    // check for val error (should end at 0)
    val = updateVal(d->cov[j], d->frac[j], &cov, &frac);
    if (val) {
      char msg[MAX_ALNS];
      sprintf(msg, "Experimental pileup for ref %s finishes at %f (not 0.0)",
        chr->name, val);
      exit(error(msg, ERRISSUE));
    }
  }

  if (fragLen == 0.0)
    exit(error("", ERREXPT));
  return fragLen;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movl %esi, 0x17c(%rsp)
xorps %xmm0, %xmm0
movsd %xmm0, 0x170(%rsp)
movl $0x0, 0x16c(%rsp)
movl 0x16c(%rsp), %eax
cmpl 0x17c(%rsp), %eax
jge 0xacf6
movq 0x180(%rsp), %rax
movslq 0x16c(%rsp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
testb $0x1, 0xc(%rax)
jne 0xa49c
movq 0x160(%rsp), %rax
testb $0x1, 0xd(%rax)
jne 0xa4a1
jmp 0xace0
movq 0x160(%rsp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xa4ec
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rdi
movq 0x160(%rsp), %rsi
addq $0x30, %rsi
movq 0x160(%rsp), %rdx
addq $0x34, %rdx
movq 0x160(%rsp), %rax
movl 0x8(%rax), %ecx
xorps %xmm0, %xmm0
callq 0x90d0
jmp 0xace0
movl $0x0, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xa528
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x1c(%rsp)
jmp 0xa53a
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x1c(%rsp)
movl 0x1c(%rsp), %eax
movl %eax, 0x158(%rsp)
movb $0x1, 0x157(%rsp)
cmpl $0x0, 0x158(%rsp)
jne 0xa5be
movb $0x0, 0x157(%rsp)
movl 0x15c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xa5a1
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x18(%rsp)
jmp 0xa5b3
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x158(%rsp)
movq 0x160(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x148(%rsp)
movl $0x1, 0x144(%rsp)
movl $0x1, 0x140(%rsp)
movl 0x140(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xa704
movl 0x140(%rsp), %eax
cmpl 0x158(%rsp), %eax
jne 0xa698
movl 0x144(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x144(%rsp)
movb 0x157(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x157(%rsp)
movl 0x15c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xa679
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
jmp 0xa68b
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x158(%rsp)
jmp 0xa6ec
testb $0x1, 0x157(%rsp)
je 0xa6ea
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x140(%rsp), %ecx
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jne 0xa6d9
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x140(%rsp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xa6ea
movl 0x144(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x144(%rsp)
jmp 0xa6ec
jmp 0xa6ee
movl 0x140(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x140(%rsp)
jmp 0xa5e8
movl 0x144(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x34(%rcx), %eax
jbe 0xa792
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rdi
movl 0x144(%rsp), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x28e0
movq %rax, %rcx
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, (%rax)
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rdi
movl 0x144(%rsp), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x28e0
movq %rax, %rcx
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq %rcx, 0x8(%rax)
movl 0x144(%rsp), %ecx
movq 0x160(%rsp), %rax
movl %ecx, 0x34(%rax)
movl 0x144(%rsp), %ecx
movq 0x160(%rsp), %rax
movl %ecx, 0x30(%rax)
movl $0x0, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xa7e0
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x10(%rsp)
jmp 0xa7f2
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x10(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x158(%rsp)
movb $0x1, 0x157(%rsp)
cmpl $0x0, 0x158(%rsp)
jne 0xa876
movb $0x0, 0x157(%rsp)
movl 0x15c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xa859
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0xc(%rsp)
jmp 0xa86b
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x158(%rsp)
movl $0x0, 0x13c(%rsp)
movb $0x0, 0x13b(%rsp)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movw (%rax), %si
movq 0x148(%rsp), %rax
movq (%rax), %rax
leaq 0x13c(%rsp), %rdx
leaq 0x13b(%rsp), %rcx
movswl %si, %edi
movzbl (%rax), %esi
callq 0x9650
movss %xmm0, 0x134(%rsp)
movl $0x0, 0x130(%rsp)
movl $0x0, 0x12c(%rsp)
movl $0x1, 0x128(%rsp)
movl 0x128(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xab3c
movl 0x128(%rsp), %eax
cmpl 0x158(%rsp), %eax
je 0xa959
testb $0x1, 0x157(%rsp)
je 0xaa1c
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x128(%rsp), %ecx
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jne 0xa959
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x128(%rsp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xaa1c
movl 0x128(%rsp), %edx
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movl 0x12c(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
testb $0x1, 0x157(%rsp)
je 0xa9de
movss 0x134(%rsp), %xmm0
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movl 0x12c(%rsp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl 0x128(%rsp), %eax
movl 0x130(%rsp), %ecx
subl %ecx, %eax
cvtsi2ss %rax, %xmm0
mulss 0x134(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x170(%rsp), %xmm0
movsd %xmm0, 0x170(%rsp)
jmp 0xa9fd
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movl 0x12c(%rsp), %ecx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl 0x12c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x12c(%rsp)
movl 0x128(%rsp), %eax
movl %eax, 0x130(%rsp)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x128(%rsp), %ecx
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jne 0xaa53
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x128(%rsp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xaaa3
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x128(%rsp), %ecx
movw (%rax,%rcx,2), %di
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x128(%rsp), %ecx
movl %ecx, %esi
leaq 0x13c(%rsp), %rdx
leaq 0x13b(%rsp), %rcx
movswl %di, %edi
movzbl (%rax,%rsi), %esi
callq 0x9650
movss %xmm0, 0x134(%rsp)
movl 0x128(%rsp), %eax
cmpl 0x158(%rsp), %eax
jne 0xab24
movb 0x157(%rsp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, 0x157(%rsp)
movl 0x15c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0xab07
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x8(%rsp)
jmp 0xab19
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x158(%rsp)
jmp 0xab26
movl 0x128(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x128(%rsp)
jmp 0xa8e8
movl 0x128(%rsp), %edx
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq (%rax), %rax
movl 0x12c(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
testb $0x1, 0x157(%rsp)
je 0xabc1
movss 0x134(%rsp), %xmm0
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movl 0x12c(%rsp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl 0x128(%rsp), %eax
movl 0x130(%rsp), %ecx
subl %ecx, %eax
cvtsi2ss %rax, %xmm0
mulss 0x134(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
addsd 0x170(%rsp), %xmm0
movsd %xmm0, 0x170(%rsp)
jmp 0xabe0
movq 0x160(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x8(%rax), %rax
movl 0x12c(%rsp), %ecx
xorps %xmm0, %xmm0
movss %xmm0, (%rax,%rcx,4)
movl 0x12c(%rsp), %eax
addl $0x1, %eax
movq 0x160(%rsp), %rcx
cmpl 0x30(%rcx), %eax
je 0xac38
leaq 0xa0(%rsp), %rdi
movq 0x186a2(%rip), %rdx     # 0x232a8
movq 0x160(%rsp), %rax
movq (%rax), %rcx
leaq 0x14e63(%rip), %rsi     # 0x1fa7b
movb $0x0, %al
callq 0x22a0
leaq 0xa0(%rsp), %rdi
movl $0x21, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x128(%rsp), %ecx
movw (%rax,%rcx,2), %di
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x128(%rsp), %ecx
movl %ecx, %esi
leaq 0x13c(%rsp), %rdx
leaq 0x13b(%rsp), %rcx
movswl %di, %edi
movzbl (%rax,%rsi), %esi
callq 0x9650
movss %xmm0, 0x134(%rsp)
movss 0x134(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xac9d
jp 0xac9d
jmp 0xacde
leaq 0x20(%rsp), %rdi
movq 0x160(%rsp), %rax
movq (%rax), %rdx
movss 0x134(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x14df5(%rip), %rsi     # 0x1fab6
movb $0x1, %al
callq 0x22a0
leaq 0x20(%rsp), %rdi
movl $0x21, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
jmp 0xace0
movl 0x16c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x16c(%rsp)
jmp 0xa44d
movsd 0x170(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0xad22
jp 0xad22
leaq 0x15061(%rip), %rdi     # 0x1fd72
movl $0x15, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movsd 0x170(%rsp), %xmm0
addq $0x188, %rsp            # imm = 0x188
retq
nopw %cs:(%rax,%rax)