// File: /workspace/github_c_makefile_star2_O1/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
testq %rcx, %rcx
je 0x318707
movq %rdi, %r14
testq %rdi, %rdi
je 0x318707
testq %r8, %r8
je 0x318707
movq %r9, 0x30(%rsp)
testl %esi, %esi
je 0x31870c
movq %rcx, %r12
movl %edx, %ebx
movq 0x78(%rsp), %rbp
movq 0x70(%rsp), %rax
movl 0x18(%r14), %ecx
movl %ecx, 0x1c(%rsp)
movl %ecx, %r15d
imull %edx, %r15d
movl 0x1c(%r14), %ecx
movl %esi, 0x8(%rsp)
imull %esi, %ecx
movq %rcx, 0x10(%rsp)
movq %rax, %r13
testq %rax, %rax
movq %r8, 0x20(%rsp)
jne 0x31851d
movq 0x10(%rsp), %rax
addq %r15, %rax
movq %rax, %rdi
shrq $0x3, %rdi
andl $0x7, %eax
cmpq $0x1, %rax
sbbq $-0x1, %rdi
leaq 0xd2aff(%rip), %rsi     # 0x3eb00f
movl $0x1cb, %edx            # imm = 0x1CB
callq 0x1092b2
movq %rax, %r13
movl %ebx, %esi
testq %rbp, %rbp
movq %rbp, %rbx
movq %rsi, 0x28(%rsp)
je 0x318543
leaq (,%rsi,4), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x173a0
movq %rbx, %rbp
jmp 0x31855f
movq %rbx, %rbp
leaq 0xd2ac2(%rip), %rdx     # 0x3eb00f
movl $0x4, %edi
movl $0x1d6, %ecx            # imm = 0x1D6
callq 0x1093ef
movq %rax, %rbx
movl 0x8(%rsp), %eax
cmpq $0x1, %rax
movq %rax, 0x8(%rsp)
adcq $0x0, %rax
xorl %ecx, %ecx
movzbl (%r12,%rcx), %edx
incl (%rbx,%rdx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x318572
movq %r13, %rdi
xorl %esi, %esi
movl 0x1c(%rsp), %edx
movq 0x28(%rsp), %rcx
movq %rbx, %r8
callq 0x2fc0ab
testq %rbp, %rbp
jne 0x3185b1
leaq 0xd2a6b(%rip), %rsi     # 0x3eb00f
movq %rbx, %rdi
movl $0x1de, %edx            # imm = 0x1DE
callq 0x109670
movq (%r14), %rbx
movq 0x10(%r14), %rcx
shrq %rbx
movq %rbx, %r8
imulq %r15, %r8
movq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r15, %r9
callq 0x2f9d9f
testl %eax, %eax
je 0x318614
movq %rbx, %rbp
cmpq $0x2, %rbx
setae %cl
shrq %cl, %rbx
movq %rbx, %rcx
testl %eax, %eax
jg 0x3185f0
movq %rbx, %rcx
negq %rcx
addq %rcx, %rbp
movq 0x10(%r14), %rcx
movq %rbp, %r8
imulq %r15, %r8
movq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r15, %r9
callq 0x2f9d9f
testl %eax, %eax
jne 0x3185d9
jmp 0x318617
movq %rbx, %rbp
movq 0x20(%rsp), %rcx
movl %ebp, (%rcx)
movl %ebp, %eax
leaq (%rax,%rax,2), %rbx
shlq $0x3, %rbx
addq 0x8(%r14), %rbx
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
je 0x31863b
movl 0x8(%rbx), %eax
movl %eax, (%rdx)
xorl %ebp, %ebp
cmpq $0x2, (%rbx)
jb 0x3186d7
movl 0x1c(%r14), %edx
movq %r13, %rdi
movq %r15, %rsi
movq 0x8(%rsp), %rcx
movq %r12, %r8
callq 0x2fe3fd
movq (%rbx), %r12
shrq %r12
movq 0x10(%r14), %rcx
movq %r12, %r8
movq 0x10(%rsp), %rdx
imulq %rdx, %r8
addq 0x10(%rbx), %r8
movq %r13, %rdi
movq %r15, %rsi
movq %rdx, %r9
callq 0x2f9d9f
testl %eax, %eax
je 0x3186cf
movq %r12, %rbp
cmpq $0x2, %r12
setae %cl
shrq %cl, %r12
movq %r12, %rcx
testl %eax, %eax
jg 0x3186a4
movq %r12, %rcx
negq %rcx
addq %rcx, %rbp
movq 0x10(%r14), %rcx
movq %rbp, %r8
movq 0x10(%rsp), %rdx
imulq %rdx, %r8
addq 0x10(%rbx), %r8
movq %r13, %rdi
movq %r15, %rsi
movq %rdx, %r9
callq 0x2f9d9f
testl %eax, %eax
jne 0x31868d
jmp 0x3186d2
movq %r12, %rbp
movq 0x20(%rsp), %rcx
movl %ebp, 0x4(%rcx)
cmpq $0x0, 0x70(%rsp)
jne 0x3186f6
leaq 0xd2926(%rip), %rsi     # 0x3eb00f
movq %r13, %rdi
movl $0x21a, %edx            # imm = 0x21A
callq 0x109670
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x9217e
callq 0x921b7
nopl (%rax)