// File: /workspace/github_c_makefile_star2_O0/jsh58[P]Genrich/Genrich.c
// Function: updateVal
float updateVal(int16_t dCov, uint8_t dFrac, int32_t* cov,
    uint8_t* frac) {

  // add ints
  *cov += dCov;
  if (! dFrac) {
    if (*cov < 0)
      exit(error(errMsg[ERRPILE], ERRISSUE));
    return getVal(*cov, *frac);
  }

  // sum eighths (and collect halves)
  int half = 0;
  if (dFrac & 0x7) {
    int sum8 = (dFrac & 0x7) + (*frac & 0x7);
    while (sum8 > 3) {
      half++;
      sum8 -= 4;
    }
    *frac = (*frac & 0xF8) | sum8;
  } else if (*frac & 0x4) {
    half++;
    *frac &= 0xFB;
  }

  // sum sixths
  if (dFrac & 0x18) {
    int sum6 = ((dFrac >> 3) & 0x3) + ((*frac >> 3) & 0x3);
    if (sum6 > 2) {
      half++;
      sum6 -= 3;
    }
    *frac = (*frac & 0xE7) | (sum6 << 3);
  }

  // sum tenths
  if (dFrac & 0xE0) {
    int sum10 = ((dFrac >> 5) & 0x7) + ((*frac >> 5) & 0x7);
    if (sum10 > 4) {
      half++;
      sum10 -= 5;
    }
    *frac = (*frac & 0x1F) | (sum10 << 5);
  }

  // combine halves
  while (half > 1) {
    (*cov)++;
    half -= 2;
  }
  if (half)
    *frac |= 0x4;

  // check for negative pileup
  if (*cov < 0)
    exit(error(errMsg[ERRPILE], ERRISSUE));

  return getVal(*cov, *frac);
}

// Assembly:
subq $0x28, %rsp
movb %sil, %al
movw %di, %si
movw %si, 0x22(%rsp)
movb %al, 0x21(%rsp)
movq %rdx, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movswl 0x22(%rsp), %ecx
movq 0x18(%rsp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
cmpb $0x0, 0x21(%rsp)
jne 0x96c3
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
jge 0x96a4
movq 0x19c05(%rip), %rdi     # 0x23298
movl $0x21, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movq 0x18(%rsp), %rax
movl (%rax), %edi
movq 0x10(%rsp), %rax
movzbl (%rax), %esi
callq 0x95e0
movss %xmm0, 0x24(%rsp)
jmp 0x9896
movl $0x0, 0xc(%rsp)
movzbl 0x21(%rsp), %eax
andl $0x7, %eax
cmpl $0x0, %eax
je 0x972c
movzbl 0x21(%rsp), %eax
andl $0x7, %eax
movq 0x10(%rsp), %rcx
movzbl (%rcx), %ecx
andl $0x7, %ecx
addl %ecx, %eax
movl %eax, 0x8(%rsp)
cmpl $0x3, 0x8(%rsp)
jle 0x9710
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
movl 0x8(%rsp), %eax
subl $0x4, %eax
movl %eax, 0x8(%rsp)
jmp 0x96f1
movq 0x10(%rsp), %rax
movzbl (%rax), %eax
andl $0xf8, %eax
orl 0x8(%rsp), %eax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, (%rax)
jmp 0x9759
movq 0x10(%rsp), %rax
movzbl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x9757
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
movq 0x10(%rsp), %rax
movzbl (%rax), %ecx
andl $0xfb, %ecx
movb %cl, (%rax)
jmp 0x9759
movzbl 0x21(%rsp), %eax
andl $0x18, %eax
cmpl $0x0, %eax
je 0x97c1
movzbl 0x21(%rsp), %eax
sarl $0x3, %eax
andl $0x3, %eax
movq 0x10(%rsp), %rcx
movzbl (%rcx), %ecx
sarl $0x3, %ecx
andl $0x3, %ecx
addl %ecx, %eax
movl %eax, 0x4(%rsp)
cmpl $0x2, 0x4(%rsp)
jle 0x97a2
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
movl 0x4(%rsp), %eax
subl $0x3, %eax
movl %eax, 0x4(%rsp)
movq 0x10(%rsp), %rax
movzbl (%rax), %eax
andl $0xe7, %eax
movl 0x4(%rsp), %ecx
shll $0x3, %ecx
orl %ecx, %eax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, (%rax)
movzbl 0x21(%rsp), %eax
andl $0xe0, %eax
cmpl $0x0, %eax
je 0x9824
movzbl 0x21(%rsp), %eax
sarl $0x5, %eax
andl $0x7, %eax
movq 0x10(%rsp), %rcx
movzbl (%rcx), %ecx
sarl $0x5, %ecx
andl $0x7, %ecx
addl %ecx, %eax
movl %eax, (%rsp)
cmpl $0x4, (%rsp)
jle 0x9808
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
movl (%rsp), %eax
subl $0x5, %eax
movl %eax, (%rsp)
movq 0x10(%rsp), %rax
movzbl (%rax), %eax
andl $0x1f, %eax
movl (%rsp), %ecx
shll $0x5, %ecx
orl %ecx, %eax
movb %al, %cl
movq 0x10(%rsp), %rax
movb %cl, (%rax)
jmp 0x9826
cmpl $0x1, 0xc(%rsp)
jle 0x9846
movq 0x18(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movl 0xc(%rsp), %eax
subl $0x2, %eax
movl %eax, 0xc(%rsp)
jmp 0x9826
cmpl $0x0, 0xc(%rsp)
je 0x985a
movq 0x10(%rsp), %rax
movzbl (%rax), %ecx
orl $0x4, %ecx
movb %cl, (%rax)
movq 0x18(%rsp), %rax
cmpl $0x0, (%rax)
jge 0x987c
movq 0x19a2d(%rip), %rdi     # 0x23298
movl $0x21, %esi
callq 0x2840
movl %eax, %edi
callq 0x22b0
movq 0x18(%rsp), %rax
movl (%rax), %edi
movq 0x10(%rsp), %rax
movzbl (%rax), %esi
callq 0x95e0
movss %xmm0, 0x24(%rsp)
movss 0x24(%rsp), %xmm0
addq $0x28, %rsp
retq
nopw %cs:(%rax,%rax)