// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/core/bitpackstringop64.c
// Function: gt_bsStoreNonUniformUInt64Array
void
gt_bsStoreNonUniformUInt64Array(
  BitString str, BitOffset offset, GT_UNUSED size_t numValues,
  BitOffset totalBitsLeft, unsigned numBitsList[], const uint64_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;
  GtUint64 accum, valMask = ~(GtUint64)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 < 64)?
      ~((~(uint64_t)0) << numBits):~(uint64_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 = ~(~(GtUint64)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 < 64)?
          ~((~(uint64_t)0) << numBits):~(uint64_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 &= ~(GtUint64)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)
      {
        GtUint64 mask = ~((~(GtUint64)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 < 64)?
          ~((~(uint64_t)0) << numBits):~(uint64_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)
  {
    GtUint64 mask =
      ~(GtUint64)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 0x2fd968
testq %r9, %r9
je 0x2fd96d
testq %rdx, %rdx
je 0x2fd972
movq %rcx, %rax
movq %r9, 0x8(%rsp)
movl (%r8), %r10d
movq $-0x1, %rdx
movq $-0x1, %r14
movl %r10d, %ecx
shlq %cl, %r14
cmpq $0x40, %r10
notq %r14
cmovaeq %rdx, %r14
testq %rdi, %rdi
je 0x2fd977
cmpl $0x41, %r10d
jae 0x2fd97c
testq %rax, %rax
je 0x2fd94f
movq 0x8(%rsp), %r9
movq (%r9), %r15
andq %r14, %r15
cmpq %rax, %r10
jne 0x2fd648
xorl %r12d, %r12d
xorl %edx, %edx
xorl %r9d, %r9d
xorl %eax, %eax
jmp 0x2fd689
movl 0x4(%r8), %edx
cmpq $0x41, %rdx
jae 0x2fd981
movq $-0x1, %r14
movl %edx, %ecx
shlq %cl, %r14
movq $-0x1, %rcx
cmpl $0x40, %edx
notq %r14
cmoveq %rcx, %r14
movq 0x8(%r9), %r12
andq %r14, %r12
movq %r10, %rcx
addq %rdx, %rcx
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 0x2fd8f8
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 0x2fd772
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 0x2fd74b
testb $0x1, %sil
je 0x2fd74b
movl 0x4(%r8,%r9,4), %edx
cmpq $0x41, %rdx
jae 0x2fd963
movq $-0x1, %r14
movl %edx, %ecx
shlq %cl, %r14
cmpl $0x40, %edx
notq %r14
movq $-0x1, %rcx
cmoveq %rcx, %r14
movq 0x8(%rsp), %rcx
movq 0x8(%rcx,%r9,8), %r12
incq %r9
andq %r14, %r12
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 0x2fd772
cmpl %r11d, %r10d
jb 0x2fd6dc
testb %bl, %bl
je 0x2fd7b0
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 0x2fd7d8
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 0x2fd8f8
jmp 0x2fd94f
testq %rax, %rax
setne %r11b
jne 0x2fd7f6
testl %edx, %edx
je 0x2fd8cf
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 0x2fd8cc
cmpl %ebp, %edx
movl %ebp, %esi
cmovbl %edx, %esi
movq %r12, %r15
cmpl $0x3f, %esi
ja 0x2fd852
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 0x2fd8a4
movl 0x4(%r8,%r9,4), %edx
cmpq $0x41, %rdx
jae 0x2fd95e
movq $-0x1, %r11
movq $-0x1, %r14
movl %edx, %ecx
shlq %cl, %r14
cmpl $0x40, %edx
notq %r14
cmoveq %r11, %r14
movq 0x8(%rsp), %rcx
movq 0x8(%rcx,%r9,8), %r12
incq %r9
andq %r14, %r12
subq %rdx, %rax
jmp 0x2fd8a6
subl %esi, %edx
addl %r10d, %esi
movl %esi, %r10d
movq %r15, %rbx
testq %rax, %rax
setne %r11b
jne 0x2fd7f9
movl %esi, %r10d
movq %r15, %rbx
testl %edx, %edx
jne 0x2fd7f9
jmp 0x2fd8d2
movq %rbx, %r15
movl %r10d, %esi
cmpl $0x8, %esi
jb 0x2fd8f5
movl %esi, %r10d
addq $-0x8, %r10
movq %r15, %rsi
movl %r10d, %ecx
shrq %cl, %rsi
movb %sil, (%rdi)
incq %rdi
cmpq $0x7, %r10
ja 0x2fd8da
jmp 0x2fd8f8
movl %esi, %r10d
testq %rax, %rax
jne 0x2fd7e5
leal (%rdx,%r10), %esi
cmpl $0x9, %esi
jae 0x2fd7e5
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 0x2fd92f
movb %r14b, (%rdi)
incq %rdi
xorl %esi, %esi
testl %esi, %esi
je 0x2fd94f
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 0x89df4
callq 0x89dbb
callq 0x89ed8
callq 0x89e9f
callq 0x89e66
callq 0x89e2d
callq 0x89d49
callq 0x89d82