// File: /workspace/github_c_makefile_star2_O1/jsh58[P]Genrich/Genrich.c
// Function: saveInterval
uint32_t saveInterval(Chrom* c, int64_t start, int64_t end,
    char* qname, uint8_t count, File bed, bool bedOpt,
    bool gzOut, bool ctrl, int sample, uint64_t* errCount,
    bool verbose) {

  // check validity of positions
  if (start < 0) {
    if (verbose) {
      if (*errCount < MAX_ALNS)
        fprintf(stderr, "Warning! Read %s prevented from extending below 0 on %s\n",
          qname, c->name);
      (*errCount)++;
    }
    start = 0;
  }
  if (start >= c->len) {
    char msg[MAX_ALNS];
    sprintf(msg, "Read %s, ref. %s", qname, c->name);
    exit(error(msg, ERRPOS));
  }
  if (end > c->len) {
    if (verbose) {
      if (*errCount < MAX_ALNS)
        fprintf(stderr, "Warning! Read %s prevented from extending past %d on %s\n",
          qname, c->len, c->name);
      (*errCount)++;
    }
    end = c->len;
  }

  // create 'diff' arrays if necessary
  if (c->diff == NULL) {
    c->diff = (Diff*) memalloc(sizeof(Diff));
    c->diff->frac = (uint8_t*) memalloc((1 + c->len) * sizeof(uint8_t));
    c->diff->cov = (int16_t*) memalloc((1 + c->len) * sizeof(int16_t));
    for (int i = 0; i < 1 + c->len; i++) {
      c->diff->frac[i] = 0;
      c->diff->cov[i] = 0;
    }
  }

  // check for overflow/underflow (c->diff->cov is int16_t)
  if (c->diff->cov[start] == INT16_MAX) {
    if (verbose) {
      fprintf(stderr, "Warning! Read %s, alignment at (%s, %ld-%ld)",
        qname, c->name, start, end);
      fprintf(stderr, " skipped due to overflow\n");
    }
    return 0;
  }
  if (c->diff->cov[end] == INT16_MIN) {
    if (verbose) {
      fprintf(stderr, "Warning! Read %s, alignment at (%s, %ld-%ld)",
        qname, c->name, start, end);
      fprintf(stderr, " skipped due to underflow\n");
    }
    return 0;
  }

  // add counts to diff array(s)
  if (count == 1) {
    c->diff->cov[start]++;
    c->diff->cov[end]--;
  } else {
    // add fractional count
    addFrac(&c->diff->cov[start], &c->diff->frac[start], count);
    subFrac(&c->diff->cov[end], &c->diff->frac[end], count);
  }

  // print BED interval
  if (bedOpt)
    printBED(bed, gzOut, c->name, start, end, qname,
      count, ctrl, sample);

  return end - start;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r11
movq %rdx, %r14
movq %rdi, %r15
movb 0xe8(%rsp), %dil
movl %edi, %eax
xorb $0x1, %al
movq 0xe0(%rsp), %rbx
xorl %r12d, %r12d
testq %rsi, %rsi
setns %cl
cmovgq %rsi, %r12
orb %al, %cl
jne 0x8887
cmpq $0x7f, (%rbx)
jbe 0x8a4f
incq (%rbx)
xorl %r12d, %r12d
movl 0x8(%r15), %ecx
cmpq %rcx, %r12
jae 0x8ac9
cmpq %r14, %rcx
jge 0x88af
testb %dil, %dil
je 0x88ab
cmpq $0x7f, (%rbx)
jbe 0x8a8c
incq (%rbx)
movl 0x8(%r15), %r14d
cmpq $0x0, 0x20(%r15)
jne 0x893a
movl $0x10, %edi
movq %r11, %rbx
movq %r9, %rbp
movl %r8d, %r13d
callq 0x3903
movq %rax, 0x20(%r15)
movl 0x8(%r15), %edi
incl %edi
callq 0x3903
movq 0x20(%r15), %rcx
movq %rax, (%rcx)
movl 0x8(%r15), %edi
incl %edi
addq %rdi, %rdi
callq 0x3903
movb 0xe8(%rsp), %dil
movl %r13d, %r8d
movq %rbp, %r9
movq %rbx, %r11
movq 0x20(%r15), %rcx
movq %rax, 0x8(%rcx)
cmpl $-0x1, 0x8(%r15)
je 0x893a
xorl %eax, %eax
movq 0x20(%r15), %rcx
movq (%rcx), %rcx
movb $0x0, (%rcx,%rax)
movq 0x20(%r15), %rcx
movq 0x8(%rcx), %rcx
movw $0x0, (%rcx,%rax,2)
incq %rax
movl 0x8(%r15), %ecx
incl %ecx
cmpq %rcx, %rax
jb 0x8913
movq 0x20(%r15), %rdx
movq 0x8(%rdx), %rax
movzwl (%rax,%r12,2), %ecx
xorl %ebx, %ebx
cmpl $0x7fff, %ecx           # imm = 0x7FFF
jne 0x8970
testb %dil, %dil
je 0x8a3b
movq %r15, %rdi
movq %r11, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2ea2
jmp 0x8a3b
cmpw (%rax,%r14,2), %bx
jno 0x8996
testb %dil, %dil
je 0x8a3b
movq %r15, %rdi
movq %r11, %rsi
movq %r12, %rdx
movq %r14, %rcx
callq 0x2e64
jmp 0x8a3b
movb 0xc0(%rsp), %sil
leaq (%rax,%r12,2), %rdi
movzbl %r8b, %ebx
cmpb $0x1, %r8b
jne 0x89b8
incl %ecx
movw %cx, (%rdi)
decw (%rax,%r14,2)
jmp 0x89f2
movq (%rdx), %rsi
addq %r12, %rsi
movl %ebx, %edx
movq %r11, %rbp
movq %r9, %r13
callq 0x85d9
movq 0x20(%r15), %rax
leaq (%r14,%r14), %rdi
addq 0x8(%rax), %rdi
movq (%rax), %rsi
addq %r14, %rsi
movl %ebx, %edx
callq 0x8702
movb 0xc0(%rsp), %sil
movq %r13, %r9
movq %rbp, %r11
testb %sil, %sil
je 0x8a35
movl 0xd8(%rsp), %eax
movb 0xd0(%rsp), %cl
movb 0xc8(%rsp), %sil
movq (%r15), %rdx
subq $0x8, %rsp
movzbl %cl, %r10d
movzbl %sil, %esi
movq %r9, %rdi
movq %r12, %rcx
movq %r14, %r8
movq %r11, %r9
pushq %rax
pushq %r10
pushq %rbx
callq 0x87e6
addq $0x20, %rsp
subl %r12d, %r14d
movl %r14d, %ebx
movl %ebx, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x115a2(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movq (%r15), %rcx
leaq 0xaf2b(%rip), %rsi      # 0x1398e
movq %r11, %rdx
xorl %eax, %eax
movq %r11, %r12
movq %r9, %rbp
movl %r8d, %r13d
callq 0x21d0
movb 0xe8(%rsp), %dil
movl %r13d, %r8d
movq %rbp, %r9
movq %r12, %r11
jmp 0x8881
movq 0x11565(%rip), %rax     # 0x19ff8
movq (%rax), %rdi
movl %r8d, %r13d
movq (%r15), %r8
leaq 0xaf35(%rip), %rsi      # 0x139d8
movq %r11, %rdx
xorl %eax, %eax
movq %r11, %r14
movq %r9, %rbp
callq 0x21d0
movb 0xe8(%rsp), %dil
movl %r13d, %r8d
movq %rbp, %r9
movq %r14, %r11
jmp 0x88a8
movq %rsp, %rdi
movq %r15, %rsi
movq %r11, %rdx
callq 0x2e3c