// File: /workspace/github_c_makefile_star2_O3/genometools[P]genometools/src/match/eis-bwtseq-context.c
// Function: BWTSeqCRMapOpen
static inline bool
BWTSeqCRMapOpen(unsigned short mapIntervalLog2,
                unsigned short bitsPerUlong,
                GtUword seqLen,
                const char *projectName,
                bool createMapFile,
                BWTSeqContextRetriever *gt_newBWTSeqCR)
{
  FILE *mapFile = NULL;
  BitString mapMap = NULL;
  GtStr *mapName = NULL;
  gt_assert(projectName);
  do {
    size_t headerBitElems = bitElemsAllocSize(2 * HEADER_ENTRY_BITS),
      headerSize = headerBitElems * sizeof (BitElem),
      mapSize = headerSize + sizeof (BitElem)
      * bitElemsAllocSize(bitsPerUlong * numMapEntries(
                            seqLen, mapIntervalLog2));
    mapName = gt_str_new_cstr(projectName);
    {
      char buf[1 + 4 + 3 + 3];
      snprintf(buf, sizeof (buf), ".%ucxm", (unsigned)mapIntervalLog2);
      gt_str_append_cstr(mapName, buf);
      if (createMapFile)
      {
        /* write header information, for reference to verify noone
         * toyed with the file name */
        BitElem headerBuf[headerBitElems];
        if (!(mapFile = gt_fa_fopen(gt_str_get(mapName), "w+b", NULL)))
          break;
        gt_bsStoreUInt16(headerBuf, 0, HEADER_ENTRY_BITS, mapIntervalLog2);
        gt_bsStoreUInt16(headerBuf, HEADER_ENTRY_BITS, HEADER_ENTRY_BITS,
                      bitsPerUlong);
        gt_xfwrite(headerBuf,  sizeof (headerBuf), 1, mapFile);
        if (fseeko(mapFile, mapSize - 1, SEEK_SET))
          break;
        /* write one byte so mmap works for full file */
        gt_xfwrite(&buf, 1, 1, mapFile);
        gt_xfflush(mapFile);
      }
      else
      {
        /* read header information, for reference to verify noone
         * toyed with the file name */
        BitElem headerBuf[headerBitElems];
        if (!(mapFile = gt_fa_fopen(gt_str_get(mapName), "rb", NULL)))
          break;
        if (fread(headerBuf,  sizeof (headerBuf), 1, mapFile) != 1)
          break;
        if (gt_bsGetUInt16(headerBuf, 0, HEADER_ENTRY_BITS) != mapIntervalLog2
            || (gt_bsGetUInt16(headerBuf, HEADER_ENTRY_BITS, HEADER_ENTRY_BITS)
                != bitsPerUlong))
        {
          fprintf(stderr, "error: context map file %s contains corrupted "
                  "data.\n", gt_str_get(mapName));
          break;
        }
      }
    }
    mapMap = gt_fa_mmap_generic_fd(fileno(mapFile), gt_str_get(mapName),
                                   mapSize, 0, createMapFile, false, NULL);
    gt_newBWTSeqCR->revMap = (gt_newBWTSeqCR->revMapMMap = mapMap) + headerSize;
  } while (0);
  if (mapName) gt_str_delete(mapName);
  if (mapFile) gt_fa_xfclose(mapFile);
  return mapMap != NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x10(%rsp)
movl %r8d, %ebp
movq %rcx, %rax
movl %edi, %r14d
movl $0x1, %edi
movl %r14d, %ecx
shll %cl, %edi
movl %esi, %r13d
movslq %edi, %rcx
addq %rcx, %rdx
decq %rdx
movl %r14d, %ecx
shrq %cl, %rdx
movl %esi, %ecx
imulq %rcx, %rdx
movq %rdx, %r15
shrq $0x3, %r15
andl $0x7, %edx
cmpq $0x1, %rdx
sbbq $-0x1, %r15
movq %rax, %rdi
callq 0x11acc9
movq %rax, %rbx
leaq 0x2088f5(%rip), %rdx    # 0x3a2264
leaq 0x1d(%rsp), %r12
movl $0xb, %esi
movq %r12, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x17c60
movq %rbx, %rdi
movq %r12, %rsi
callq 0x11acf3
movq %rsp, 0x8(%rsp)
movq %rbx, %rdi
callq 0x11b0a1
movl %ebp, 0x4(%rsp)
testl %ebp, %ebp
je 0x199a4c
leaq 0x2088ba(%rip), %rsi    # 0x3a226b
leaq 0x20867a(%rip), %rdx    # 0x3a2032
movq %rax, %rdi
movl $0x12a, %ecx            # imm = 0x12A
xorl %r8d, %r8d
callq 0xfcdbb
movq %rax, %r12
testq %rax, %rax
je 0x199b31
movzwl %r14w, %ecx
movq %rsp, %r14
movq %r14, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2f158c
movzwl %r13w, %ecx
movl $0x10, %esi
movq %r14, %rdi
movl $0x10, %edx
callq 0x2f158c
movl $0x4, %esi
movl $0x1, %edx
movq %r14, %rdi
movq %r12, %rcx
callq 0x11f89c
leaq 0x3(%r15), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x17cf0
testl %eax, %eax
jne 0x199b31
leaq 0x1d(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x11f89c
movq %r12, %rdi
callq 0x11f782
jmp 0x199ac2
leaq 0x20bcca(%rip), %rsi    # 0x3a571d
leaq 0x2085d8(%rip), %rdx    # 0x3a2032
movq %rax, %rdi
movl $0x13b, %ecx            # imm = 0x13B
xorl %r8d, %r8d
callq 0xfcdbb
movq %rax, %r12
testq %rax, %rax
je 0x199b31
movq %rsp, %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x17b40
cmpq $0x1, %rax
jne 0x199b31
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2f14dc
cmpw %r14w, %ax
jne 0x199b29
movq %rsp, %rdi
movl $0x10, %esi
movl $0x10, %edx
callq 0x2f14dc
cmpw %r13w, %ax
jne 0x199b29
addq $0x4, %r15
movq 0x8(%rsp), %rsp
movq %r12, %rdi
callq 0x17850
movl %eax, %r14d
movq %rbx, %rdi
callq 0x11b0a1
subq $0x8, %rsp
leaq 0x208549(%rip), %r10    # 0x3a2032
movzbl 0xc(%rsp), %r8d
movl %r14d, %edi
movq %rax, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
pushq $0x0
pushq $0x14a                  # imm = 0x14A
pushq %r10
callq 0xfd565
addq $0x20, %rsp
movq 0x10(%rsp), %rdx
movq %rax, 0x18(%rdx)
leaq 0x4(%rax), %rcx
movq %rcx, 0x20(%rdx)
testq %rax, %rax
setne %bpl
jmp 0x199b38
movq %rbx, %rdi
callq 0x5e7de
movq 0x8(%rsp), %rsp
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x199b45
movq %rbx, %rdi
callq 0x11bdbf
testq %r12, %r12
je 0x199b52
movq %r12, %rdi
callq 0xfd09a
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq