// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/core/bitpackstringop64.c
// Function: gt_bsStoreUInt64
void
gt_bsStoreUInt64(BitString str, BitOffset offset,
                 unsigned numBits, uint64_t val)
{
  unsigned bitsLeft = numBits,
    bitTop = offset%bitElemBits;
  size_t elemStart = offset/bitElemBits;
  BitElem *p = str + elemStart;
  gt_assert(str);
  gt_assert(numBits <= sizeof (val)*CHAR_BIT);
  /* set bits of first element, accounting for bits to be preserved */
  if (bitTop)
  {
    GtUint64 mask = ~(GtUint64)0;
    if (bitElemBits < (sizeof (GtUint64)*CHAR_BIT))
    {
      mask <<= bitElemBits;
    }
    else
    {
      mask = 0;
    }
    mask = (~mask) >> bitTop;
    if (numBits < bitElemBits - bitTop)
    {
      unsigned backShift = bitElemBits - numBits - bitTop;
      mask &= ~(GtUint64)0 << backShift;
      *p = (*p & ~mask) | ((val << backShift) & mask);
      /* TODO: try wether  r = a ^ ((a ^ b) & mask) is faster, see below */
      return;
    }
    else
    {
      bitsLeft -= bitElemBits - bitTop;
      *p = (*p & ~mask) | ((val >> bitsLeft) & mask);
      ++p;
    }
  }
  /* set bits for intervening elems */
  while (bitsLeft >= bitElemBits)
  {
    bitsLeft -= bitElemBits;
    *p++ = val >> bitsLeft;
  }
  /* set bits for last elem */
  if (bitsLeft)
  {
    GtUint64 mask =
      ((~(GtUint64)0)<<(bitElemBits - bitsLeft));
    if (bitElemBits < (sizeof (GtUint64)*CHAR_BIT))
      mask &= (~(~(GtUint64)0<<bitElemBits));
    *p = (*p & ~mask) | ((val << (bitElemBits - bitsLeft)) & mask);
  }
}

// Assembly:
pushq %rax
testq %rdi, %rdi
je 0x28e084
cmpl $0x41, %edx
jae 0x28e0ae
movq %rcx, %rax
movl %esi, %r10d
andl $0x7, %r10d
movq %rsi, %rcx
shrq $0x3, %rcx
addq %rcx, %rdi
testl %r10d, %r10d
je 0x28e016
andl $0x7, %esi
movl $0xff, %r9d
movl %esi, %ecx
shrq %cl, %r9
pushq $0x8
popq %rcx
subl %r10d, %ecx
movl %edx, %r8d
subl %ecx, %r8d
jae 0x28e01b
addl %edx, %r10d
movb $0x8, %cl
subb %r10b, %cl
pushq $-0x1
popq %rdx
shlq %cl, %rdx
andl %r9d, %edx
movzbl (%rdi), %esi
shlq %cl, %rax
notl %edx
andl %esi, %edx
andl %r9d, %eax
orl %edx, %eax
jmp 0x28e080
movl %edx, %r8d
jmp 0x28e041
movq $-0x100, %rdx
movl %esi, %ecx
sarq %cl, %rdx
movzbl (%rdi), %ecx
andl %ecx, %edx
movq %rax, %rsi
movl %r8d, %ecx
shrq %cl, %rsi
andl %esi, %r9d
orl %edx, %r9d
movb %r9b, (%rdi)
incq %rdi
movl %r8d, %ecx
addq $-0x8, %rcx
leaq 0x8(%rcx), %rdx
cmpq $0x8, %rdx
jb 0x28e05f
movq %rax, %rdx
shrq %cl, %rdx
movb %dl, (%rdi)
incq %rdi
jmp 0x28e044
cmpq $-0x8, %rcx
je 0x28e082
negb %cl
pushq $-0x1
popq %rdx
shlq %cl, %rdx
notl %edx
movzbl (%rdi), %esi
orl $0xffffff01, %edx       # imm = 0xFFFFFF01
andl %esi, %edx
shlq %cl, %rax
orq %rdx, %rax
movb %al, (%rdi)
popq %rax
retq
movq 0x1a9edd(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x56f7e(%rip), %rsi     # 0x2e5013
leaq 0x83f88(%rip), %rdx     # 0x312024
leaq 0xecf9a(%rip), %rcx     # 0x37b03d
leaq 0xecf76(%rip), %r8      # 0x37b020
pushq $0x49
jmp 0x28e0d6
movq 0x1a9eb3(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x56f54(%rip), %rsi     # 0x2e5013
leaq 0xecc8c(%rip), %rdx     # 0x37ad52
leaq 0xecf70(%rip), %rcx     # 0x37b03d
leaq 0xecf4c(%rip), %r8      # 0x37b020
pushq $0x4a
popq %r9
xorl %eax, %eax
callq 0x17a50
callq 0x17390