// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/eis-seqblocktranslate.c
// Function: gt_block2IndexPair
int
gt_block2IndexPair(const struct compList *compositionTable,
                unsigned blockSize, unsigned alphabetSize,
                const Symbol *block, PermCompIndex idxOutput[2],
                unsigned *bitsOfPermIdx,
                BitString permCompPA, unsigned *compPA)
{
  unsigned bitsPerCount;
  BitOffset bitsPerComposition, bitsPerPermutation;
  BitString permCompBitString;
  gt_assert(compositionTable && idxOutput && block);
  gt_assert(blockSize > 0);
  bitsPerComposition = (bitsPerCount = compositionTable->bitsPerCount)
    * alphabetSize;
  bitsPerPermutation = compositionTable->bitsPerSymbol * blockSize;
  if (permCompPA)
    permCompBitString = permCompPA;
  else
    permCompBitString =
      gt_malloc(bitElemsAllocSize(bitsPerComposition + bitsPerPermutation)
                * sizeof (BitElem));
  {
    /* first compute composition from block */
    size_t i;
    unsigned *composition;
    if (compPA)
    {
      composition = compPA;
      memset(composition, 0, sizeof (composition[0])*alphabetSize);
    }
    else
      composition = gt_calloc(sizeof (composition[0]), alphabetSize);
    for (i = 0; i < blockSize; ++i)
    {
      ++composition[block[i]];
    }
    gt_bsStoreUniformUIntArray(permCompBitString, 0, bitsPerCount,
                            alphabetSize, composition);
    if (!compPA)
      gt_free(composition);
  }
  {
    /* do binary search for composition (simplified because the list
     * contains every composition possible and thus cmpresult will
     * become 0 at some point) */
    size_t compIndex = compositionTable->numCompositions / 2;
    size_t divStep = compIndex;
    int cmpresult;
    while ((cmpresult = gt_bsCompare(permCompBitString, 0, bitsPerComposition,
                                 compositionTable->catCompsPerms,
                                 compIndex * bitsPerComposition,
                                 bitsPerComposition)))
    {
      if (divStep > 1)
        divStep >>= 1; /* divStep /= 2 */
      if (cmpresult > 0)
        compIndex += divStep;
      else /* cmpresult < 0 */
        compIndex -= divStep;
    }
    idxOutput[0] = compIndex;
  }
  {
    const struct permList *permutation = compositionTable->permutations
      + idxOutput[0];
    if (bitsOfPermIdx)
      *bitsOfPermIdx = permutation->permIdxBits;
    if (permutation->numPermutations > 1)
    {
      /* build permutation bitstring */
      gt_bsStoreUniformSymbolArray(permCompBitString, bitsPerComposition,
                                compositionTable->bitsPerSymbol, blockSize,
                                block);
      /* do binary search for permutation */
      {
        size_t permIndex = permutation->numPermutations / 2;
        size_t divStep = permIndex;
        int cmpresult;
        while ((cmpresult = gt_bsCompare(permCompBitString, bitsPerComposition,
                                     bitsPerPermutation,
                                     compositionTable->catCompsPerms,
                                     permutation->catPermsOffset
                                     + permIndex * bitsPerPermutation,
                                     bitsPerPermutation)))
        {
          if (divStep > 1)
            divStep >>= 1; /* divStep /= 2 */
          if (cmpresult > 0)
            permIndex += divStep;
          else /* cmpresult < 0 */
            permIndex -= divStep;
        }
        idxOutput[1] = permIndex;
      }
    }
    else
        idxOutput[1] = 0;
  }
  if (!permCompPA)
    gt_free(permCompBitString);
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r9, 0x30(%rsp)
movq %rdi, 0x8(%rsp)
testq %rcx, %rcx
je 0x30e56b
cmpq $0x0, 0x8(%rsp)
je 0x30e56b
testq %r8, %r8
je 0x30e56b
movl %esi, %r12d
testl %esi, %esi
je 0x30e570
movq %rcx, %rbp
movl %edx, %ebx
movq 0x78(%rsp), %rdi
movq 0x70(%rsp), %rcx
movq 0x8(%rsp), %rax
movl 0x18(%rax), %edx
movl %edx, 0x14(%rsp)
movl %edx, %r15d
imull %ebx, %r15d
movl 0x1c(%rax), %eax
imull %r12d, %eax
movq %rax, 0x18(%rsp)
movq %rcx, %r13
testq %rcx, %rcx
movq %r8, 0x20(%rsp)
jne 0x30e371
movq 0x18(%rsp), %rax
addq %r15, %rax
movq %rdi, %r14
movq %rax, %rdi
shrq $0x3, %rdi
andl $0x7, %eax
cmpq $0x1, %rax
sbbq $-0x1, %rdi
leaq 0xd35be(%rip), %rsi     # 0x3e191f
movl $0x1cb, %edx            # imm = 0x1CB
callq 0x104226
movq %r14, %rdi
movq %rax, %r13
movl %r12d, %r14d
movl %ebx, %esi
testq %rdi, %rdi
movq %rsi, 0x28(%rsp)
je 0x30e397
leaq (,%rsi,4), %rdx
movq %rdi, %r12
xorl %esi, %esi
callq 0x173a0
movq %r12, %rbx
jmp 0x30e3b3
movq %rdi, %rbx
leaq 0xd357e(%rip), %rdx     # 0x3e191f
movl $0x4, %edi
movl $0x1d6, %ecx            # imm = 0x1D6
callq 0x10436a
movq %rax, %r12
movl %r14d, %r14d
xorl %eax, %eax
movzbl (%rbp,%rax), %ecx
incl (%r12,%rcx,4)
incq %rax
cmpq %rax, %r14
jne 0x30e3b8
movq %r13, %rdi
xorl %esi, %esi
movl 0x14(%rsp), %edx
movq 0x28(%rsp), %rcx
movq %r12, %r8
callq 0x2f2c61
testq %rbx, %rbx
jne 0x30e3f8
leaq 0xd3534(%rip), %rsi     # 0x3e191f
movq %r12, %rdi
movl $0x1de, %edx            # imm = 0x1DE
callq 0x1045eb
movq 0x8(%rsp), %rax
movq (%rax), %r12
movq 0x10(%rax), %rcx
shrq %r12
movq %r12, %r8
imulq %r15, %r8
movq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r15, %r9
callq 0x2f0a3b
testl %eax, %eax
je 0x30e465
movq %r12, %rbx
cmpq $0x2, %r12
setae %cl
shrq %cl, %r12
movq %r12, %rcx
testl %eax, %eax
jg 0x30e43c
movq %r12, %rcx
negq %rcx
addq %rcx, %rbx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rbx, %r8
imulq %r15, %r8
movq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r15, %r9
callq 0x2f0a3b
testl %eax, %eax
jne 0x30e425
jmp 0x30e468
movq %r12, %rbx
movq 0x20(%rsp), %rcx
movl %ebx, (%rcx)
movl %ebx, %eax
leaq (%rax,%rax,2), %r12
shlq $0x3, %r12
movq 0x8(%rsp), %rax
addq 0x8(%rax), %r12
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
je 0x30e493
movl 0x8(%r12), %eax
movl %eax, (%rdx)
xorl %ebx, %ebx
cmpq $0x2, (%r12)
jb 0x30e53b
movq 0x8(%rsp), %rbx
movl 0x1c(%rbx), %edx
movq %r13, %rdi
movq %r15, %rsi
movq %r14, %rcx
movq %rbp, %r8
callq 0x2f4f1a
movq (%r12), %r14
shrq %r14
movq 0x10(%rbx), %rcx
movq %r14, %r8
movq 0x18(%rsp), %rbp
imulq %rbp, %r8
addq 0x10(%r12), %r8
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %rbp, %r9
callq 0x2f0a3b
testl %eax, %eax
je 0x30e533
movq %r14, %rbx
cmpq $0x2, %r14
setae %cl
shrq %cl, %r14
movq %r14, %rcx
testl %eax, %eax
jg 0x30e504
movq %r14, %rcx
negq %rcx
addq %rcx, %rbx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq %rbx, %r8
imulq %rbp, %r8
addq 0x10(%r12), %r8
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %rbp, %r9
callq 0x2f0a3b
testl %eax, %eax
jne 0x30e4ed
jmp 0x30e536
movq %r14, %rbx
movq 0x20(%rsp), %rcx
movl %ebx, 0x4(%rcx)
cmpq $0x0, 0x70(%rsp)
jne 0x30e55a
leaq 0xd33d2(%rip), %rsi     # 0x3e191f
movq %r13, %rdi
movl $0x21a, %edx            # imm = 0x21A
callq 0x1045eb
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x903bf
callq 0x903f8
nopl (%rax)