// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/tools/gt_packedindex_mkctxmap.c
// Function: gt_packedindex_mkctxmap
extern int
gt_packedindex_mkctxmap(int argc, const char *argv[], GtError *err)
{
  struct mkCtxMapOptions params;
  const char *projectName;
  GtLogger *logger = NULL;
  BWTSeq *bwtSeq = NULL;
  SASeqSrc *src;
  int parsedArgs;
  bool had_err = false;
  bool saInitialized = false, saiInitialized = false;
  Suffixarray sa;
  SuffixarrayFileInterface sai;

  do {
    gt_error_check(err);
    {
      bool exitNow = false;
      switch (parseMkCtxMapOptions(&parsedArgs, argc, argv, &params, err))
      {
      case GT_OPTION_PARSER_OK:
        break;
      case GT_OPTION_PARSER_ERROR:
        had_err = true;
        exitNow = true;
        break;
      case GT_OPTION_PARSER_REQUESTS_EXIT:
        exitNow = true;
        break;
      }
      if (exitNow)
        break;
    }
    projectName = argv[parsedArgs];
    logger = gt_logger_new(params.verboseOutput,
                           GT_LOGGER_DEFLT_PREFIX, stdout);
    /* try to find appropriate suffix source */
    {
      GtUword len;
      if (streamsuffixarray(&sa, SARR_SUFTAB, projectName, logger, err))
      {
        gt_error_unset(err);
        if (streamsuffixarray(&sa, 0, projectName, logger, err))
        {
          had_err = true;
          break;
        }
        len = gt_encseq_total_length(sa.encseq) + 1;
        saInitialized = true;
        bwtSeq = gt_loadBWTSeqForSA(projectName, BWT_ON_BLOCK_ENC,
                                 BWTDEFOPT_MULTI_QUERY,
                                 gt_encseq_alphabet(sa.encseq), err);
        if (!(src = gt_BWTSeqNewSASeqSrc(bwtSeq, NULL)))
        {
          gt_error_set(err, "The project %s does not contain sufficient"
                       " information to regenerate the suffix array.",
                       projectName);
          had_err = true;
          break;
        }
      }
      else
      {
        len = gt_encseq_total_length(sa.encseq) + 1;
        saInitialized = true;
        gt_initSuffixarrayFileInterface(&sai, len, &sa);
        src = SAI2SASS(&sai);
        saiInitialized = true;
      }
      {
        SeqDataReader readSfxIdx = SASSCreateReader(src, SFX_REQUEST_SUFTAB);
        BWTSeqContextRetriever *bwtSeqCR;
        BWTSeqContextRetrieverFactory *bwtSeqCRF
          = gt_newBWTSeqContextRetrieverFactory(len, params.mapIntervalLog2);
        if (gt_BWTSCRFReadAdvance(bwtSeqCRF, len, readSfxIdx)
            != len)
        {
          gt_error_set(err, "Creation of context map unsuccessful: %s",
                    gt_error_get(err));
          had_err = true;
          gt_deleteBWTSeqContextRetrieverFactory(bwtSeqCRF);
          break;
        }
        bwtSeqCR = gt_BWTSCRFGet(bwtSeqCRF, bwtSeq, projectName);
        gt_deleteBWTSeqCR(bwtSeqCR);
        gt_deleteBWTSeqContextRetrieverFactory(bwtSeqCRF);
      }
    }
  } while (0);
  if (bwtSeq)
  {
    SASSDelete(src);
    gt_deleteBWTSeq(bwtSeq);
  }
  if (saiInitialized) gt_destructSuffixarrayFileInterface(&sai);;
  if (saInitialized) gt_freesuffixarray(&sa);
  if (logger) gt_logger_delete(logger);
  return had_err?-1:0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x218, %rsp            # imm = 0x218
movq %rdx, %rbx
movq %rsi, %r14
movl %edi, %ebp
testq %rdx, %rdx
je 0xb4a27
movq %rbx, %rdi
callq 0x101a9a
testb %al, %al
jne 0xb4d0b
testq %rbx, %rbx
je 0xb4a27
movq %rbx, %rdi
callq 0x101a9a
testb %al, %al
jne 0xb4d10
leaq 0x2ba2e4(%rip), %rdi    # 0x36ed12
leaq 0x2a63ce(%rip), %rsi    # 0x35ae03
callq 0x10cc4e
movq %rax, %r15
leaq 0x10(%rsp), %rsi
movq %rax, %rdi
callq 0x1a190c
leaq 0x14(%rsp), %rdx
leaq 0x2e4204(%rip), %rdi    # 0x398c5a
leaq 0x2a5c06(%rip), %rsi    # 0x35a663
xorl %r12d, %r12d
xorl %ecx, %ecx
callq 0x10f451
movq %r15, %rdi
movq %rax, %rsi
callq 0x10cd10
movq %r15, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0x10d784
leaq 0x7093d(%rip), %r8      # 0x1253c8
leaq 0xc(%rsp), %rsi
movq %r15, %rdi
movl %ebp, %edx
movq %r14, %rcx
movq %rbx, %r9
callq 0x10d796
movl %eax, %ebp
movq %r15, %rdi
callq 0x10f2d0
cmpl $0x2, %ebp
je 0xb4ac1
cmpl $0x1, %ebp
movl $0x0, %ebp
jne 0xb4ac6
movb $0x1, %r12b
movb $0x1, %bpl
jmp 0xb4ac6
movb $0x1, %r12b
xorl %ebp, %ebp
testb %r12b, %r12b
je 0xb4adb
xorl %r14d, %r14d
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %r15d, %r15d
jmp 0xb4c91
movslq 0xc(%rsp), %rax
movq (%r14,%rax,8), %r12
movzbl 0x14(%rsp), %edi
movq 0x40f3f8(%rip), %rax    # 0x4c3ee8
movq (%rax), %rdx
leaq 0x29adda(%rip), %rsi    # 0x34f8d4
callq 0x108ed0
movq %rax, %r15
leaq 0x38(%rsp), %rdi
movl $0x2, %esi
movq %r12, %rdx
movq %rax, %rcx
movq %rbx, %r8
callq 0x1a9f52
testl %eax, %eax
sete %al
movq %rax, 0x30(%rsp)
je 0xb4b57
movq %rbx, %rdi
callq 0x101aac
leaq 0x38(%rsp), %rdi
xorl %r14d, %r14d
xorl %esi, %esi
movq %r12, %rdx
movq %r15, %rcx
movq %rbx, %r8
callq 0x1a9f52
testl %eax, %eax
je 0xb4b93
movb $0x1, %bpl
xorl %ebx, %ebx
xorl %r12d, %r12d
jmp 0xb4c91
movq %r12, 0x18(%rsp)
movq %rbp, 0x20(%rsp)
movq %r15, (%rsp)
leaq 0x38(%rsp), %r15
movq (%r15), %rdi
callq 0xec1d8
movq %rax, %rbp
incq %rbp
leaq 0x138(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x1a7419
xorl %r12d, %r12d
jmp 0xb4bef
movq %rbp, 0x20(%rsp)
movq 0x38(%rsp), %rdi
callq 0xec1d8
movq %rax, %rbp
movq 0x38(%rsp), %rdi
callq 0xf02da
movq %r12, %rdi
movl $0x2, %esi
movl $0x2, %edx
movq %rax, %rcx
movq %rbx, %r8
callq 0x1a15e9
movq %r12, %r14
movq %rax, %r12
movq %rax, %rdi
xorl %esi, %esi
callq 0x1a3cac
testq %rax, %rax
je 0xb4cea
movq %rax, %r13
movq %r14, 0x18(%rsp)
movq %r15, (%rsp)
incq %rbp
movq %r13, %rdi
movl $0x1, %esi
callq *0x8(%r13)
movq %rax, %r14
movq %rdx, %r15
movswl 0x10(%rsp), %esi
movq %rbp, %rdi
callq 0x1a1944
movq %rax, 0x28(%rsp)
movq %rax, %rdi
movq %rbp, %rsi
movq %r14, %rdx
movq %r15, %rcx
callq 0x1a1ad8
cmpq %rbp, %rax
jne 0xb4c5c
movq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movq 0x18(%rsp), %rdx
callq 0x1a1c47
movq %rax, %rdi
callq 0x1a21b6
movq %rbx, %rdi
callq 0x1a1aad
movb $0x1, %r14b
movq (%rsp), %r15
movq 0x20(%rsp), %rbp
jmp 0xb4c8c
movq %rbx, %rdi
callq 0x101ac2
leaq 0x2a615a(%rip), %rsi    # 0x35adc5
movq %rbx, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x1019cf
movq 0x28(%rsp), %rdi
callq 0x1a1aad
movb $0x1, %r14b
movb $0x1, %bpl
movq (%rsp), %r15
movq 0x30(%rsp), %rbx
testq %r12, %r12
je 0xb4ca5
movq %r13, %rdi
callq *0x38(%r13)
movq %r12, %rdi
callq 0x1a430c
testb %bl, %bl
je 0xb4cb6
leaq 0x138(%rsp), %rdi
callq 0x1a76ce
testb %r14b, %r14b
je 0xb4cc5
leaq 0x38(%rsp), %rdi
callq 0x1a9e1c
testq %r15, %r15
je 0xb4cd2
movq %r15, %rdi
callq 0x10916a
movzbl %bpl, %eax
negl %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a607d(%rip), %rsi    # 0x35ad6e
movq %rbx, %rdi
xorl %ebx, %ebx
movq %r14, %rdx
xorl %eax, %eax
callq 0x1019cf
movb $0x1, %r14b
movb $0x1, %bpl
xorl %r13d, %r13d
jmp 0xb4c91
callq 0x1d22e
callq 0x1d1f5
nopl (%rax)