// File: /workspace/github_c_makefile_star2_O3/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, %r15d
movq %rcx, %r12
movq %rdx, %r13
movq %rsi, %rbx
movl %edi, %ebp
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x74a30
callq 0x34fea
testb %al, %al
jne 0x74b6e
movq %rbx, (%rsp)
cmpq $0x0, 0xde194(%rip)     # 0x152bd0
je 0x74b69
leaq 0x7be3c(%rip), %rdx     # 0xf0885
movl $0x1, %edi
movl $0x18, %esi
movl $0x189, %ecx            # imm = 0x189
callq 0x359a6
movq %rax, %rbx
movq 0x40(%rsp), %rax
movq %rax, 0x8(%rbx)
movl 0x48(%rsp), %eax
movl %eax, 0x10(%rbx)
movq %r13, (%rbx)
movzbl %r15b, %eax
leal 0x1(,%rax,2), %edx
xorl %edi, %edi
movq %r13, %rsi
movl $0x1, %ecx
movl %ebp, %r8d
movq %r12, %r9
testb %r14b, %r14b
je 0x74a9d
callq 0x832b1
movq %rax, %r12
jmp 0x74aab
callq 0xb660
movq %rax, %r12
cmpq $-0x1, %rax
je 0x74b1a
testq %r12, %r12
je 0x74b40
movq 0xde115(%rip), %rax     # 0x152bd0
movq 0x8(%rax), %rdi
callq 0x3d043
movq 0xde105(%rip), %rax     # 0x152bd0
movq 0x18(%rax), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x77628
movq (%rbx), %rdi
movq 0xde0ec(%rip), %rax     # 0x152bd0
movq 0x20(%rax), %rcx
addq %rdi, %rcx
movq %rcx, 0x20(%rax)
cmpb $0x1, 0x30(%rax)
jne 0x74b05
callq 0x39e3a
movq 0xde0cf(%rip), %rax     # 0x152bd0
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jbe 0x74b0f
movq %rcx, 0x28(%rax)
movq 0x8(%rax), %rdi
callq 0x3d05e
jmp 0x74b57
callq 0xb060
movl (%rax), %edi
callq 0xb1d0
leaq 0x7bedc(%rip), %rsi     # 0xf0a09
movq 0x50(%rsp), %rdi
movq (%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x34f1f
leaq 0x7bd3e(%rip), %rsi     # 0xf0885
movq %rbx, %rdi
movl $0x1cd, %edx            # imm = 0x1CD
callq 0x35c27
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x1b03a
callq 0x1b001