// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
movq %r8, 0x8(%rsp)
testq %r8, %r8
je 0x28ecd4
testq %r9, %r9
je 0x28ed02
testq %rdx, %rdx
je 0x28ed30
movq %rcx, %rax
movq 0x8(%rsp), %rcx
movl (%rcx), %r10d
pushq $-0x1
popq %rbx
movq %rbx, %r14
movl %r10d, %ecx
shlq %cl, %r14
cmpq $0x40, %r10
notq %r14
cmovaeq %rbx, %r14
testq %rdi, %rdi
je 0x28ed61
cmpl $0x41, %r10d
jae 0x28ed92
testq %rax, %rax
je 0x28ec8d
movq (%r9), %r13
andq %r14, %r13
cmpq %rax, %r10
jne 0x28e9ef
xorl %r12d, %r12d
xorl %edx, %edx
xorl %r8d, %r8d
xorl %eax, %eax
jmp 0x28ea27
movq 0x8(%rsp), %rcx
movl 0x4(%rcx), %edx
cmpq $0x41, %rdx
jae 0x28edf4
movq %rbx, %r14
movl %edx, %ecx
shlq %cl, %r14
cmpl $0x40, %edx
notq %r14
cmoveq %rbx, %r14
movq 0x8(%r9), %r12
andq %r14, %r12
movq %r10, %rcx
addq %rdx, %rcx
subq %rcx, %rax
pushq $0x1
popq %r8
movl %esi, %ebp
andl $0x7, %ebp
movq %rsi, %rcx
shrq $0x3, %rcx
addq %rcx, %rdi
pushq $-0x1
popq %rcx
testl %ebp, %ebp
movq %r9, 0x18(%rsp)
je 0x28eb54
movq %rsi, 0x20(%rsp)
pushq $0x8
popq %r11
movl %ebp, 0x14(%rsp)
subl %ebp, %r11d
movl %ecx, %r9d
movl %r11d, %ecx
shll %cl, %r9d
pushq $0x40
popq %rsi
movl %r10d, %r15d
testq %rax, %rax
sete %cl
testl %edx, %edx
sete %r10b
testb %cl, %r10b
jne 0x28eaf3
cmpl %r11d, %r15d
jae 0x28eaf3
movl %esi, %r10d
subl %r15d, %r10d
cmpl %edx, %r10d
cmovael %edx, %r10d
movl %r10d, %ecx
shlq %cl, %r13
subl %r10d, %edx
movq %r12, %rbp
movl %edx, %ecx
shrq %cl, %rbp
orq %rbp, %r13
cmpl $0x40, %r10d
cmovaeq %r12, %r13
addl %r15d, %r10d
movl %r10d, %r15d
testl %edx, %edx
jne 0x28ea65
movl %r10d, %r15d
testq %rax, %rax
je 0x28ea65
movq 0x8(%rsp), %rcx
movl 0x4(%rcx,%r8,4), %edx
cmpq $0x41, %rdx
jae 0x28edc3
incq %r8
movq %rbx, %r14
movl %edx, %ecx
shlq %cl, %r14
cmpl $0x40, %edx
notq %r14
cmoveq %rbx, %r14
movq 0x18(%rsp), %rcx
movq (%rcx,%r8,8), %r12
andq %r14, %r12
subq %rdx, %rax
jmp 0x28ea62
movl %r15d, %r10d
subl %r11d, %r10d
jae 0x28eb2e
movl 0x14(%rsp), %eax
addl %r15d, %eax
movb $0x8, %cl
subb %al, %cl
shlq %cl, %rbx
notl %r9d
orl $0xff01, %r9d           # imm = 0xFF01
movzwl %r9w, %eax
andl %eax, %ebx
movzbl (%rdi), %edx
shlq %cl, %r13
notl %ebx
andl %edx, %ebx
andl %eax, %r13d
orl %ebx, %r13d
jmp 0x28ec8a
movzbl (%rdi), %esi
movq 0x20(%rsp), %rcx
orl $0xf8, %ecx
addl %r15d, %ecx
movl %r9d, %r11d
movq %r13, %r9
shrq %cl, %r9
andl %esi, %r11d
orl %r11d, %r9d
movb %r9b, (%rdi)
incq %rdi
pushq $0x40
popq %r11
testq %rax, %rax
jne 0x28eb6a
leal (%rdx,%r10), %esi
cmpl $0x9, %esi
jb 0x28ec44
movq %r13, %r15
movl %r10d, %ecx
testq %rax, %rax
jne 0x28eb7d
testl %edx, %edx
je 0x28ec1f
cmpl $0x8, %r10d
setb %sil
movl %edx, %r13d
movq %r11, %r9
subq %rcx, %r9
cmpq %r13, %r9
seta %bpl
orb %sil, %bpl
cmpb $0x1, %bpl
jne 0x28ec33
cmpl %r9d, %edx
movl %r9d, %esi
cmovbl %edx, %esi
movq %r12, %r13
cmpl $0x3f, %esi
ja 0x28ebd1
movq %rbx, %rbp
movl %esi, %ecx
shlq %cl, %rbp
shlq %cl, %r15
movl %edx, %ecx
subl %esi, %ecx
movq %r12, %r13
shrq %cl, %r13
notq %rbp
andq %rbp, %r13
orq %r15, %r13
addl %esi, %r10d
cmpl %r9d, %edx
ja 0x28ebde
testq %rax, %rax
jne 0x28ebe2
subl %esi, %edx
jmp 0x28eb6a
movq 0x8(%rsp), %rcx
movl 0x4(%rcx,%r8,4), %edx
cmpq $0x41, %rdx
jae 0x28ec9c
incq %r8
movq %rbx, %r14
movl %edx, %ecx
shlq %cl, %r14
cmpl $0x40, %edx
notq %r14
cmoveq %rbx, %r14
movq 0x18(%rsp), %rcx
movq (%rcx,%r8,8), %r12
andq %r14, %r12
subq %rdx, %rax
jmp 0x28eb6a
xorl %edx, %edx
jmp 0x28ec33
addq $-0x8, %rcx
movq %r15, %rsi
shrq %cl, %rsi
movb %sil, (%rdi)
incq %rdi
cmpq $0x8, %rcx
jae 0x28ec23
movq %r15, %r13
movl %ecx, %r10d
jmp 0x28eb58
movl %edx, %ecx
shlq %cl, %r13
movq 0x8(%rsp), %rax
movl (%rax,%r8,4), %ecx
subl %edx, %ecx
shrq %cl, %r14
andq %r12, %r14
orq %r13, %r14
pushq $-0x1
popq %rdx
cmpl $0x8, %esi
jb 0x28ec6f
movb %r14b, (%rdi)
incq %rdi
xorl %esi, %esi
jmp 0x28ec60
testl %esi, %esi
je 0x28ec8d
movb $0x8, %cl
subb %sil, %cl
movzbl (%rdi), %eax
shll %cl, %edx
shlq %cl, %r14
notl %edx
andl %eax, %edx
orq %rdx, %r14
movq %r14, %r13
movb %r13b, (%rdi)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1a92c5(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x56366(%rip), %rsi     # 0x2e5013
leaq 0xec0e5(%rip), %rdx     # 0x37ad99
leaq 0xec406(%rip), %rcx     # 0x37b0c1
leaq 0xec35e(%rip), %r8      # 0x37b020
movl $0x25a, %r9d            # imm = 0x25A
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x1a928d(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x5632e(%rip), %rsi     # 0x2e5013
leaq 0xec129(%rip), %rdx     # 0x37ae15
leaq 0xec3ce(%rip), %rcx     # 0x37b0c1
leaq 0xec326(%rip), %r8      # 0x37b020
movl $0x1fb, %r9d            # imm = 0x1FB
jmp 0x28ecc8
movq 0x1a925f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x56300(%rip), %rsi     # 0x2e5013
leaq 0xb5e4b(%rip), %rdx     # 0x344b65
leaq 0xec3a0(%rip), %rcx     # 0x37b0c1
leaq 0xec2f8(%rip), %r8      # 0x37b020
movl $0x1fc, %r9d            # imm = 0x1FC
jmp 0x28ecc8
movq 0x1a9231(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x562d2(%rip), %rsi     # 0x2e5013
leaq 0xec101(%rip), %rdx     # 0x37ae49
leaq 0xec372(%rip), %rcx     # 0x37b0c1
leaq 0xec2ca(%rip), %r8      # 0x37b020
movl $0x1fd, %r9d            # imm = 0x1FD
jmp 0x28ecc8
movq 0x1a9200(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x562a1(%rip), %rsi     # 0x2e5013
leaq 0xebffa(%rip), %rdx     # 0x37ad73
leaq 0xec341(%rip), %rcx     # 0x37b0c1
leaq 0xec299(%rip), %r8      # 0x37b020
movl $0x200, %r9d            # imm = 0x200
jmp 0x28ecc8
movq 0x1a91cf(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x56270(%rip), %rsi     # 0x2e5013
leaq 0xec0ae(%rip), %rdx     # 0x37ae58
leaq 0xec310(%rip), %rcx     # 0x37b0c1
leaq 0xec268(%rip), %r8      # 0x37b020
movl $0x201, %r9d            # imm = 0x201
jmp 0x28ecc8
movq 0x1a919e(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x5623f(%rip), %rsi     # 0x2e5013
leaq 0xebfbe(%rip), %rdx     # 0x37ad99
leaq 0xec2df(%rip), %rcx     # 0x37b0c1
leaq 0xec237(%rip), %r8      # 0x37b020
movl $0x22c, %r9d            # imm = 0x22C
jmp 0x28ecc8
movq 0x1a916d(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x5620e(%rip), %rsi     # 0x2e5013
leaq 0xebf8d(%rip), %rdx     # 0x37ad99
leaq 0xec2ae(%rip), %rcx     # 0x37b0c1
leaq 0xec206(%rip), %r8      # 0x37b020
movl $0x20c, %r9d            # imm = 0x20C
jmp 0x28ecc8