// File: /workspace/github_c_makefile_star2_O2/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 0x1fadc3(%rip), %rdx    # 0x343b0e
pushq $0x1
popq %rsi
pushq $0x31
popq %rcx
callq 0x9334a
movq %rax, %r15
testq %rax, %rax
je 0x148df1
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 0x17380
movzwl (%r14), %eax
movw %ax, (%r15,%rbp)
movw %ax, 0x218(%r15)
leaq (%r15,%rbp), %rcx
addq $0x2, %rcx
xorl %edx, %edx
leaq 0x1(%rdx), %rsi
cmpq %r13, %rsi
jae 0x148dd1
movzwl 0x2(%r14,%rdx,2), %edi
movw %di, (%rcx,%rdx,2)
addl %edi, %eax
movw %ax, 0x21a(%r15,%rdx,2)
movq %rsi, %rdx
jmp 0x148dae
xorl %eax, %eax
cmpq $0x100, %rax            # imm = 0x100
je 0x148df1
movzbl (%rbx,%rax), %ecx
movb %cl, 0x18(%r15,%rax)
movb %al, 0x118(%r15,%rcx)
incq %rax
jmp 0x148dd3
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq