// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/core/bitpackstringop.c
// Function: gt_bs1BitsCount
BitOffset gt_bs1BitsCount(constBitString str, BitOffset offset,
                          BitOffset numBits)
{
  uint32_t accum = 0;
  BitOffset weight = 0, bitsLeft = numBits;
  unsigned bitTop = offset%bitElemBits, bitsInAccum = 0;
  size_t elemStart = offset/bitElemBits;
  const BitElem *p = str + elemStart;
  gt_assert(str);
  if (bitTop)
  {
    uint32_t mask;
    unsigned bits2Read = GT_MIN(bitElemBits - bitTop, bitsLeft);
    unsigned unreadRightBits = (bitElemBits - bitTop - bits2Read);
    mask = (~((~(uint32_t)0) << bits2Read)) << unreadRightBits;
    weight += bitCountUInt32(((*p++) & mask) >> unreadRightBits);
    bitsLeft -= bits2Read;
  }
  /* get bits from intervening elems */
  while (bitsLeft >= bitElemBits)
  {
    while (bitsLeft >= bitElemBits
           && sizeof (accum) * CHAR_BIT - bitElemBits >= bitsInAccum)
    {
      accum = accum << bitElemBits | (*p++);
      bitsLeft -= bitElemBits;
      bitsInAccum += bitElemBits;
    }
    weight += bitCountUInt32(accum);
    accum = 0; bitsInAccum = 0;
  }
  /* get bits from last elem */
  if (bitsLeft)
  {
    accum = ((*p) & ((~(uint32_t)0)<<(bitElemBits - bitsLeft)));
    weight += bitCountUInt32(accum);
  }
  return weight;
}

// Assembly:
pushq %rax
testq %rdi, %rdi
je 0x2fa73e
movl %esi, %ecx
andl $0x7, %ecx
shrq $0x3, %rsi
addq %rsi, %rdi
testl %ecx, %ecx
je 0x2fa67f
movl $0x8, %eax
subl %ecx, %eax
cmpq %rdx, %rax
movq %rdx, %rsi
cmovbq %rax, %rsi
subl %esi, %eax
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
movl %esi, %ecx
shll %cl, %r8d
movzbl (%rdi), %r9d
movl %eax, %ecx
shrl %cl, %r9d
notl %r8d
incq %rdi
andl %r8d, %r9d
movl %r9d, %eax
shrl %eax
andl $-0x2b, %eax
subl %eax, %r9d
movl $0x33333333, %eax       # imm = 0x33333333
movl %r9d, %ecx
andl %eax, %ecx
shrl $0x2, %r9d
andl %eax, %r9d
addl %ecx, %r9d
movl %r9d, %eax
shrl $0x4, %eax
addl %r9d, %eax
andl $0xf0f0f0f, %eax        # imm = 0xF0F0F0F
imull $0x1010101, %eax, %eax  # imm = 0x1010101
shrl $0x18, %eax
subq %rsi, %rdx
jmp 0x2fa681
xorl %eax, %eax
cmpq $0x8, %rdx
jb 0x2fa6fa
movl $0x33333333, %ecx       # imm = 0x33333333
xorl %esi, %esi
xorl %r8d, %r8d
movl %esi, %r9d
shll $0x8, %r9d
movzbl (%rdi), %esi
incq %rdi
orl %r9d, %esi
addq $-0x8, %rdx
cmpq $0x8, %rdx
jb 0x2fa6b8
leal 0x8(%r8), %r9d
cmpl $0x11, %r8d
movl %r9d, %r8d
jb 0x2fa691
movl %esi, %r8d
shrl %r8d
andl $0x55555555, %r8d       # imm = 0x55555555
subl %r8d, %esi
movl %esi, %r8d
andl %ecx, %r8d
shrl $0x2, %esi
andl %ecx, %esi
addl %r8d, %esi
movl %esi, %r8d
shrl $0x4, %r8d
addl %esi, %r8d
andl $0xf0f0f0f, %r8d        # imm = 0xF0F0F0F
imull $0x1010101, %r8d, %esi  # imm = 0x1010101
shrl $0x18, %esi
addq %rsi, %rax
cmpq $0x7, %rdx
ja 0x2fa68c
testq %rdx, %rdx
je 0x2fa73c
movzbl (%rdi), %esi
movb $0x8, %cl
subb %dl, %cl
shrl %cl, %esi
shll %cl, %esi
movl %esi, %ecx
shrl %ecx
andl $0x55, %ecx
subl %ecx, %esi
movl $0x33333333, %ecx       # imm = 0x33333333
movl %esi, %edx
andl %ecx, %edx
shrl $0x2, %esi
andl %ecx, %esi
addl %edx, %esi
movl %esi, %ecx
shrl $0x4, %ecx
addl %esi, %ecx
andl $0xf0f0f0f, %ecx        # imm = 0xF0F0F0F
imull $0x1010101, %ecx, %ecx  # imm = 0x1010101
shrl $0x18, %ecx
addq %rcx, %rax
popq %rcx
retq
callq 0x88eaf