// File: /workspace/github_c_makefile_star2_O2/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 0x52597
callq 0xc103
testb %al, %al
jne 0x526f5
movq %rbx, (%rsp)
cmpq $0x0, 0xdd61d(%rip)     # 0x12fbc0
je 0x526c7
leaq 0x87285(%rip), %rdx     # 0xd9835
pushq $0x1
popq %rdi
pushq $0x18
popq %rsi
movl $0x189, %ecx            # imm = 0x189
callq 0xce9a
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,%rax), %edx
pushq $0x1
popq %rcx
xorl %edi, %edi
movq %r13, %rsi
movl %ebp, %r8d
movq %r12, %r9
testb %r14b, %r14b
je 0x525fb
callq 0x62535
movq %rax, %r12
jmp 0x52609
callq 0xb660
movq %rax, %r12
cmpq $-0x1, %rax
je 0x52678
testq %r12, %r12
je 0x5269e
movq 0xdd5a7(%rip), %rax     # 0x12fbc0
movq 0x8(%rax), %rdi
callq 0x16028
movq 0xdd597(%rip), %rax     # 0x12fbc0
movq 0x18(%rax), %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x55f31
movq (%rbx), %rdi
movq 0xdd57e(%rip), %rax     # 0x12fbc0
movq 0x20(%rax), %rcx
addq %rdi, %rcx
movq %rcx, 0x20(%rax)
cmpb $0x1, 0x30(%rax)
jne 0x52663
callq 0x1230e
movq 0xdd561(%rip), %rax     # 0x12fbc0
movq 0x20(%rax), %rcx
cmpq 0x28(%rax), %rcx
jbe 0x5266d
movq %rcx, 0x28(%rax)
movq 0x8(%rax), %rdi
callq 0x1609f
jmp 0x526b5
callq 0xb060
movl (%rax), %edi
callq 0xb1d0
leaq 0x8732e(%rip), %rsi     # 0xd99b9
movq 0x50(%rsp), %rdi
movq (%rsp), %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0xc007
leaq 0x87190(%rip), %rsi     # 0xd9835
movq %rbx, %rdi
movl $0x1cd, %edx            # imm = 0x1CD
callq 0xd249
xorl %r12d, %r12d
movq %r12, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xdb8ea(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x7798e(%rip), %rsi     # 0xca066
leaq 0x87148(%rip), %rdx     # 0xd9827
leaq 0x872b8(%rip), %rcx     # 0xd999e
leaq 0x87148(%rip), %r8      # 0xd9835
movl $0x188, %r9d            # imm = 0x188
jmp 0x52721
movq 0xdb8bc(%rip), %rax     # 0x12dfb8
movq (%rax), %rdi
leaq 0x77960(%rip), %rsi     # 0xca066
leaq 0x77f4c(%rip), %rdx     # 0xca659
leaq 0x8728a(%rip), %rcx     # 0xd999e
leaq 0x8711a(%rip), %r8      # 0xd9835
movl $0x187, %r9d            # imm = 0x187
xorl %eax, %eax
callq 0xb8c0
callq 0xb300