// File: /workspace/github_c_makefile_star2_O0/jsh58[P]Genrich/Genrich.c
// Function: savePileupCtrl
void savePileupCtrl(Chrom* chrom, int chromLen,
    double fragLen, uint64_t genomeLen, bool verbose) {

  // calculate background lambda value
  float lambda = calcLambda(chrom, chromLen, fragLen, genomeLen);
  if (verbose)
    fprintf(stderr, "  Background pileup value: %f\n", lambda);

  // calculate scale factor (experimental / control)
  float factor = calcFactor(chrom, chromLen, fragLen);
  if (verbose) {
    fprintf(stderr, "  Scaling factor for control pileup: %f\n", factor);
    if (factor > 5.0f)
      fprintf(stderr, "  ** Warning! Large scaling may mask true signal **\n");
  }

  // create pileup for each chrom
  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 lambda
    if (chr->diff == NULL) {
      saveLambda(chr, lambda);
      continue;
    }

    // expand pileup arrays (if necessary)
    //   (chr->ctrlLen already set in calcFactor())
    if (chr->ctrlLen > chr->ctrlMem) {
      chr->ctrl->end = (uint32_t*) memrealloc(chr->ctrl->end,
        chr->ctrlLen * sizeof(uint32_t));
      chr->ctrl->cov = (float*) memrealloc(chr->ctrl->cov,
        chr->ctrlLen * sizeof(float));
      chr->ctrlMem = chr->ctrlLen;
    }

    // initialize BED interval variables
    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;
    }

    // initialize pileup values
    Diff* d = chr->diff;
    int32_t cov = 0;      // current pileup value
    uint8_t frac = 0;     // current pileup value (fraction part)
    float val = factor * updateVal(d->cov[0], d->frac[0],
      &cov, &frac);
    float net = MAX(val, lambda);

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

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

      // determine if interval should be saved
      if (j == bedPos || (save && net != MAX(val, lambda))) {
        chr->ctrl->end[pos] = j;
        chr->ctrl->cov[pos] = save ? net : SKIP;
        pos++;
      }
      net = MAX(val, lambda);

      // 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->ctrl->end[pos] = j;
    chr->ctrl->cov[pos] = save ? net : SKIP;

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

    // 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, "Control pileup for ref %s finishes at %f (not 0.0)",
        chr->name, val);
      exit(error(msg, ERRISSUE));
    }
  }

}

// Assembly:
subq $0x198, %rsp            # imm = 0x198
movb %cl, %al
movq %rdi, 0x190(%rsp)
movl %esi, 0x18c(%rsp)
movsd %xmm0, 0x180(%rsp)
movq %rdx, 0x178(%rsp)
andb $0x1, %al
movb %al, 0x177(%rsp)
movq 0x190(%rsp), %rdi
movl 0x18c(%rsp), %esi
movsd 0x180(%rsp), %xmm0
movq 0x178(%rsp), %rdx
callq 0x9160
movss %xmm0, 0x170(%rsp)
testb $0x1, 0x177(%rsp)
je 0x9c9f
movq 0x19377(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
movss 0x170(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x15d66(%rip), %rsi     # 0x1f9fe
movb $0x1, %al
callq 0x21c0
movq 0x190(%rsp), %rdi
movl 0x18c(%rsp), %esi
movsd 0x180(%rsp), %xmm0
callq 0x98b0
movss %xmm0, 0x16c(%rsp)
testb $0x1, 0x177(%rsp)
je 0x9d24
movq 0x19322(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
movss 0x16c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x15d30(%rip), %rsi     # 0x1fa1d
movb $0x1, %al
callq 0x21c0
movss 0x16c(%rsp), %xmm0
movss 0x144ab(%rip), %xmm1    # 0x1e1b0
ucomiss %xmm1, %xmm0
jbe 0x9d22
movq 0x192e7(%rip), %rax     # 0x22ff8
movq (%rax), %rdi
leaq 0x15d2b(%rip), %rsi     # 0x1fa46
movb $0x0, %al
callq 0x21c0
jmp 0x9d24
movl $0x0, 0x168(%rsp)
movl 0x168(%rsp), %eax
cmpl 0x18c(%rsp), %eax
jge 0xa418
movq 0x190(%rsp), %rax
movslq 0x168(%rsp), %rcx
imulq $0x68, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x160(%rsp)
movq 0x160(%rsp), %rax
testb $0x1, 0xc(%rax)
jne 0x9d7e
movq 0x160(%rsp), %rax
testb $0x1, 0xd(%rax)
jne 0x9d83
jmp 0xa402
movq 0x160(%rsp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x9dad
movq 0x160(%rsp), %rdi
movss 0x170(%rsp), %xmm0
callq 0x92b0
jmp 0xa402
movq 0x160(%rsp), %rax
movl 0x40(%rax), %eax
movq 0x160(%rsp), %rcx
cmpl 0x44(%rcx), %eax
jbe 0x9e4f
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rdi
movq 0x160(%rsp), %rax
movl 0x40(%rax), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x28e0
movq %rax, %rcx
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq %rcx, (%rax)
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rdi
movq 0x160(%rsp), %rax
movl 0x40(%rax), %eax
movl %eax, %esi
shlq $0x2, %rsi
callq 0x28e0
movq %rax, %rcx
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq %rcx, 0x8(%rax)
movq 0x160(%rsp), %rax
movl 0x40(%rax), %ecx
movq 0x160(%rsp), %rax
movl %ecx, 0x44(%rax)
movl $0x0, 0x15c(%rsp)
movl 0x15c(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x18(%rcx), %eax
jge 0x9e8b
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x2c(%rsp)
jmp 0x9e9d
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
movl %eax, 0x158(%rsp)
movb $0x1, 0x157(%rsp)
cmpl $0x0, 0x158(%rsp)
jne 0x9f21
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 0x9f04
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x28(%rsp)
jmp 0x9f16
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
movl 0x28(%rsp), %eax
movl %eax, 0x158(%rsp)
movq 0x160(%rsp), %rax
movq 0x20(%rax), %rax
movq %rax, 0x148(%rsp)
movl $0x0, 0x144(%rsp)
movb $0x0, 0x143(%rsp)
movss 0x16c(%rsp), %xmm0
movss %xmm0, 0x24(%rsp)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movw (%rax), %si
movq 0x148(%rsp), %rax
movq (%rax), %rax
leaq 0x144(%rsp), %rdx
leaq 0x143(%rsp), %rcx
movswl %si, %edi
movzbl (%rax), %esi
callq 0x9650
movaps %xmm0, %xmm1
movss 0x24(%rsp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0x13c(%rsp)
movss 0x13c(%rsp), %xmm0
ucomiss 0x170(%rsp), %xmm0
jbe 0x9fc6
movss 0x13c(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
jmp 0x9fd5
movss 0x170(%rsp), %xmm0
movss %xmm0, 0x20(%rsp)
movss 0x20(%rsp), %xmm0
movss %xmm0, 0x138(%rsp)
movl $0x0, 0x134(%rsp)
movl $0x1, 0x130(%rsp)
movl 0x130(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x8(%rcx), %eax
jae 0xa283
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x130(%rsp), %ecx
movswl (%rax,%rcx,2), %eax
cmpl $0x0, %eax
jne 0xa049
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x130(%rsp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0xa0b5
movss 0x16c(%rsp), %xmm0
movss %xmm0, 0x1c(%rsp)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x130(%rsp), %ecx
movw (%rax,%rcx,2), %di
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x130(%rsp), %ecx
movl %ecx, %esi
leaq 0x144(%rsp), %rdx
leaq 0x143(%rsp), %rcx
movswl %di, %edi
movzbl (%rax,%rsi), %esi
callq 0x9650
movaps %xmm0, %xmm1
movss 0x1c(%rsp), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0x13c(%rsp)
movl 0x130(%rsp), %eax
cmpl 0x158(%rsp), %eax
je 0xa12a
testb $0x1, 0x157(%rsp)
je 0xa1a8
movss 0x138(%rsp), %xmm0
movss %xmm0, 0x18(%rsp)
movss 0x13c(%rsp), %xmm0
ucomiss 0x170(%rsp), %xmm0
jbe 0xa106
movss 0x13c(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
jmp 0xa115
movss 0x170(%rsp), %xmm0
movss %xmm0, 0x14(%rsp)
movss 0x18(%rsp), %xmm0
movss 0x14(%rsp), %xmm1
ucomiss %xmm1, %xmm0
jne 0xa12a
jp 0xa12a
jmp 0xa1a8
movl 0x130(%rsp), %edx
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movl 0x134(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
testb $0x1, 0x157(%rsp)
je 0xa165
movss 0x138(%rsp), %xmm0
movss %xmm0, 0x10(%rsp)
jmp 0xa175
movss 0x14027(%rip), %xmm0    # 0x1e194
movss %xmm0, 0x10(%rsp)
jmp 0xa175
movss 0x10(%rsp), %xmm0
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movl 0x134(%rsp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl 0x134(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x134(%rsp)
movss 0x13c(%rsp), %xmm0
ucomiss 0x170(%rsp), %xmm0
jbe 0xa1cc
movss 0x13c(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
jmp 0xa1db
movss 0x170(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0xc(%rsp), %xmm0
movss %xmm0, 0x138(%rsp)
movl 0x130(%rsp), %eax
cmpl 0x158(%rsp), %eax
jne 0xa26b
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 0xa24e
movq 0x160(%rsp), %rax
movq 0x10(%rax), %rax
movslq 0x15c(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x8(%rsp)
jmp 0xa260
movq 0x160(%rsp), %rax
movl 0x8(%rax), %eax
addl $0x1, %eax
movl %eax, 0x8(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x158(%rsp)
jmp 0xa26d
movl 0x130(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x130(%rsp)
jmp 0x9ffa
movl 0x130(%rsp), %edx
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq (%rax), %rax
movl 0x134(%rsp), %ecx
movl %edx, (%rax,%rcx,4)
testb $0x1, 0x157(%rsp)
je 0xa2be
movss 0x138(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
jmp 0xa2ce
movss 0x13ece(%rip), %xmm0    # 0x1e194
movss %xmm0, 0x4(%rsp)
jmp 0xa2ce
movss 0x4(%rsp), %xmm0
movq 0x160(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x8(%rax), %rax
movl 0x134(%rsp), %ecx
movss %xmm0, (%rax,%rcx,4)
movl 0x134(%rsp), %eax
movq 0x160(%rsp), %rcx
cmpl 0x40(%rcx), %eax
jb 0xa345
leaq 0xb0(%rsp), %rdi
movq 0x18f9d(%rip), %rdx     # 0x232b0
movq 0x160(%rsp), %rax
movq (%rax), %rcx
leaq 0x15756(%rip), %rsi     # 0x1fa7b
movb $0x0, %al
callq 0x22a0
leaq 0xb0(%rsp), %rdi
movl $0x21, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movl 0x134(%rsp), %ecx
addl $0x1, %ecx
movq 0x160(%rsp), %rax
movl %ecx, 0x40(%rax)
movq 0x148(%rsp), %rax
movq 0x8(%rax), %rax
movl 0x130(%rsp), %ecx
movw (%rax,%rcx,2), %di
movq 0x148(%rsp), %rax
movq (%rax), %rax
movl 0x130(%rsp), %ecx
movl %ecx, %esi
leaq 0x144(%rsp), %rdx
leaq 0x143(%rsp), %rcx
movswl %di, %edi
movzbl (%rax,%rsi), %esi
callq 0x9650
movss %xmm0, 0x13c(%rsp)
movss 0x13c(%rsp), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jne 0xa3bf
jp 0xa3bf
jmp 0xa400
leaq 0x30(%rsp), %rdi
movq 0x160(%rsp), %rax
movq (%rax), %rdx
movss 0x13c(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
leaq 0x156a0(%rip), %rsi     # 0x1fa83
movb $0x1, %al
callq 0x22a0
leaq 0x30(%rsp), %rdi
movl $0x21, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
jmp 0xa402
movl 0x168(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x168(%rsp)
jmp 0x9d2f
addq $0x198, %rsp            # imm = 0x198
retq