// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r9, 0x30(%rsp)
movl %r8d, %ebp
movq %rcx, %rax
movl %edi, %r14d
pushq $0x1
popq %rdi
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 0xacbd1
movq %rax, %rbx
leaq 0x1fe6f8(%rip), %rdx    # 0x342534
leaq 0x3d(%rsp), %r12
pushq $0xb
popq %rsi
movq %r12, %rdi
movl %r14d, %ecx
xorl %eax, %eax
callq 0x17bf0
movq %rbx, %rdi
movq %r12, %rsi
callq 0xacbfb
movq %rsp, 0x28(%rsp)
movq %rbx, %rdi
callq 0xad1fa
movl %ebp, 0x24(%rsp)
testl %ebp, %ebp
je 0x143f0c
leaq 0x1fe6bf(%rip), %rsi    # 0x34253b
leaq 0x1fe49f(%rip), %rdx    # 0x342322
movq %rax, %rdi
movl $0x12a, %ecx            # imm = 0x12A
xorl %r8d, %r8d
callq 0x8a156
movq %rax, %r12
testq %rax, %rax
je 0x14400a
movzwl %r14w, %ecx
leaq 0x20(%rsp), %r14
pushq $0x10
popq %rbp
movq %r14, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x28b538
movzwl %r13w, %ecx
pushq $0x10
popq %rsi
movq %r14, %rdi
movl %ebp, %edx
callq 0x28b538
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
movq %r12, %rcx
callq 0xb302c
leaq 0x3(%r15), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x17c70
testl %eax, %eax
jne 0x14400a
leaq 0x3d(%rsp), %rdi
pushq $0x1
popq %rdx
movq %rdx, %rsi
movq %r12, %rcx
callq 0xb302c
movq %r12, %rdi
callq 0xb2e24
jmp 0x143f7e
leaq 0x201b8a(%rip), %rsi    # 0x345a9d
leaq 0x1fe408(%rip), %rdx    # 0x342322
movq %rax, %rdi
movl $0x13b, %ecx            # imm = 0x13B
xorl %r8d, %r8d
callq 0x8a156
movq %rax, %r12
testq %rax, %rax
je 0x14400a
leaq 0x20(%rsp), %rdi
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r12, %rcx
callq 0x17ad0
cmpq $0x1, %rax
jne 0x14400a
leaq 0x20(%rsp), %rdi
pushq $0x10
popq %rdx
xorl %esi, %esi
callq 0x28b438
cmpw %r14w, %ax
jne 0x143fe4
leaq 0x20(%rsp), %rdi
pushq $0x10
popq %rsi
pushq $0x10
popq %rdx
callq 0x28b438
cmpw %r13w, %ax
jne 0x143fe4
addq $0x4, %r15
movq 0x28(%rsp), %rsp
movq %r12, %rdi
callq 0x17800
movl %eax, %ebp
movq %rbx, %rdi
callq 0xad1fa
leaq 0x1fe382(%rip), %rcx    # 0x342322
movq %rcx, (%rsp)
andq $0x0, 0x10(%rsp)
movl $0x14a, 0x8(%rsp)       # imm = 0x14A
movzbl 0x24(%rsp), %r8d
movl %ebp, %edi
movq %rax, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
callq 0x8ae80
movq 0x30(%rsp), %rdx
movq %rax, 0x18(%rdx)
leaq 0x4(%rax), %rcx
movq %rcx, 0x20(%rdx)
testq %rax, %rax
setne %bpl
jmp 0x144011
movq 0x2f3f7d(%rip), %rax    # 0x437f68
movq (%rax), %r14
movq %rbx, %rdi
callq 0xad1fa
leaq 0x1fe542(%rip), %rsi    # 0x34253f
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x17a50
movq 0x28(%rsp), %rsp
xorl %ebp, %ebp
testq %rbx, %rbx
je 0x14401e
movq %rbx, %rdi
callq 0xae103
testq %r12, %r12
je 0x14402b
movq %r12, %rdi
callq 0x8a5e5
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq