// File: /workspace/github_c_makefile_star2_O2/genometools[P]genometools/src/extended/editscript.c
// Function: editscript_space_add_length
static inline void editscript_space_add_length(GtEditscript *es,
                                               GtEditscriptPos *fillpos,
                                               GtBitsequence value)
{
  /* scheme: [1111][x][x][x][x] first store consecutive ones for each element
     needed, (like elias gamma) then store the value split up to chunks of
     element size */
  /* Idea: this could be made faster with lookup-tables for the filling of most
     significant bits. */
  uint32_t num_elems = 0,
           shift;
  GtBitsequence tmp = value;

  /* needs just one element not starting with 1, store it */
  if (tmp < GT_EDITSCRIPT_FIRSTMASK(es)) {
    editscript_space_add_next(es, fillpos, tmp);
  }
  else {
    /* count the number elements needed */
    while (tmp != 0) {
      num_elems++;
      tmp >>= es->entry_size;
    }

    /* write number of entries in unary */
    tmp = num_elems;
    /* write full 1-entries */
    while (tmp >= es->entry_size) {
      editscript_space_add_next(es, fillpos, GT_EDITSCRIPT_FULLMASK(es));
      tmp -= es->entry_size;
    }
    if (tmp != 0) {
      /* write tmp 1 bits at most siginficant positions, e.g. entry_size=4,
         tmp=3: [1110]
         left shift by number of zeros, mask with entry_size 1bits.
      */
      tmp = (GT_EDITSCRIPT_FULLMASK(es) << (es->entry_size - tmp)) &
        GT_EDITSCRIPT_FULLMASK(es);
    }
    /* tmp contains either the remaining bits or one zero element to seperated
     */
    editscript_space_add_next(es, fillpos, tmp);

    /* store actual value */
    shift = (num_elems * es->entry_size);
    while (num_elems != 0) {
      num_elems--;
      shift -= es->entry_size;
      editscript_space_add_next(es, fillpos, (value >> (GtBitsequence) shift) &
                                GT_EDITSCRIPT_FULLMASK(es));
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movq %rdi, %r15
movzbl 0x15(%rdi), %eax
leal -0x1(%rax), %ecx
movq %rdx, %rsi
shrq %cl, %rsi
testq %rsi, %rsi
je 0xd0ebf
xorl %ebp, %ebp
movq %rdx, %rsi
testq %rsi, %rsi
je 0xd0e6e
movl %eax, %ecx
shrq %cl, %rsi
decl %ebp
jmp 0xd0e60
movq %rdx, (%rsp)
movl %ebp, %ebx
negl %ebx
pushq $-0x1
popq %r13
movq %rbx, %r12
movzbl %al, %ecx
cmpq %r12, %rcx
ja 0xd0ea3
movq %r13, %rdx
shlq %cl, %rdx
notq %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xcfd6f
movzbl 0x15(%r15), %eax
subq %rax, %r12
jmp 0xd0e7d
testq %r12, %r12
je 0xd0ed8
movq %r13, %rax
shlq %cl, %rax
notq %rax
subl %r12d, %ecx
movq %rax, %rdx
shlq %cl, %rdx
andq %rax, %rdx
jmp 0xd0eda
movq %r15, %rdi
movq %r14, %rsi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xcfd6f
xorl %edx, %edx
movq (%rsp), %r12
movq %r15, %rdi
movq %r14, %rsi
callq 0xcfd6f
movzbl 0x15(%r15), %eax
imull %eax, %ebx
testl %ebp, %ebp
je 0xd0f21
movzbl 0x15(%r15), %eax
subl %eax, %ebx
movq %r12, %rsi
movl %ebx, %ecx
shrq %cl, %rsi
movq %r13, %rdx
movl %eax, %ecx
shlq %cl, %rdx
notq %rdx
andq %rsi, %rdx
movq %r15, %rdi
movq %r14, %rsi
callq 0xcfd6f
incl %ebp
jmp 0xd0ef1
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq