// File: /workspace/github_c_makefile_star2_O0/genometools[P]genometools/src/core/bitpackstringop32.c
// Function: gt_bsStoreUInt32
void
gt_bsStoreUInt32(BitString str, BitOffset offset,
                 unsigned numBits, uint32_t val)
{
  unsigned bitsLeft = numBits,
    bitTop = offset%bitElemBits;
  size_t elemStart = offset/bitElemBits;
  BitElem *p = str + elemStart;
  gt_assert(str);
  gt_assert(numBits <= sizeof (val)*CHAR_BIT);
  /* set bits of first element, accounting for bits to be preserved */
  if (bitTop)
  {
    GtUword mask = ~(GtUword)0;
    if (bitElemBits < (sizeof (GtUword)*CHAR_BIT))
    {
      mask <<= bitElemBits;
    }
    else
    {
      mask = 0;
    }
    mask = (~mask) >> bitTop;
    if (numBits < bitElemBits - bitTop)
    {
      unsigned backShift = bitElemBits - numBits - bitTop;
      mask &= ~(GtUword)0 << backShift;
      *p = (*p & ~mask) | ((val << backShift) & mask);
      /* TODO: try wether  r = a ^ ((a ^ b) & mask) is faster, see below */
      return;
    }
    else
    {
      bitsLeft -= bitElemBits - bitTop;
      *p = (*p & ~mask) | ((val >> bitsLeft) & mask);
      ++p;
    }
  }
  /* set bits for intervening elems */
  while (bitsLeft >= bitElemBits)
  {
    bitsLeft -= bitElemBits;
    *p++ = val >> bitsLeft;
  }
  /* set bits for last elem */
  if (bitsLeft)
  {
    GtUword mask =
      ((~(GtUword)0)<<(bitElemBits - bitsLeft));
    if (bitElemBits < (sizeof (GtUword)*CHAR_BIT))
      mask &= (~(~(GtUword)0<<bitElemBits));
    *p = (*p & ~mask) | ((val << (bitElemBits - bitsLeft)) & mask);
  }
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movl %ecx, 0x30(%rsp)
movl 0x34(%rsp), %eax
movl %eax, 0x2c(%rsp)
movq 0x38(%rsp), %rax
andq $0x7, %rax
movl %eax, 0x28(%rsp)
movq 0x38(%rsp), %rax
shrq $0x3, %rax
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
addq 0x20(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x156e48
movq 0x5d1c1(%rip), %rax     # 0x1b3fd8
movq (%rax), %rdi
leaq 0x7245(%rip), %rsi      # 0x15e066
leaq 0x9bac(%rip), %rdx      # 0x1609d4
leaq 0x38086(%rip), %rcx     # 0x18eeb5
leaq 0x38031(%rip), %r8      # 0x18ee67
movl $0x49, %r9d
movb $0x0, %al
callq 0xb890
callq 0xb2e0
jmp 0x156e4a
jmp 0x156e4c
movl 0x34(%rsp), %eax
cmpq $0x20, %rax
jbe 0x156e8e
movq 0x5d17b(%rip), %rax     # 0x1b3fd8
movq (%rax), %rdi
leaq 0x71ff(%rip), %rsi      # 0x15e066
leaq 0x38058(%rip), %rdx     # 0x18eec6
leaq 0x38040(%rip), %rcx     # 0x18eeb5
leaq 0x37feb(%rip), %r8      # 0x18ee67
movl $0x4a, %r9d
movb $0x0, %al
callq 0xb890
callq 0xb2e0
jmp 0x156e90
cmpl $0x0, 0x28(%rsp)
je 0x156f91
movq $-0x1, 0x10(%rsp)
movq 0x10(%rsp), %rax
shlq $0x8, %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
xorq $-0x1, %rax
movl 0x28(%rsp), %ecx
shrq %cl, %rax
movq %rax, 0x10(%rsp)
movl 0x34(%rsp), %eax
movl $0x8, %ecx
subl 0x28(%rsp), %ecx
cmpl %ecx, %eax
jae 0x156f3b
movl $0x8, %eax
subl 0x34(%rsp), %eax
subl 0x28(%rsp), %eax
movl %eax, 0xc(%rsp)
movl 0xc(%rsp), %eax
movl %eax, %ecx
movq $-0x1, %rax
shlq %cl, %rax
andq 0x10(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
movq 0x10(%rsp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movl 0x30(%rsp), %edx
movl 0xc(%rsp), %ecx
shll %cl, %edx
movl %edx, %ecx
movl %ecx, %ecx
andq 0x10(%rsp), %rcx
orq %rcx, %rax
movb %al, %cl
movq 0x18(%rsp), %rax
movb %cl, (%rax)
jmp 0x15702c
movl $0x8, %ecx
subl 0x28(%rsp), %ecx
movl 0x2c(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x2c(%rsp)
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
movq 0x10(%rsp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movl 0x30(%rsp), %edx
movl 0x2c(%rsp), %ecx
shrl %cl, %edx
movl %edx, %ecx
movl %ecx, %ecx
andq 0x10(%rsp), %rcx
orq %rcx, %rax
movb %al, %cl
movq 0x18(%rsp), %rax
movb %cl, (%rax)
movq 0x18(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x18(%rsp)
jmp 0x156f91
jmp 0x156f93
cmpl $0x8, 0x2c(%rsp)
jb 0x156fc6
movl 0x2c(%rsp), %eax
subl $0x8, %eax
movl %eax, 0x2c(%rsp)
movl 0x30(%rsp), %eax
movl 0x2c(%rsp), %ecx
shrl %cl, %eax
movb %al, %cl
movq 0x18(%rsp), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, 0x18(%rsp)
movb %cl, (%rax)
jmp 0x156f93
cmpl $0x0, 0x2c(%rsp)
je 0x15702c
movl $0x8, %eax
subl 0x2c(%rsp), %eax
movl %eax, %eax
movl %eax, %ecx
movq $-0x1, %rax
shlq %cl, %rax
movq %rax, (%rsp)
movq (%rsp), %rax
andq $0xff, %rax
movq %rax, (%rsp)
movq 0x18(%rsp), %rax
movzbl (%rax), %eax
movq (%rsp), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
movl 0x30(%rsp), %edx
movl $0x8, %ecx
subl 0x2c(%rsp), %ecx
shll %cl, %edx
movl %edx, %ecx
movl %ecx, %ecx
andq (%rsp), %rcx
orq %rcx, %rax
movb %al, %cl
movq 0x18(%rsp), %rax
movb %cl, (%rax)
addq $0x48, %rsp
retq
nopw %cs:(%rax,%rax)