// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/eis-mrangealphabet.c
// Function: gt_newMultiRangeAlphabetEncodingUInt8
MRAEnc *
gt_newMultiRangeAlphabetEncodingUInt8(AlphabetRangeID numRanges,
                                   const AlphabetRangeSize symbolsPerRange[],
                                   const uint8_t *mappings)
{
  MRAEncUInt8 *newAlpha = NULL;
  size_t rEIOffset = offsetAlign(
    sizeof (MRAEncUInt8),
    sizeof (newAlpha->baseClass.rangeEndIndices[0]));
  size_t sPROffset = offsetAlign(
    rEIOffset  +  sizeof (newAlpha->baseClass.rangeEndIndices[0]) * numRanges,
    sizeof (newAlpha->baseClass.symbolsPerRange[0]));
  AlphabetRangeID i;
  if ((newAlpha = gt_calloc(
         sPROffset
         + sizeof (newAlpha->baseClass.symbolsPerRange[0]) * numRanges,
         1)))
  {
    newAlpha->baseClass.rangeEndIndices
      = (AlphabetRangeSize *)((char *)newAlpha + rEIOffset);
    newAlpha->baseClass.symbolsPerRange
      = (AlphabetRangeSize *)((char *)newAlpha + sPROffset);
    newAlpha->baseClass.encType = sourceUInt8;
    newAlpha->baseClass.numRanges = numRanges;
    memset(newAlpha->mappings, UNDEF_UCHAR, UINT8_MAX+1);
    memset(newAlpha->revMappings, UNDEF_UCHAR, UINT8_MAX+1);
    newAlpha->baseClass.rangeEndIndices[0] =
      newAlpha->baseClass.symbolsPerRange[0] = symbolsPerRange[0];
    for (i = 1; i < numRanges; ++i)
    {
      newAlpha->baseClass.rangeEndIndices[i] =
        newAlpha->baseClass.rangeEndIndices[i-1]
        + (newAlpha->baseClass.symbolsPerRange[i] = symbolsPerRange[i]);
    }
    for (i = 0; i <= UINT8_MAX; ++i)
    {
      newAlpha->mappings[i] = mappings[i];
      newAlpha->revMappings[mappings[i]] = i;
    }
  }
  else
  {
    if (newAlpha)
    {
      if (newAlpha->baseClass.symbolsPerRange)
        gt_free(newAlpha->baseClass.symbolsPerRange);
      if (newAlpha->baseClass.rangeEndIndices)
        gt_free(newAlpha->baseClass.rangeEndIndices);
      gt_free(newAlpha);
    }
    return NULL;
  }
  return &(newAlpha->baseClass);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, %r14
movl %edi, %r12d
movl %edi, %r13d
leaq 0x218(,%r13,2), %rax
andq $-0x4, %rax
leal (,%r12,4), %ebp
andl $0x4, %ebp
addq %rax, %rbp
leaq (,%r13,2), %rdi
addq %rbp, %rdi
leaq 0x205f08(%rip), %rdx    # 0x3a3797
movl $0x1, %esi
movl $0x31, %ecx
callq 0x10436a
movq %rax, %r15
testq %rax, %rax
je 0x19d93a
leaq 0x218(%r15), %rax
movq %rax, 0x8(%r15)
leaq (%r15,%rbp), %rax
movq %rax, 0x10(%r15)
movl $0x1, (%r15)
movl %r12d, 0x4(%r15)
leaq 0x18(%r15), %rdi
movl $0x200, %edx            # imm = 0x200
movl $0xff, %esi
callq 0x173a0
movzwl (%r14), %eax
movw %ax, (%r15,%rbp)
movw %ax, 0x218(%r15)
cmpl $0x2, %r12d
jb 0x19d91c
leaq (%r15,%rbp), %rcx
addq $0x2, %rcx
decq %r13
xorl %edx, %edx
movzwl 0x2(%r14,%rdx,2), %esi
movw %si, (%rcx,%rdx,2)
addl %esi, %eax
movw %ax, 0x21a(%r15,%rdx,2)
incq %rdx
cmpq %rdx, %r13
jne 0x19d8ff
xorl %eax, %eax
movzbl (%rbx,%rax), %ecx
movb %cl, 0x18(%r15,%rax)
movb %al, 0x118(%r15,%rcx)
incq %rax
cmpq $0x100, %rax            # imm = 0x100
jne 0x19d91e
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq