// File: /workspace/github_c_makefile_star2_O1/genometools[P]genometools/src/core/fa.c
// Function: gt_fa_mmap_generic_fd_func
void* gt_fa_mmap_generic_fd_func(GT_UNUSED int fd, const char *filename,
                                 size_t len, GT_UNUSED size_t offset,
                                 bool mapwritable, bool hard_fail,
                                 const char *src_file, int src_line,
                                 GtError *err)
{
  FAMapInfo *mapinfo;
  void *map = NULL;
  gt_error_check(err);
  gt_assert(fa);
  mapinfo = gt_calloc(1, sizeof *mapinfo);
  mapinfo->src_file = src_file;
  mapinfo->src_line = src_line;
  mapinfo->len = len;

#ifndef _WIN32
  if (hard_fail) {
    map = gt_xmmap(0, len, PROT_READ | (mapwritable ? PROT_WRITE : 0),
                   MAP_SHARED, fd, offset);
  }
  else {
    if ((map = mmap(0, len, PROT_READ | (mapwritable ? PROT_WRITE : 0),
                    MAP_SHARED, fd, offset)) == MAP_FAILED) {
      gt_error_set(err,"cannot map file \"%s\": %s", filename, strerror(errno));
      map = NULL;
    }
  }
#else
  mapinfo->filehandle = CreateFile(filename,
                                   mapwritable ? GENERIC_READ | GENERIC_WRITE
                                               : GENERIC_READ,
                                   FILE_SHARE_READ, NULL, OPEN_EXISTING,
                                   FILE_FLAG_RANDOM_ACCESS, NULL);
  if (!mapinfo->filehandle) {
    if (hard_fail) {
      gt_error_set(err,"cannot CreateFile for file \"%s\": 0x%08x", filename,
                   (unsigned int) GetLastError());
    }
  }
  else {
    mapinfo->filemapping = CreateFileMapping(mapinfo->filehandle, NULL,
                                             mapwritable ? PAGE_READWRITE
                                                         : PAGE_READONLY,
                                             0, 0, 0);
    if (!mapinfo->filemapping) {
      CloseHandle(mapinfo->filehandle);
      if (hard_fail) {
        gt_error_set(err,"cannot CreateFileMapping for file \"%s\": 0x%08x",
                     filename, (unsigned int) GetLastError());
      }
    }
    else {
      map = MapViewOfFile(mapinfo->filemapping,
                          mapwritable ? FILE_MAP_WRITE : FILE_MAP_READ,
                          0, 0, 0);
      if (!map) {
        CloseHandle(mapinfo->filemapping);
        CloseHandle(mapinfo->filehandle);
        if (hard_fail) {
          gt_error_set(err,"cannot MapViewOfFile for file \"%s\": 0x%08x",
                       filename, (unsigned int) GetLastError());
        }
      }
    }
  }
#endif

  if (map) {
    gt_mutex_lock(fa->mmap_mutex);
    gt_hashmap_add(fa->memory_maps, map, mapinfo);
    fa->current_size += mapinfo->len;
    if (fa->global_space_peak)
      gt_spacepeak_add(mapinfo->len);
    if (fa->current_size > fa->max_size)
      fa->max_size = fa->current_size;
    gt_mutex_unlock(fa->mmap_mutex);
  }
  else
    gt_free(mapinfo);
  return map;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %r9d, %r14d
movl %r8d, %r12d
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rbx
movl %edi, %ebp
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x744d6
callq 0x3566a
testb %al, %al
jne 0x74609
movq %rbx, (%rsp)
cmpq $0x0, 0xde6ee(%rip)     # 0x152bd0
je 0x74604
leaq 0x7c3e6(%rip), %rdx     # 0xf08d5
movl $0x1, %edi
movl $0x18, %esi
movl $0x189, %ecx            # imm = 0x189
callq 0x3601f
movq %rax, %rbx
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rbx)
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rbx)
movq %r13, (%rbx)
movzbl %r12b, %eax
leal 0x1(,%rax,2), %edx
xorl %edi, %edi
movq %r13, %rsi
movl $0x1, %ecx
movl %ebp, %r8d
movq %r15, %r9
testb %r14b, %r14b
je 0x74543
callq 0x836c9
movq %rax, %r15
jmp 0x7457a
callq 0xb660
movq %rax, %r15
cmpq $-0x1, %rax
jne 0x7457a
callq 0xb060
movl (%rax), %edi
callq 0xb1d0
leaq 0x7c4f5(%rip), %rsi     # 0xf0a59
xorl %r15d, %r15d
movq 0x50(%rsp), %rdi
movq (%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3559f
testq %r15, %r15
je 0x745de
movq 0xde64a(%rip), %rax     # 0x152bd0
movq 0x8(%rax), %rdi
callq 0x3d9b7
movq 0xde63a(%rip), %rax     # 0x152bd0
movq 0x18(%rax), %rdi
movq %r15, %rsi
movq %rbx, %rdx
callq 0x77144
movq (%rbx), %rdi
movq 0xde621(%rip), %rax     # 0x152bd0
addq %rdi, 0x20(%rax)
cmpb $0x1, 0x30(%rax)
jne 0x745be
callq 0x3a69a
movq 0xde60b(%rip), %rax     # 0x152bd0
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jbe 0x745d3
movq %rcx, 0x28(%rax)
movq 0x8(%rax), %rdi
callq 0x3d9d2
jmp 0x745f2
leaq 0x7c2f0(%rip), %rsi     # 0xf08d5
movq %rbx, %rdi
movl $0x1cd, %edx            # imm = 0x1CD
callq 0x362a0
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1b08f
callq 0x1b056