// File: /workspace/github_c_makefile_star2_O2/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 0x2ad536
cmpq $0x0, 0x8(%rsp)
je 0x2ad536
testq %r8, %r8
je 0x2ad536
testl %esi, %esi
je 0x2ad564
movq %rcx, %r14
movl %edx, %ebx
movq 0x78(%rsp), %rbp
movq 0x70(%rsp), %rcx
movq 0x8(%rsp), %rax
movl 0x18(%rax), %edx
movl %edx, 0x1c(%rsp)
movl %edx, %r15d
imull %ebx, %r15d
movl 0x1c(%rax), %r12d
movl %esi, 0x10(%rsp)
imull %esi, %r12d
movq %rcx, %r13
testq %rcx, %rcx
movq %r8, 0x20(%rsp)
jne 0x2ad391
leaq (%r12,%r15), %rax
movq %rax, %rdi
shrq $0x3, %rdi
andl $0x7, %eax
cmpq $0x1, %rax
sbbq $-0x1, %rdi
leaq 0xd497a(%rip), %rsi     # 0x381cfe
movl $0x1cb, %edx            # imm = 0x1CB
callq 0x93160
movq %rax, %r13
movl %ebx, %esi
testq %rbp, %rbp
movq %rsi, 0x28(%rsp)
je 0x2ad3b1
leaq (,%rsi,4), %rdx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x17380
jmp 0x2ad3c8
leaq 0xd4946(%rip), %rdx     # 0x381cfe
pushq $0x4
popq %rdi
movl $0x1d6, %ecx            # imm = 0x1D6
callq 0x9334a
movq %rax, %rbp
movl 0x10(%rsp), %ebx
xorl %eax, %eax
cmpq %rax, %rbx
je 0x2ad3e1
movzbl (%r14,%rax), %ecx
incl (%rbp,%rcx,4)
incq %rax
jmp 0x2ad3ce
movq %r14, 0x10(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movl 0x1c(%rsp), %edx
movq 0x28(%rsp), %rcx
movq %rbp, %r8
callq 0x28d138
cmpq $0x0, 0x78(%rsp)
jne 0x2ad418
leaq 0xd48f3(%rip), %rsi     # 0x381cfe
movq %rbp, %rdi
movl $0x1de, %edx            # imm = 0x1DE
callq 0x936f9
movq 0x8(%rsp), %rax
movq (%rax), %r14
shrq %r14
movq %r14, %rbp
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq %r14, %r8
imulq %r15, %r8
movq %r13, %rdi
xorl %esi, %esi
movq %r15, %rdx
movq %r15, %r9
callq 0x28a997
testl %eax, %eax
je 0x2ad465
cmpq $0x2, %rbp
setae %cl
shrq %cl, %rbp
movq %rbp, %rcx
negq %rcx
testl %eax, %eax
cmovgq %rbp, %rcx
addq %rcx, %r14
jmp 0x2ad426
movq 0x20(%rsp), %rcx
movl %r14d, (%rcx)
movl %r14d, %eax
imulq $0x18, %rax, %rbp
movq 0x8(%rsp), %rax
addq 0x8(%rax), %rbp
movq 0x30(%rsp), %rdx
testq %rdx, %rdx
je 0x2ad48c
movl 0x8(%rbp), %eax
movl %eax, (%rdx)
xorl %r14d, %r14d
cmpq $0x2, (%rbp)
jb 0x2ad505
movq 0x8(%rsp), %rax
movl 0x1c(%rax), %edx
movq %r13, %rdi
movq %r15, %rsi
movq %rbx, %rcx
movq 0x10(%rsp), %r8
callq 0x28fb3b
movq (%rbp), %r14
shrq %r14
movq %r14, %rbx
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rcx
movq %r14, %r8
imulq %r12, %r8
addq 0x10(%rbp), %r8
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
movq %r12, %r9
callq 0x28a997
testl %eax, %eax
je 0x2ad500
cmpq $0x2, %rbx
setae %cl
shrq %cl, %rbx
movq %rbx, %rcx
testl %eax, %eax
jg 0x2ad4fb
movq %rbx, %rcx
negq %rcx
addq %rcx, %r14
jmp 0x2ad4bb
movq 0x20(%rsp), %rcx
movl %r14d, 0x4(%rcx)
cmpq $0x0, 0x70(%rsp)
jne 0x2ad525
leaq 0xd47e6(%rip), %rsi     # 0x381cfe
movq %r13, %rdi
movl $0x21a, %edx            # imm = 0x21A
callq 0x936f9
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18aa2b(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x37acc(%rip), %rsi     # 0x2e5013
leaq 0xd48b5(%rip), %rdx     # 0x381e03
leaq 0xd48d5(%rip), %rcx     # 0x381e2a
leaq 0xd47a2(%rip), %r8      # 0x381cfe
movl $0x1c1, %r9d            # imm = 0x1C1
jmp 0x2ad590
movq 0x18a9fd(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x37a9e(%rip), %rsi     # 0x2e5013
leaq 0xd3842(%rip), %rdx     # 0x380dbe
leaq 0xd48a7(%rip), %rcx     # 0x381e2a
leaq 0xd4774(%rip), %r8      # 0x381cfe
movl $0x1c2, %r9d            # imm = 0x1C2
xorl %eax, %eax
callq 0x17a50
callq 0x17390