// File: /workspace/github_c_makefile_star2_O2/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, %r14
movq %rsi, %rbx
movl %edi, %ebp
testq %rdx, %rdx
je 0x36116
movq %r14, %rdi
callq 0x89eb7
testb %al, %al
jne 0x363c2
movq %r14, %rdi
callq 0x89eb7
testb %al, %al
jne 0x363ee
leaq 0x2cf940(%rip), %rdi    # 0x305a5d
leaq 0x2bbcb7(%rip), %rsi    # 0x2f1ddb
callq 0x97df5
movq %rax, %r15
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x143860
leaq 0x24(%rsp), %rdx
leaq 0x2f9a2b(%rip), %rdi    # 0x32fb70
leaq 0x2bb4ef(%rip), %rsi    # 0x2f163b
xorl %ecx, %ecx
callq 0x9a997
movq %r15, %rdi
movq %rax, %rsi
callq 0x97f31
pushq $0x1
popq %rdx
movq %r15, %rdi
movl %edx, %esi
callq 0x98c6b
leaq 0x7cade(%rip), %r8      # 0xb2c50
leaq 0x1c(%rsp), %rsi
movq %r15, %rdi
movl %ebp, %edx
movq %rbx, %rcx
movq %r14, %r9
callq 0x98cb0
movl %eax, %ebp
movq %r15, %rdi
callq 0x9a844
cmpl $0x1, %ebp
je 0x361a2
cmpl $0x2, %ebp
jne 0x361a9
xorl %ebx, %ebx
jmp 0x3638b
movb $0x1, %bl
jmp 0x3638b
movslq 0x1c(%rsp), %rax
movq (%rbx,%rax,8), %r13
movzbl 0x24(%rsp), %edi
movq 0x401cf2(%rip), %rax    # 0x437eb0
movq (%rax), %rdx
leaq 0x2b070c(%rip), %rsi    # 0x2e68d4
callq 0x92b50
movq %rax, %r15
leaq 0x38(%rsp), %rdi
pushq $0x2
popq %rsi
movq %r13, %rdx
movq %rax, %rcx
movq %r14, %r8
callq 0x14d283
movl %eax, %r12d
testl %eax, %eax
je 0x36277
movq %r14, %rdi
callq 0x89efa
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r15, %rcx
movq %r14, %r8
callq 0x14d283
movb $0x1, %bl
testl %eax, %eax
jne 0x3637e
movq 0x38(%rsp), %rdi
callq 0x7055e
movq %rax, %rbp
movq 0x38(%rsp), %rdi
callq 0x754dd
pushq $0x2
popq %rdx
movq %r13, %rdi
movl %edx, %esi
movq %rax, %rcx
movq %r14, %r8
callq 0x143419
movq %rax, %rbx
movq %rax, %rdi
xorl %esi, %esi
callq 0x146308
movq %r13, %rdx
testq %rax, %rax
je 0x363a2
movq %rax, %r13
movq %rbx, 0x10(%rsp)
movq %rdx, 0x28(%rsp)
movl %r12d, 0xc(%rsp)
movq %r15, 0x30(%rsp)
incq %rbp
jmp 0x362b9
movq %r13, 0x28(%rsp)
movl %r12d, 0xc(%rsp)
movq %r15, 0x30(%rsp)
leaq 0x38(%rsp), %r12
movq (%r12), %rdi
callq 0x7055e
movq %rax, %rbp
incq %rbp
leaq 0x138(%rsp), %r13
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x14a055
movq $0x0, 0x10(%rsp)
pushq $0x1
popq %rsi
movq %r13, %rdi
callq *0x8(%r13)
movq %rax, %rbx
movq %rdx, %r15
movswl 0x20(%rsp), %esi
movq %rbp, %rdi
callq 0x143894
movq %rax, %r12
movq %rax, %rdi
movq %rbp, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x143a3b
cmpq %rbp, %rax
jne 0x36310
movq %r12, %rdi
movq 0x10(%rsp), %r14
movq %r14, %rsi
movq 0x28(%rsp), %rdx
callq 0x143c2a
movq %rax, %rdi
callq 0x14417b
xorl %ebx, %ebx
jmp 0x36333
movq %r14, %rdi
callq 0x89f41
leaq 0x2bba7e(%rip), %rsi    # 0x2f1d9d
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x89dbb
movb $0x1, %bl
movq 0x10(%rsp), %r14
movq %r12, %rdi
callq 0x143a12
testq %r14, %r14
movq 0x30(%rsp), %r15
je 0x36360
movl 0xc(%rsp), %r12d
movq %r13, %rdi
callq *0x38(%r13)
movq %r14, %rdi
callq 0x146b99
testl %r12d, %r12d
jne 0x36374
jmp 0x36367
cmpl $0x0, 0xc(%rsp)
jne 0x36374
leaq 0x138(%rsp), %rdi
callq 0x14a3cb
leaq 0x38(%rsp), %rdi
callq 0x14d148
testq %r15, %r15
je 0x3638b
movq %r15, %rdi
callq 0x92fd0
movzbl %bl, %eax
negl %eax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2bb99d(%rip), %rsi    # 0x2f1d46
xorl %r13d, %r13d
movq %r14, %rdi
xorl %eax, %eax
callq 0x89dbb
movq %rbx, %r14
movb $0x1, %bl
testq %r14, %r14
jne 0x3634a
jmp 0x36374
movq 0x401b9f(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2aec40(%rip), %rsi    # 0x2e5013
leaq 0x2aede5(%rip), %rdx    # 0x2e51bf
leaq 0x2bb929(%rip), %rcx    # 0x2f1d0a
leaq 0x2bb93a(%rip), %r8     # 0x2f1d22
pushq $0x38
popq %r9
jmp 0x3641a
movq 0x401b73(%rip), %rax    # 0x437f68
movq (%rax), %rdi
leaq 0x2aec14(%rip), %rsi    # 0x2e5013
leaq 0x2aedb9(%rip), %rdx    # 0x2e51bf
leaq 0x2bb9b9(%rip), %rcx    # 0x2f1dc6
leaq 0x2bb90e(%rip), %r8     # 0x2f1d22
movl $0x95, %r9d
xorl %eax, %eax
callq 0x17a50
callq 0x17390
nop