// File: /workspace/github_c_makefile_star2_O2/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 $0x18, %rsp
movq %rcx, %rax
movl %edx, %ecx
pushq $-0x1
popq %rbx
movq %rbx, %rdx
shlq %cl, %rdx
cmpl $0x20, %ecx
notq %rdx
cmovaeq %rbx, %rdx
testq %rdi, %rdi
je 0xc7576
testq %r8, %r8
je 0xc7576
cmpl $0x21, %ecx
jae 0xc75a4
movq %rsi, %r14
movl %ecx, %r9d
movq %r9, %rsi
imulq %rax, %rsi
testq %rsi, %rsi
je 0xc7567
movl %r14d, %r11d
andl $0x7, %r11d
movq %r14, %r10
shrq $0x3, %r10
movl (%r8), %r15d
andl %edx, %r15d
cmpq %r9, %rsi
movq %r8, 0x10(%rsp)
movq %r9, 0x8(%rsp)
jne 0xc7336
xorl %r12d, %r12d
xorl %r9d, %r9d
xorl %eax, %eax
xorl %ebp, %ebp
jmp 0xc734b
movl 0x4(%r8), %r12d
andl %edx, %r12d
addq $-0x2, %rax
imulq %r9, %rax
pushq $0x1
popq %rbp
movl %ecx, %r9d
addq %r10, %rdi
testl %r11d, %r11d
movl %ecx, (%rsp)
je 0xc7427
pushq $0x8
popq %r10
movl %r11d, 0x4(%rsp)
subl %r11d, %r10d
pushq $0x40
popq %r13
movl %ecx, %r11d
movl %r11d, %esi
testq %rax, %rax
sete %cl
testl %r9d, %r9d
sete %r8b
testb %cl, %r8b
jne 0xc73e1
cmpl %r10d, %esi
jae 0xc73e1
movl %r13d, %r11d
subl %esi, %r11d
cmpl %r9d, %r11d
cmovael %r9d, %r11d
movl %r11d, %ecx
shlq %cl, %r15
subl %r11d, %r9d
movq %r12, %r8
movl %r9d, %ecx
shrq %cl, %r8
orq %r8, %r15
cmpl $0x40, %r11d
cmovaeq %r12, %r15
addl %esi, %r11d
movl %r11d, %esi
testq %rax, %rax
je 0xc7370
movl %r11d, %esi
testl %r9d, %r9d
jne 0xc7370
movq 0x10(%rsp), %rcx
movl 0x4(%rcx,%rbp,4), %r12d
andl %edx, %r12d
incq %rbp
subq 0x8(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, %r9d
jmp 0xc736d
pushq $-0x1
popq %rcx
movl %ecx, %r8d
movl %r10d, %ecx
shll %cl, %r8d
movl %esi, %r11d
subl %r10d, %r11d
jae 0xc742c
movl 0x4(%rsp), %eax
addl %esi, %eax
movb $0x8, %cl
subb %al, %cl
shlq %cl, %rbx
notl %r8d
orl $0xff01, %r8d           # imm = 0xFF01
movzwl %r8w, %eax
andl %eax, %ebx
movzbl (%rdi), %edx
shlq %cl, %r15
notl %ebx
andl %edx, %ebx
andl %eax, %r15d
orl %ebx, %r15d
jmp 0xc7564
movl %ecx, %r11d
jmp 0xc744f
movzbl (%rdi), %r10d
orl $0xf8, %r14d
addl %esi, %r14d
movq %r15, %rsi
movl %r14d, %ecx
shrq %cl, %rsi
andl %r10d, %r8d
orl %r8d, %esi
movb %sil, (%rdi)
incq %rdi
pushq $0x40
popq %r8
testq %rax, %rax
jne 0xc7465
leal (%r9,%r11), %esi
cmpl $0x9, %esi
jb 0xc7523
movq %r15, %r13
movl %r11d, %ecx
testq %rax, %rax
jne 0xc7479
testl %r9d, %r9d
je 0xc74fd
cmpl $0x8, %r11d
setb %sil
movl %r9d, %r15d
movq %r8, %r10
subq %rcx, %r10
cmpq %r15, %r10
seta %r15b
orb %sil, %r15b
cmpb $0x1, %r15b
jne 0xc7512
cmpl %r10d, %r9d
movl %r10d, %esi
cmovbl %r9d, %esi
movq %r12, %r15
cmpl $0x3f, %esi
ja 0xc74cb
movq %rbx, %r14
movl %esi, %ecx
shlq %cl, %r14
shlq %cl, %r13
movl %r9d, %ecx
subl %esi, %ecx
movq %r12, %r15
shrq %cl, %r15
notq %r14
andq %r14, %r15
orq %r13, %r15
addl %esi, %r11d
testq %rax, %rax
je 0xc74d8
cmpl %r10d, %r9d
jbe 0xc74dd
subl %esi, %r9d
jmp 0xc7465
movq 0x10(%rsp), %rcx
movl 0x4(%rcx,%rbp,4), %r12d
andl %edx, %r12d
incq %rbp
subq 0x8(%rsp), %rax
movl (%rsp), %ecx
movl %ecx, %r9d
jmp 0xc7465
xorl %r9d, %r9d
jmp 0xc7512
addq $-0x8, %rcx
movq %r13, %rsi
shrq %cl, %rsi
movb %sil, (%rdi)
incq %rdi
cmpq $0x8, %rcx
jae 0xc7502
movq %r13, %r15
movl %ecx, %r11d
jmp 0xc7453
movl %r9d, %ecx
shlq %cl, %r15
movl (%rsp), %ecx
subl %r9d, %ecx
shrq %cl, %rdx
andq %r12, %rdx
orq %r15, %rdx
cmpl $0x8, %esi
jb 0xc7546
movb %dl, (%rdi)
incq %rdi
xorl %esi, %esi
jmp 0xc7538
testl %esi, %esi
je 0xc7567
movb $0x8, %cl
subb %sil, %cl
movzbl (%rdi), %eax
pushq $-0x1
popq %rsi
shll %cl, %esi
shlq %cl, %rdx
notl %esi
andl %eax, %esi
orq %rsi, %rdx
movq %rdx, %r15
movb %r15b, (%rdi)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x66a3b(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x2adf(%rip), %rsi      # 0xca066
leaq 0x2dd99(%rip), %rdx     # 0xf5327
leaq 0x2de17(%rip), %rcx     # 0xf53ac
leaq 0x2dd0b(%rip), %r8      # 0xf52a7
movl $0x184, %r9d            # imm = 0x184
jmp 0xc75d0
movq 0x66a0d(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x2ab1(%rip), %rsi      # 0xca066
leaq 0x2dd91(%rip), %rdx     # 0xf534d
leaq 0x2dde9(%rip), %rcx     # 0xf53ac
leaq 0x2dcdd(%rip), %r8      # 0xf52a7
movl $0x185, %r9d            # imm = 0x185
xorl %eax, %eax
callq 0xb8c0
callq 0xb300