// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/core/bitpackstringop32.c
// Function: gt_bsStoreNonUniformUInt32Array
void
gt_bsStoreNonUniformUInt32Array(
  BitString str, BitOffset offset, GT_UNUSED size_t numValues,
  BitOffset totalBitsLeft, unsigned numBitsList[], const uint32_t val[])
{
  /* idea: read as much as possible from val in each iteration,
   * accumulate if bitsInAccum < bitElemBits */
  size_t j = 0;
  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;
  gt_assert(numBitsList != NULL);
  gt_assert(val != NULL);
  gt_assert(numValues != 0);
  if (numBitsList[0] < (sizeof (val[0])*CHAR_BIT))
    valMask = ~(valMask << numBitsList[0]);
  gt_assert(str && val);
  gt_assert(numBitsList[0] <= 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 = numBitsList[0];
  if (totalBitsLeft)
  {
    unsigned numBits = numBitsList[++j];
    gt_assert(numBits <= sizeof (val[0])*CHAR_BIT);
    valMask = (numBits < 32)?
      ~((~(uint32_t)0) << numBits):~(uint32_t)0;
    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)
      {
        unsigned numBits = numBitsList[++j];
        gt_assert(numBits <= sizeof (val[0])*CHAR_BIT);
        valMask = (numBits < 32)?
          ~((~(uint32_t)0) << numBits):~(uint32_t)0;
        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)
      {
        unsigned numBits = numBitsList[++j];
        gt_assert(numBits <= sizeof (val[0])*CHAR_BIT);
        valMask = (numBits < 32)?
          ~((~(uint32_t)0) << numBits):~(uint32_t)0;
        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 >> (numBitsList[j] - 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
testq %r8, %r8
je 0xde7c0
testq %r9, %r9
je 0xde7c5
testq %rdx, %rdx
je 0xde7ca
movq %rcx, %rax
movq %r9, 0x8(%rsp)
movl (%r8), %r10d
movq $-0x1, %rdx
movq $-0x1, %r14
movl %r10d, %ecx
shlq %cl, %r14
cmpq $0x20, %r10
notq %r14
cmovaeq %rdx, %r14
testq %rdi, %rdi
je 0xde7cf
cmpl $0x21, %r10d
jae 0xde7d4
testq %rax, %rax
je 0xde7a7
movq 0x8(%rsp), %r9
movl (%r9), %r15d
andl %r14d, %r15d
cmpq %rax, %r10
jne 0xde4aa
xorl %r12d, %r12d
xorl %edx, %edx
xorl %r9d, %r9d
xorl %eax, %eax
jmp 0xde4e6
movl 0x4(%r8), %edx
cmpl $0x21, %edx
jae 0xde7d9
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %edx, %ecx
shll %cl, %r14d
cmpl $0x20, %edx
notl %r14d
cmovel %r11d, %r14d
movl %r14d, %r12d
andl 0x4(%r9), %r12d
leal (%rdx,%r10), %ecx
subq %rcx, %rax
movl $0x1, %r9d
movl %esi, %ebp
andl $0x7, %ebp
movq %rsi, %rcx
shrq $0x3, %rcx
addq %rcx, %rdi
testl %ebp, %ebp
je 0xde750
movq %rsi, 0x10(%rsp)
movl $0x8, %r11d
subl %ebp, %r11d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl %r11d, %ecx
shll %cl, %esi
movl %esi, 0x4(%rsp)
testq %rax, %rax
setne %sil
testl %edx, %edx
setne %cl
orb %sil, %cl
cmpl %r11d, %r10d
setb %bl
andb %bl, %cl
cmpb $0x1, %cl
jne 0xde5cc
movl $0x40, %ebx
subl %r10d, %ebx
cmpl %edx, %ebx
cmovael %edx, %ebx
movl %ebx, %ecx
shlq %cl, %r15
subl %ebx, %edx
movq %r12, %r13
movl %edx, %ecx
shrq %cl, %r13
orq %r13, %r15
cmpl $0x40, %ebx
cmovaeq %r12, %r15
testl %edx, %edx
jne 0xde5a5
testb $0x1, %sil
je 0xde5a5
movl 0x4(%r8,%r9,4), %edx
cmpq $0x21, %rdx
jae 0xde7bb
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %edx, %ecx
shll %cl, %r14d
cmpl $0x20, %edx
notl %r14d
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmovel %ecx, %r14d
movl %r14d, %r12d
movq 0x8(%rsp), %rcx
andl 0x4(%rcx,%r9,4), %r12d
incq %r9
subq %rdx, %rax
addl %ebx, %r10d
testq %rax, %rax
setne %sil
sete %cl
testl %edx, %edx
sete %r13b
cmpl %r11d, %r10d
setb %bl
testb %cl, %r13b
jne 0xde5cc
cmpl %r11d, %r10d
jb 0xde539
testb %bl, %bl
je 0xde60a
addl %r10d, %ebp
movb $0x8, %cl
subb %bpl, %cl
movq $-0x1, %rsi
shlq %cl, %rsi
movl 0x4(%rsp), %ebp
notl %ebp
orl $0xffffff01, %ebp       # imm = 0xFFFFFF01
andl %ebp, %esi
movzbl (%rdi), %r11d
notl %esi
movq %r15, %r13
shlq %cl, %r13
andl %r11d, %esi
andl %ebp, %r13d
orl %esi, %r13d
movb %r13b, (%rdi)
jmp 0xde632
movzbl (%rdi), %ecx
movl 0x4(%rsp), %ebp
andl %ecx, %ebp
movq 0x10(%rsp), %rcx
orl $0xf8, %ecx
addl %r10d, %ecx
movq %r15, %rsi
shrq %cl, %rsi
orl %ebp, %esi
movb %sil, (%rdi)
incq %rdi
subl %r11d, %r10d
testb %bl, %bl
je 0xde750
jmp 0xde7a7
testq %rax, %rax
setne %r11b
jne 0xde650
testl %edx, %edx
je 0xde727
movq %r15, %rbx
cmpl $0x8, %r10d
setb %cl
movl %edx, %esi
movl %r10d, %r15d
movl $0x40, %ebp
subq %r15, %rbp
cmpq %rsi, %rbp
seta %sil
orb %cl, %sil
cmpb $0x1, %sil
jne 0xde724
cmpl %ebp, %edx
movl %ebp, %esi
cmovbl %edx, %esi
movq %r12, %r15
cmpl $0x3f, %esi
ja 0xde6ac
movq $-0x1, %r13
movl %esi, %ecx
shlq %cl, %r13
shlq %cl, %rbx
movl %edx, %ecx
subl %esi, %ecx
movq %r12, %r15
shrq %cl, %r15
notq %r13
andq %r13, %r15
orq %rbx, %r15
cmpl %ebp, %edx
seta %cl
notb %r11b
orb %cl, %r11b
testb $0x1, %r11b
jne 0xde6fc
movl 0x4(%r8,%r9,4), %edx
cmpq $0x21, %rdx
jae 0xde7b6
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl %edx, %ecx
shll %cl, %r14d
cmpl $0x20, %edx
notl %r14d
cmovel %r11d, %r14d
movl %r14d, %r12d
movq 0x8(%rsp), %rcx
andl 0x4(%rcx,%r9,4), %r12d
incq %r9
subq %rdx, %rax
jmp 0xde6fe
subl %esi, %edx
addl %r10d, %esi
movl %esi, %r10d
movq %r15, %rbx
testq %rax, %rax
setne %r11b
jne 0xde653
movl %esi, %r10d
movq %r15, %rbx
testl %edx, %edx
jne 0xde653
jmp 0xde72a
movq %rbx, %r15
movl %r10d, %esi
cmpl $0x8, %esi
jb 0xde74d
movl %esi, %r10d
addq $-0x8, %r10
movq %r15, %rsi
movl %r10d, %ecx
shrq %cl, %rsi
movb %sil, (%rdi)
incq %rdi
cmpq $0x7, %r10
ja 0xde732
jmp 0xde750
movl %esi, %r10d
testq %rax, %rax
jne 0xde63f
leal (%rdx,%r10), %esi
cmpl $0x9, %esi
jae 0xde63f
movl %edx, %ecx
shlq %cl, %r15
movl (%r8,%r9,4), %ecx
subl %edx, %ecx
shrq %cl, %r14
andq %r12, %r14
orq %r15, %r14
cmpl $0x8, %esi
jb 0xde787
movb %r14b, (%rdi)
incq %rdi
xorl %esi, %esi
testl %esi, %esi
je 0xde7a7
movb $0x8, %cl
subb %sil, %cl
movzbl (%rdi), %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
shll %cl, %edx
shll %cl, %r14d
notl %edx
andl %eax, %edx
orl %edx, %r14d
movb %r14b, (%rdi)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x34657
callq 0x3461e
callq 0x3473b
callq 0x34702
callq 0x346c9
callq 0x34690
callq 0x345ac
callq 0x345e5