// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movq %rcx, 0x38(%rsp)
movl 0x44(%rsp), %eax
movl %eax, 0x34(%rsp)
movq 0x48(%rsp), %rax
andq $0x7, %rax
movl %eax, 0x30(%rsp)
movq 0x48(%rsp), %rax
shrq $0x3, %rax
movq %rax, 0x28(%rsp)
movq 0x50(%rsp), %rax
addq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x50(%rsp)
jne 0x477179
movq 0x1c4e58(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x9eec1(%rip), %rsi     # 0x516013
leaq 0xccf04(%rip), %rdx     # 0x54405d
leaq 0x138ecd(%rip), %rcx    # 0x5b002d
leaq 0x138ea9(%rip), %r8     # 0x5b0010
movl $0x49, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x47717b
jmp 0x47717d
movl 0x44(%rsp), %eax
cmpq $0x40, %rax
jbe 0x4771bf
movq 0x1c4e12(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x9ee7b(%rip), %rsi     # 0x516013
leaq 0x138ba3(%rip), %rdx    # 0x5afd42
leaq 0x138e87(%rip), %rcx    # 0x5b002d
leaq 0x138e63(%rip), %r8     # 0x5b0010
movl $0x4a, %r9d
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x4771c1
cmpl $0x0, 0x30(%rsp)
je 0x4772c4
movq $-0x1, 0x18(%rsp)
movq 0x18(%rsp), %rax
shlq $0x8, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
xorq $-0x1, %rax
movl 0x30(%rsp), %ecx
shrq %cl, %rax
movq %rax, 0x18(%rsp)
movl 0x44(%rsp), %eax
movl $0x8, %ecx
subl 0x30(%rsp), %ecx
cmpl %ecx, %eax
jae 0x47726d
movl $0x8, %eax
subl 0x44(%rsp), %eax
subl 0x30(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x14(%rsp), %eax
movl %eax, %ecx
movq $-0x1, %rax
shlq %cl, %rax
andq 0x18(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movzbl (%rax), %eax
movq 0x18(%rsp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movq 0x38(%rsp), %rdx
movl 0x14(%rsp), %ecx
shlq %cl, %rdx
movq %rdx, %rcx
andq 0x18(%rsp), %rcx
orq %rcx, %rax
movb %al, %cl
movq 0x20(%rsp), %rax
movb %cl, (%rax)
jmp 0x477369
movl $0x8, %ecx
subl 0x30(%rsp), %ecx
movl 0x34(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x34(%rsp)
movq 0x20(%rsp), %rax
movzbl (%rax), %eax
movq 0x18(%rsp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movq 0x38(%rsp), %rdx
movl 0x34(%rsp), %ecx
shrq %cl, %rdx
movq %rdx, %rcx
andq 0x18(%rsp), %rcx
orq %rcx, %rax
movb %al, %cl
movq 0x20(%rsp), %rax
movb %cl, (%rax)
movq 0x20(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x20(%rsp)
jmp 0x4772c4
jmp 0x4772c6
cmpl $0x8, 0x34(%rsp)
jb 0x4772fb
movl 0x34(%rsp), %eax
subl $0x8, %eax
movl %eax, 0x34(%rsp)
movq 0x38(%rsp), %rax
movl 0x34(%rsp), %ecx
shrq %cl, %rax
movb %al, %cl
movq 0x20(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x20(%rsp)
movb %cl, (%rax)
jmp 0x4772c6
cmpl $0x0, 0x34(%rsp)
je 0x477369
movl $0x8, %eax
subl 0x34(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq $-0x1, %rax
shlq %cl, %rax
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rax
andq $0xff, %rax
movq %rax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movzbl (%rax), %eax
movq 0x8(%rsp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movq 0x38(%rsp), %rdx
movl $0x8, %ecx
subl 0x34(%rsp), %ecx
movl %ecx, %ecx
shlq %cl, %rdx
movq %rdx, %rcx
andq 0x8(%rsp), %rcx
orq %rcx, %rax
movb %al, %cl
movq 0x20(%rsp), %rax
movb %cl, (%rax)
addq $0x58, %rsp
retq
nop