// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %r9, 0x20(%rsp)
movl %r8d, %ebp
movq %rcx, %rax
movl %edi, %ebx
movl $0x1, %edi
movl %ebx, %ecx
shll %cl, %edi
movslq %edi, %rcx
addq %rcx, %rdx
decq %rdx
movl %ebx, %ecx
shrq %cl, %rdx
movl %esi, 0x10(%rsp)
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 0x120955
movq %rax, %r14
leaq 0x209939(%rip), %rdx    # 0x3ab7c4
leaq 0x2d(%rsp), %r12
movl $0xb, %esi
movq %r12, %rdi
movl %ebx, %ecx
xorl %eax, %eax
callq 0x17c60
movq %r14, %rdi
movq %r12, %rsi
callq 0x12097f
movq %rsp, 0x18(%rsp)
movq %r14, %rdi
callq 0x120d23
movl %ebp, 0x14(%rsp)
testl %ebp, %ebp
je 0x1a1f7a
leaq 0x2098ff(%rip), %rsi    # 0x3ab7cb
leaq 0x2096bf(%rip), %rdx    # 0x3ab592
xorl %r13d, %r13d
movq %rax, %rdi
movl $0x12a, %ecx            # imm = 0x12A
xorl %r8d, %r8d
callq 0x101c23
movq %rax, %r12
movl $0x4, %ebp
testq %rax, %rax
je 0x1a200a
movzwl %bx, %ecx
xorl %r13d, %r13d
movq %rsp, %rbx
movq %rbx, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2fa9a3
movzwl 0x10(%rsp), %ecx
movl $0x10, %esi
movq %rbx, %rdi
movl $0x10, %edx
callq 0x2fa9a3
movl $0x4, %esi
movl $0x1, %edx
movq %rbx, %rdi
movq %r12, %rcx
callq 0x125658
leaq 0x3(%r15), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x17cf0
testl %eax, %eax
jne 0x1a200a
leaq 0x2d(%rsp), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x125658
movq %r12, %rdi
callq 0x12553e
movb $0x1, %r13b
xorl %ebp, %ebp
jmp 0x1a200a
leaq 0x20cd3e(%rip), %rsi    # 0x3aecbf
leaq 0x20960a(%rip), %rdx    # 0x3ab592
xorl %r13d, %r13d
movq %rax, %rdi
movl $0x13b, %ecx            # imm = 0x13B
xorl %r8d, %r8d
callq 0x101c23
movq %rax, %r12
movl $0x4, %ebp
testq %rax, %rax
je 0x1a200a
movq %rsp, %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r12, %rcx
callq 0x17b40
cmpq $0x1, %rax
jne 0x1a2007
xorl %ebp, %ebp
movq %rsp, %rdi
xorl %esi, %esi
movl $0x10, %edx
callq 0x2fa8bc
cmpw %bx, %ax
jne 0x1a1ff5
movq %rsp, %rdi
movl $0x10, %esi
movl $0x10, %edx
callq 0x2fa8bc
movb $0x1, %r13b
cmpw 0x10(%rsp), %ax
je 0x1a200a
movq %r14, %rdi
callq 0x5fc52
xorl %r13d, %r13d
movl $0x4, %ebp
jmp 0x1a200a
xorl %r13d, %r13d
movq 0x18(%rsp), %rsp
testb %r13b, %r13b
je 0x1a2016
xorl %ebp, %ebp
testl %ebp, %ebp
je 0x1a201e
xorl %ebx, %ebx
jmp 0x1a207b
addq $0x4, %r15
movq %r12, %rdi
callq 0x17850
movl %eax, %ebx
movq %r14, %rdi
callq 0x120d23
subq $0x8, %rsp
leaq 0x209553(%rip), %r10    # 0x3ab592
movzbl 0x1c(%rsp), %r8d
movl %ebx, %edi
movq %rax, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r9d, %r9d
pushq $0x0
pushq $0x14a                  # imm = 0x14A
pushq %r10
callq 0x102407
addq $0x20, %rsp
movq 0x20(%rsp), %rdx
movq %rax, 0x18(%rdx)
leaq 0x4(%rax), %rcx
movq %rcx, 0x20(%rdx)
testq %rax, %rax
setne %bl
testq %r14, %r14
je 0x1a2088
movq %r14, %rdi
callq 0x121b03
testq %r12, %r12
je 0x1a2095
movq %r12, %rdi
callq 0x101f02
movl %ebx, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq