// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/core/bitpackstringop32.c
// Function: gt_bsStoreUniformUInt32Array
void
gt_bsStoreUniformUInt32Array(BitString str, BitOffset offset,
                                 unsigned numBits, size_t numValues,
                                 const uint32_t val[])
{
  /* idea: read as much as possible from val in each iteration,
   * accumulate if bitsInAccum < bitElemBits */
  size_t j = 0;
  BitOffset totalBitsLeft = numValues * numBits;
  unsigned bitTop = offset%bitElemBits,
    bitsLeft; /*< how many bits in currentVal == val[j] are left */
  BitElem *p = str + offset/bitElemBits;
  unsigned bitsInAccum;
  GtUword accum, valMask = ~(GtUword)0, currentVal;
  if (numBits < (sizeof (val[0])*CHAR_BIT))
    valMask = ~(valMask << numBits);
  gt_assert(str && val);
  gt_assert(numBits <= sizeof (val[0])*CHAR_BIT);
  /* user requested zero values, ugly but must be handled, since legal */
  if (!totalBitsLeft)
  {
    return;
  }
  accum = val[0] & valMask;
  totalBitsLeft -= bitsInAccum = numBits;
  if (totalBitsLeft)
  {
    currentVal = val[++j] & valMask;
    totalBitsLeft -= bitsLeft = numBits;
  }
  else
  {
    currentVal = 0;
    bitsLeft = 0;
  }
  /* set bits of first element if not aligned */
  if (bitTop)
  {
    BitElem mask = ~(~(GtUword)0 << (bitElemBits - bitTop));
    while ((totalBitsLeft || bitsLeft) && bitsInAccum < bitElemBits - bitTop)
    {
      unsigned bits2Read, bitsFree = sizeof (accum)*CHAR_BIT - bitsInAccum;

      if ((bits2Read = GT_MIN(bitsFree, bitsLeft)) < sizeof (accum)*CHAR_BIT)
      {
        accum = accum << bits2Read
          | ((currentVal) >> (bitsLeft - bits2Read));
      }
      else
        accum = currentVal;

      /* all of val[j] consumed? */
      bitsInAccum += bits2Read;
      if (!(bitsLeft -= bits2Read) && totalBitsLeft)
        currentVal = val[++j] & valMask, totalBitsLeft -= bitsLeft = numBits;
    }
    /* at this point accum holds as many bits as we could get
     * to fill the first BitElem in str, but did we get enough? */
    if (bitsInAccum < bitElemBits - bitTop)
    {
      /* no there's not enough */
      unsigned backShift = bitElemBits - bitsInAccum - bitTop;
      mask &= ~(GtUword)0 << backShift;
      *p = (*p & ~mask) | ((accum << backShift) & mask);
      /* TODO: try wether  r = a ^ ((a ^ b) & mask) is faster, see below */
      return; /* if we couldn't gather more bits, there's none left */
    }
    else
    {
      /* yep, just or with accumVals */
      *p = (*p & ~mask) | (accum >> (bitsInAccum - bitElemBits + bitTop));
      ++p;
      bitsInAccum -= bitElemBits - bitTop;
    }
  }

  while (totalBitsLeft || (bitsInAccum + bitsLeft) > bitElemBits)
  {
    while ((totalBitsLeft || bitsLeft)
          && ((bitsInAccum < bitElemBits)
              || (bitsLeft < sizeof (accum)*CHAR_BIT - bitsInAccum)))
    {
      unsigned bits2Read, bitsFree = sizeof (accum)*CHAR_BIT - bitsInAccum;
      if ((bits2Read = GT_MIN(bitsFree, bitsLeft)) < sizeof (accum)*CHAR_BIT)
      {
        GtUword mask = ~((~(GtUword)0) << bits2Read);
        accum = accum << bits2Read
          | ((currentVal >> (bitsLeft - bits2Read)) & mask);
      }
      else
        accum = currentVal;
      bitsInAccum += bits2Read;
      /* all of currentVal == val[j] consumed? */
      if (bits2Read == bitsLeft && totalBitsLeft)
        currentVal = val[++j] & valMask, totalBitsLeft -= bitsLeft = numBits;
      else
        bitsLeft -= bits2Read;
    }
    /* now we have enough bits in accum */
    while (bitsInAccum >= bitElemBits)
    {
      *p++ = accum >> (bitsInAccum - bitElemBits);
      bitsInAccum -= bitElemBits;
    }
  }
  /* write the rest bits left in accum and currentVal */
  accum = (accum << bitsLeft)
    | (currentVal & (valMask >> (numBits - bitsLeft)));
  bitsInAccum += bitsLeft;
  while (bitsInAccum >= bitElemBits)
  {
    *p++ = accum >> (bitsInAccum - bitElemBits);
    bitsInAccum -= bitElemBits;
  }
  if (bitsInAccum)
  {
    GtUword mask =
      ~(GtUword)0 << (bitElemBits - bitsInAccum);
    *p = (*p & ~mask) | ((accum << (bitElemBits - bitsInAccum))& mask);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x8(%rsp)
movq %rcx, %rax
movq %rsi, %r11
movq $-0x1, %rsi
movq $-0x1, %r8
movl %edx, %ecx
shlq %cl, %r8
cmpl $0x20, %edx
notq %r8
cmovaeq %rsi, %r8
testq %rdi, %rdi
je 0xdeaff
cmpq $0x0, 0x8(%rsp)
je 0xdeaff
cmpl $0x21, %edx
jae 0xdeb04
movl %edx, %r13d
movq %r13, %rsi
imulq %rax, %rsi
testq %rsi, %rsi
je 0xdeaf0
movl %r11d, %ebx
andl $0x7, %ebx
movq %r11, %rcx
shrq $0x3, %rcx
movq 0x8(%rsp), %r9
movl (%r9), %r10d
andl %r8d, %r10d
cmpq %r13, %rsi
jne 0xde83d
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %eax, %eax
xorl %r14d, %r14d
jmp 0xde859
movq 0x8(%rsp), %rsi
movl 0x4(%rsi), %r12d
andl %r8d, %r12d
addq $-0x2, %rax
imulq %r13, %rax
movl $0x1, %r14d
movl %edx, %ebp
addq %rcx, %rdi
testl %ebx, %ebx
je 0xde918
movq %r11, 0x18(%rsp)
movl $0x8, %r11d
movl %ebx, 0x24(%rsp)
subl %ebx, %r11d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %r11d, %ecx
shll %cl, %esi
movl %esi, 0x10(%rsp)
testq %rax, %rax
setne %sil
testl %ebp, %ebp
setne %r9b
orb %sil, %r9b
cmpl %edx, %r11d
seta %cl
andb %cl, %r9b
cmpb $0x1, %r9b
jne 0xde920
movl %edx, %r9d
movl $0x40, %ebx
subl %r9d, %ebx
cmpl %ebp, %ebx
cmovael %ebp, %ebx
movl %ebx, %ecx
shlq %cl, %r10
subl %ebx, %ebp
movq %r12, %r15
movl %ebp, %ecx
shrq %cl, %r15
orq %r15, %r10
cmpl $0x40, %ebx
cmovaeq %r12, %r10
testb $0x1, %sil
je 0xde8ed
testl %ebp, %ebp
jne 0xde8ed
movq 0x8(%rsp), %rcx
movl 0x4(%rcx,%r14,4), %r12d
andl %r8d, %r12d
incq %r14
subq %r13, %rax
movl %edx, %ecx
jmp 0xde8f0
movq %rbp, %rcx
addl %ebx, %r9d
testq %rax, %rax
setne %sil
sete %bl
movq %rcx, %rbp
testl %ecx, %ecx
sete %r15b
cmpl %r11d, %r9d
setb %cl
testb %bl, %r15b
jne 0xde923
cmpl %r11d, %r9d
jb 0xde8a6
jmp 0xde923
movl %edx, %r9d
jmp 0xdeaa3
movl %edx, %r9d
testb %cl, %cl
je 0xde965
movl 0x24(%rsp), %eax
addl %r9d, %eax
movb $0x8, %cl
subb %al, %cl
movq $-0x1, %rax
shlq %cl, %rax
movl 0x10(%rsp), %edx
notl %edx
orl $0xff01, %edx           # imm = 0xFF01
movzwl %dx, %edx
andl %edx, %eax
movzbl (%rdi), %esi
notl %eax
shlq %cl, %r10
andl %esi, %eax
andl %edx, %r10d
orl %eax, %r10d
movq %r10, %r8
jmp 0xdeaed
movzbl (%rdi), %ecx
movl 0x10(%rsp), %ebx
andl %ecx, %ebx
movq 0x18(%rsp), %rcx
orl $0xf8, %ecx
addl %r9d, %ecx
movq %r10, %rsi
shrq %cl, %rsi
orl %ebx, %esi
movb %sil, (%rdi)
incq %rdi
subl %r11d, %r9d
jmp 0xdeaa3
testq %rax, %rax
setne %bl
jne 0xde9a9
testl %ebp, %ebp
jne 0xde9a9
movq %r10, %r11
movl %r9d, %esi
jmp 0xdea70
cmpl $0x8, %r9d
setb %cl
movl %ebp, %esi
movl %r9d, %r11d
movl $0x40, %r15d
subq %r11, %r15
cmpq %rsi, %r15
seta %sil
orb %cl, %sil
cmpb $0x1, %sil
jne 0xdea7f
cmpl %r15d, %ebp
movl %r15d, %esi
cmovbl %ebp, %esi
movq %r12, %r11
cmpl $0x3f, %esi
ja 0xdea25
movq %r14, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %r13, %rax
movq %r8, %r13
movq $-0x1, %r8
movl %esi, %ecx
shlq %cl, %r8
shlq %cl, %r10
movl %ebp, %ecx
subl %esi, %ecx
movq %r12, %r11
shrq %cl, %r11
notq %r8
andq %r8, %r11
movq %r13, %r8
movq %rax, %r13
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %r14
orq %r10, %r11
cmpl %r15d, %ebp
seta %cl
notb %bl
orb %cl, %bl
testb $0x1, %bl
jne 0xdea4b
movq 0x8(%rsp), %rcx
movl 0x4(%rcx,%r14,4), %r12d
andl %r8d, %r12d
incq %r14
subq %r13, %rax
movl %edx, %ebp
jmp 0xdea4d
subl %esi, %ebp
addl %r9d, %esi
movl %esi, %r9d
movq %r11, %r10
testq %rax, %rax
setne %bl
jne 0xde9a9
movl %esi, %r9d
movq %r11, %r10
testl %ebp, %ebp
jne 0xde9a9
xorl %eax, %eax
xorl %ebp, %ebp
cmpl $0x8, %esi
jb 0xdea9d
movl %esi, %r9d
movq %r11, %r10
movl %r9d, %r9d
addq $-0x8, %r9
movq %r10, %rsi
movl %r9d, %ecx
shrq %cl, %rsi
movb %sil, (%rdi)
incq %rdi
cmpq $0x7, %r9
ja 0xdea82
jmp 0xdeaa3
movq %r11, %r10
movl %esi, %r9d
testq %rax, %rax
jne 0xde992
leal (%r9,%rbp), %esi
cmpl $0x9, %esi
jae 0xde992
movl %ebp, %ecx
shlq %cl, %r10
subl %ebp, %edx
movl %edx, %ecx
shrq %cl, %r8
andq %r12, %r8
orq %r10, %r8
cmpl $0x7, %esi
ja 0xdeaed
testl %esi, %esi
je 0xdeaf0
movb $0x8, %cl
subb %sil, %cl
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
shll %cl, %eax
movzbl (%rdi), %edx
notl %eax
andl %edx, %eax
shlq %cl, %r8
orq %rax, %r8
movb %r8b, (%rdi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x33eeb
callq 0x33f24