// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movq 0xa8(%rsp), %rax
movq 0xa0(%rsp), %rax
movq %rdi, 0x90(%rsp)
movl %esi, 0x8c(%rsp)
movl %edx, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movq %r8, 0x78(%rsp)
movq %r9, 0x70(%rsp)
cmpq $0x0, 0x90(%rsp)
je 0x4af3bd
cmpq $0x0, 0x78(%rsp)
je 0x4af3bd
cmpq $0x0, 0x80(%rsp)
jne 0x4af3f5
movq 0x18cbdc(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x66c45(%rip), %rsi     # 0x516013
leaq 0x107c5a(%rip), %rdx    # 0x5b702f
leaq 0x107c7a(%rip), %rcx    # 0x5b7056
leaq 0x107b47(%rip), %r8     # 0x5b6f2a
movl $0x1c1, %r9d            # imm = 0x1C1
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x4af3f7
jmp 0x4af3f9
cmpl $0x0, 0x8c(%rsp)
ja 0x4af43b
movq 0x18cb96(%rip), %rax    # 0x63bfa0
movq (%rax), %rdi
leaq 0x66bff(%rip), %rsi     # 0x516013
leaq 0x106b2b(%rip), %rdx    # 0x5b5f46
leaq 0x107c34(%rip), %rcx    # 0x5b7056
leaq 0x107b01(%rip), %r8     # 0x5b6f2a
movl $0x1c2, %r9d            # imm = 0x1C2
movb $0x0, %al
callq 0x199f0
callq 0x19370
jmp 0x4af43d
movq 0x90(%rsp), %rax
movl 0x18(%rax), %eax
movl %eax, 0x6c(%rsp)
imull 0x88(%rsp), %eax
movl %eax, %eax
movq %rax, 0x60(%rsp)
movq 0x90(%rsp), %rax
movl 0x1c(%rax), %eax
imull 0x8c(%rsp), %eax
movl %eax, %eax
movq %rax, 0x58(%rsp)
cmpq $0x0, 0xa0(%rsp)
je 0x4af48f
movq 0xa0(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x4af4bb
movq 0x60(%rsp), %rdi
addq 0x58(%rsp), %rdi
callq 0x4aeea0
movq %rax, %rdi
shlq $0x0, %rdi
leaq 0x107a7e(%rip), %rsi    # 0x5b6f2a
movl $0x1cb, %edx            # imm = 0x1CB
callq 0xe80f0
movq %rax, 0x50(%rsp)
cmpq $0x0, 0xa8(%rsp)
je 0x4af4ee
movq 0xa8(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rdi
movl 0x88(%rsp), %eax
movl %eax, %edx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x19360
jmp 0x4af512
movl 0x88(%rsp), %eax
movl %eax, %esi
movl $0x4, %edi
leaq 0x107a27(%rip), %rdx    # 0x5b6f2a
movl $0x1d6, %ecx            # imm = 0x1D6
callq 0xe83c0
movq %rax, 0x40(%rsp)
movq $0x0, 0x48(%rsp)
movq 0x48(%rsp), %rax
movl 0x8c(%rsp), %ecx
cmpq %rcx, %rax
jae 0x4af55b
movq 0x40(%rsp), %rax
movq 0x80(%rsp), %rcx
movq 0x48(%rsp), %rdx
movzbl (%rcx,%rdx), %ecx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movq 0x48(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x48(%rsp)
jmp 0x4af51b
movq 0x50(%rsp), %rdi
movl 0x6c(%rsp), %edx
movl 0x88(%rsp), %eax
movl %eax, %ecx
movq 0x40(%rsp), %r8
xorl %eax, %eax
movl %eax, %esi
callq 0x475070
cmpq $0x0, 0xa8(%rsp)
jne 0x4af59c
movq 0x40(%rsp), %rdi
leaq 0x107998(%rip), %rsi    # 0x5b6f2a
movl $0x1de, %edx            # imm = 0x1DE
callq 0xe88c0
movq 0x90(%rsp), %rax
movq (%rax), %rax
shrq %rax
movq %rax, 0x38(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %rdx
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x38(%rsp), %r8
imulq 0x60(%rsp), %r8
movq 0x60(%rsp), %r9
xorl %eax, %eax
movl %eax, %esi
callq 0x46ed30
movl %eax, 0x2c(%rsp)
cmpl $0x0, %eax
je 0x4af632
cmpq $0x1, 0x30(%rsp)
jbe 0x4af606
movq 0x30(%rsp), %rax
shrq %rax
movq %rax, 0x30(%rsp)
cmpl $0x0, 0x2c(%rsp)
jle 0x4af61e
movq 0x30(%rsp), %rax
addq 0x38(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x4af630
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x38(%rsp)
jmp 0x4af5b9
movq 0x38(%rsp), %rax
movl %eax, %ecx
movq 0x78(%rsp), %rax
movl %ecx, (%rax)
movq 0x90(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x78(%rsp), %rcx
movl (%rcx), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, 0x70(%rsp)
je 0x4af676
movq 0x20(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0x70(%rsp), %rax
movl %ecx, (%rax)
movq 0x20(%rsp), %rax
cmpq $0x1, (%rax)
jbe 0x4af764
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x90(%rsp), %rax
movl 0x1c(%rax), %edx
movl 0x8c(%rsp), %eax
movl %eax, %ecx
movq 0x80(%rsp), %r8
callq 0x47b210
movq 0x20(%rsp), %rax
movq (%rax), %rax
shrq %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rdi
movq 0x60(%rsp), %rsi
movq 0x58(%rsp), %rdx
movq 0x90(%rsp), %rax
movq 0x10(%rax), %rcx
movq 0x20(%rsp), %rax
movq 0x10(%rax), %r8
movq 0x18(%rsp), %rax
imulq 0x58(%rsp), %rax
addq %rax, %r8
movq 0x58(%rsp), %r9
callq 0x46ed30
movl %eax, 0xc(%rsp)
cmpl $0x0, %eax
je 0x4af753
cmpq $0x1, 0x10(%rsp)
jbe 0x4af724
movq 0x10(%rsp), %rax
shrq %rax
movq %rax, 0x10(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x4af73c
movq 0x10(%rsp), %rax
addq 0x18(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x4af74e
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x18(%rsp)
jmp 0x4af6ca
movq 0x18(%rsp), %rax
movl %eax, %ecx
movq 0x78(%rsp), %rax
movl %ecx, 0x4(%rax)
jmp 0x4af770
movq 0x78(%rsp), %rax
movl $0x0, 0x4(%rax)
cmpq $0x0, 0xa0(%rsp)
jne 0x4af791
movq 0x50(%rsp), %rdi
leaq 0x1077a3(%rip), %rsi    # 0x5b6f2a
movl $0x21a, %edx            # imm = 0x21A
callq 0xe88c0
xorl %eax, %eax
addq $0x98, %rsp
retq
nopl (%rax,%rax)