// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/core/bitpackstringop32.c
// Function: gt_bsStoreUInt32
void
gt_bsStoreUInt32(BitString str, BitOffset offset,
                 unsigned numBits, uint32_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)
  {
    GtUword mask = ~(GtUword)0;
    if (bitElemBits < (sizeof (GtUword)*CHAR_BIT))
    {
      mask <<= bitElemBits;
    }
    else
    {
      mask = 0;
    }
    mask = (~mask) >> bitTop;
    if (numBits < bitElemBits - bitTop)
    {
      unsigned backShift = bitElemBits - numBits - bitTop;
      mask &= ~(GtUword)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)
  {
    GtUword mask =
      ((~(GtUword)0)<<(bitElemBits - bitsLeft));
    if (bitElemBits < (sizeof (GtUword)*CHAR_BIT))
      mask &= (~(~(GtUword)0<<bitElemBits));
    *p = (*p & ~mask) | ((val << (bitElemBits - bitsLeft)) & mask);
  }
}

// Assembly:
pushq %rax
testq %rdi, %rdi
je 0xc6c8c
cmpl $0x21, %edx
jae 0xc6cb6
movl %ecx, %eax
movq %rsi, %rcx
movl %ecx, %r9d
andl $0x7, %r9d
shrq $0x3, %rsi
addq %rsi, %rdi
testl %r9d, %r9d
je 0xc6c63
andl $0x7, %ecx
movl $0xff, %r8d
shrq %cl, %r8
pushq $0x8
popq %r10
subl %r9d, %r10d
movl %edx, %esi
subl %r10d, %esi
jae 0xc6c6a
addl %edx, %r9d
movb $0x8, %cl
subb %r9b, %cl
pushq $-0x1
popq %rdx
shlq %cl, %rdx
andl %edx, %r8d
movzbl (%rdi), %edx
shll %cl, %eax
xorl %edx, %eax
andl %r8d, %eax
xorl %edx, %eax
jmp 0xc6d29
movl %edx, %esi
jmp 0xc6cef
movq $-0x100, %rdx
sarq %cl, %rdx
movzbl (%rdi), %ecx
andl %ecx, %edx
movl %eax, %r9d
movl %esi, %ecx
shrl %cl, %r9d
andl %r9d, %r8d
orl %edx, %r8d
movb %r8b, (%rdi)
jmp 0xc6cec
movq 0x67325(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x33c9(%rip), %rsi      # 0xca066
leaq 0x5d0f(%rip), %rdx      # 0xcc9b3
leaq 0x2e64a(%rip), %rcx     # 0xf52f5
leaq 0x2e5f5(%rip), %r8      # 0xf52a7
pushq $0x49
jmp 0xc6cde
movq 0x672fb(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x339f(%rip), %rsi      # 0xca066
leaq 0x2e638(%rip), %rdx     # 0xf5306
leaq 0x2e620(%rip), %rcx     # 0xf52f5
leaq 0x2e5cb(%rip), %r8      # 0xf52a7
pushq $0x4a
popq %r9
xorl %eax, %eax
callq 0xb8c0
callq 0xb300
incq %rdi
addl $-0x8, %esi
leal 0x8(%rsi), %ecx
cmpl $0x8, %ecx
jb 0xc6d04
movl %eax, %edx
movl %esi, %ecx
shrl %cl, %edx
movb %dl, (%rdi)
jmp 0xc6cec
cmpl $-0x8, %esi
je 0xc6d2b
movl %esi, %ecx
negb %cl
movl $0xfe, %edx
shrl %cl, %edx
shll %cl, %edx
movzbl (%rdi), %r8d
negb %sil
movl %esi, %ecx
shll %cl, %eax
xorl %r8d, %eax
andl %edx, %eax
xorl %r8d, %eax
movb %al, (%rdi)
popq %rax
retq