// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/core/bitpackstringop64.c
// Function: gt_bsGetNonUniformInt64Array
void
gt_bsGetNonUniformInt64Array(
  constBitString str, BitOffset offset, size_t numValues,
  BitOffset numBitsTotal, unsigned numBitsList[], int64_t val[])
{
  /* idea: read as much as possible from str in each iteration,
   * accumulate if bitsLeft < numBits */
  size_t j = 0;
  BitOffset totalBitsLeft = numBitsTotal;
  size_t elemStart = offset/bitElemBits;
  unsigned bitTop = offset%bitElemBits,
    bitsRead = 0; /*< how many bits in current *p are read */
  const BitElem *p = str + elemStart;
  unsigned bitsInAccum = 0;
  GtUint64 accum = 0;
  gt_assert(str && val);
  /* user requested zero values, ugly but must be handled, since legal */
  if (!totalBitsLeft)
  {
    return;
  }
  /* get bits of first element if not aligned */
  if (bitTop)
  {
    GtUint64 mask; /*< all of the bits we want to get from *p */
    unsigned bits2Read = GT_MIN(bitElemBits - bitTop, totalBitsLeft);
    unsigned unreadRightBits = (bitElemBits - bitTop - bits2Read);
    mask = (~((~(GtUint64)0) << bits2Read)) << unreadRightBits;
    accum = ((*p++) & mask) >> unreadRightBits;
    bitsInAccum += bits2Read;
    totalBitsLeft -= bits2Read;
  }
  while (j < numValues)
  {
    while (bitsInAccum < numBitsList[j] && totalBitsLeft)
    {
      unsigned bits2Read, bitsFree = sizeof (accum)*CHAR_BIT - bitsInAccum;
      GtUint64 mask;
      bits2Read = GT_MIN3(bitsFree, bitElemBits - bitsRead, totalBitsLeft);
      mask = (~((~(GtUint64)0) << bits2Read));
      accum = accum << bits2Read | (((*p) >> (bitElemBits
                                              - bits2Read - bitsRead)) & mask);
      bitsInAccum += bits2Read;
      totalBitsLeft -= bits2Read;
      /* all of *p consumed? */
      if ((bitsRead += bits2Read) == bitElemBits)
      {
        ++p, bitsRead = 0;
      }
    }
    {
      unsigned numBits;
      /* now we have enough bits in accum */
      while (j < numValues && bitsInAccum >= (numBits = numBitsList[j]))
      {
        GtUint64 valMask = (numBits < 64)
          ? ~((~(GtUint64)0) << numBits) : ~(GtUint64)0;
        int64_t m = (int64_t)1 << (numBits - 1);
        gt_assert(numBits <= sizeof (val[0])*CHAR_BIT);
        val[j++] = ((((accum >> (bitsInAccum - numBits)) & valMask)
                              ^ m) - m);
        bitsInAccum -= numBits;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r8, 0x8(%rsp)
testq %rdi, %rdi
je 0x28e612
testq %r9, %r9
je 0x28e612
movq %rcx, %rax
movq %r9, 0x10(%rsp)
testq %rcx, %rcx
je 0x28e5cb
movq %rsi, %rcx
shrq $0x3, %rcx
andl $0x7, %esi
addq %rcx, %rdi
pushq $0x8
popq %r8
testl %esi, %esi
je 0x28e4d7
movl %r8d, %r10d
subl %esi, %r10d
cmpq %rax, %r10
movq %rax, %rsi
cmovbq %r10, %rsi
subl %esi, %r10d
pushq $-0x1
popq %r14
movl %esi, %ecx
shll %cl, %r14d
notl %r14d
movl %r10d, %ecx
shlq %cl, %r14
movzbl (%rdi), %ecx
incq %rdi
andl %ecx, %r14d
movl %r10d, %ecx
shrq %cl, %r14
subq %rsi, %rax
jmp 0x28e4dc
xorl %r14d, %r14d
xorl %esi, %esi
pushq $0x40
popq %r15
pushq $-0x1
popq %r9
xorl %r13d, %r13d
xorl %ebx, %ebx
cmpq %rdx, %rbx
jae 0x28e5cb
movq 0x8(%rsp), %rcx
movl (%rcx,%rbx,4), %r11d
cmpl %r11d, %esi
jae 0x28e5af
testq %rax, %rax
je 0x28e5af
movl %r15d, %ecx
subl %esi, %ecx
movl %r8d, %r10d
subl %r13d, %r10d
cmpl %r10d, %ecx
cmovbl %ecx, %r10d
cmpq %r10, %rax
cmovbq %rax, %r10
movq %r9, %r12
movl %r10d, %ecx
shlq %cl, %r12
shlq %cl, %r14
movzbl (%rdi), %ebp
addl %r10d, %r13d
movb $0x8, %cl
subb %r13b, %cl
shrl %cl, %ebp
notl %r12d
andl %r12d, %ebp
orq %rbp, %r14
addl %r10d, %esi
subq %r10, %rax
xorl %ecx, %ecx
cmpl $0x8, %r13d
sete %cl
movl $0x0, %r10d
cmovel %r10d, %r13d
addq %rcx, %rdi
jmp 0x28e4fb
cmpl $0x41, %r10d
jae 0x28e5da
leal -0x1(%r10), %r11d
pushq $0x1
popq %r12
movl %r11d, %ecx
shlq %cl, %r12
movq %r9, %rbp
movl %r10d, %ecx
shlq %cl, %rbp
cmpq $0x40, %r10
notq %rbp
cmoveq %r9, %rbp
subl %r10d, %esi
movq %r14, %r10
movl %esi, %ecx
shrq %cl, %r10
andq %rbp, %r10
btcq %r11, %r10
subq %r12, %r10
movq 0x10(%rsp), %rcx
movq %r10, (%rcx,%rbx,8)
incq %rbx
cmpq %rdx, %rbx
jae 0x28e4e9
movq 0x8(%rsp), %rcx
movl (%rcx,%rbx,4), %r10d
cmpl %r10d, %esi
jae 0x28e566
jmp 0x28e4e9
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x1a9987(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x56a28(%rip), %rsi     # 0x2e5013
leaq 0xec7a7(%rip), %rdx     # 0x37ad99
leaq 0xeca8e(%rip), %rcx     # 0x37b087
leaq 0xeca20(%rip), %r8      # 0x37b020
movl $0x159, %r9d            # imm = 0x159
xorl %eax, %eax
callq 0x17a50
callq 0x17390
movq 0x1a994f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x569f0(%rip), %rsi     # 0x2e5013
leaq 0xec749(%rip), %rdx     # 0x37ad73
leaq 0xeca56(%rip), %rcx     # 0x37b087
leaq 0xec9e8(%rip), %r8      # 0x37b020
movl $0x12e, %r9d            # imm = 0x12E
jmp 0x28e606