// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x68, %rsp
movl %r8d, 0x14(%rsp)
movq %rcx, %rax
movl 0x14(%rsp), %ecx
movq %rax, 0x18(%rsp)
movq %rdx, %rax
movq 0x18(%rsp), %rdx
movq %rax, 0x20(%rsp)
movq %rsi, %rax
movq 0x20(%rsp), %rsi
movq %rax, 0x28(%rsp)
movl %edi, %r8d
movq 0x28(%rsp), %rdi
movb %r9b, %al
movq 0x80(%rsp), %r9
movl 0x78(%rsp), %r9d
movq 0x70(%rsp), %r9
movl %r8d, 0x64(%rsp)
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
andb $0x1, %cl
movb %cl, 0x47(%rsp)
andb $0x1, %al
movb %al, 0x46(%rsp)
movq $0x0, 0x30(%rsp)
cmpq $0x0, 0x80(%rsp)
je 0x80a8c
movq 0x80(%rsp), %rdi
callq 0xc270
testb $0x1, %al
jne 0x80a54
jmp 0x80a8c
movq 0x13357d(%rip), %rax    # 0x1b3fd8
movq (%rax), %rdi
leaq 0xdd601(%rip), %rsi     # 0x15e066
leaq 0xddbdc(%rip), %rdx     # 0x15e648
leaq 0xed355(%rip), %rcx     # 0x16ddc8
leaq 0xed1f2(%rip), %r8      # 0x16dc6c
movl $0x187, %r9d            # imm = 0x187
movb $0x0, %al
callq 0xb890
callq 0xb2e0
jmp 0x80a8e
jmp 0x80a90
cmpq $0x0, 0x135a18(%rip)    # 0x1b64b0
jne 0x80ad2
movq 0x133537(%rip), %rax    # 0x1b3fd8
movq (%rax), %rdi
leaq 0xdd5bb(%rip), %rsi     # 0x15e066
leaq 0xed5e9(%rip), %rdx     # 0x16e09b
leaq 0xed30f(%rip), %rcx     # 0x16ddc8
leaq 0xed1ac(%rip), %r8      # 0x16dc6c
movl $0x188, %r9d            # imm = 0x188
movb $0x0, %al
callq 0xb890
callq 0xb2e0
jmp 0x80ad4
movl $0x1, %edi
movl $0x18, %esi
leaq 0xed187(%rip), %rdx     # 0x16dc6c
movl $0x189, %ecx            # imm = 0x189
callq 0xd5b0
movq %rax, 0x38(%rsp)
movq 0x70(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x8(%rax)
movl 0x78(%rsp), %ecx
movq 0x38(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x50(%rsp), %rcx
movq 0x38(%rsp), %rax
movq %rcx, (%rax)
testb $0x1, 0x46(%rsp)
je 0x80b5d
movq 0x50(%rsp), %rsi
movb 0x47(%rsp), %cl
xorl %edx, %edx
movl $0x2, %eax
testb $0x1, %cl
cmovnel %eax, %edx
orl $0x1, %edx
movl 0x64(%rsp), %r8d
movq 0x48(%rsp), %r9
xorl %eax, %eax
movl %eax, %edi
movl $0x1, %ecx
callq 0xa2ee0
movq %rax, 0x30(%rsp)
jmp 0x80be6
movq 0x50(%rsp), %rsi
movb 0x47(%rsp), %cl
xorl %edx, %edx
movl $0x2, %eax
testb $0x1, %cl
cmovnel %eax, %edx
orl $0x1, %edx
movl 0x64(%rsp), %r8d
movq 0x48(%rsp), %r9
xorl %eax, %eax
movl %eax, %edi
movl $0x1, %ecx
callq 0xb640
movq %rax, 0x30(%rsp)
movq $-0x1, %rcx
cmpq %rcx, %rax
jne 0x80be4
movq 0x80(%rsp), %rax
movq %rax, (%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x8(%rsp)
callq 0xb060
movl (%rax), %edi
callq 0xb1b0
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
movq %rax, %rcx
leaq 0xed20f(%rip), %rsi     # 0x16dde3
movb $0x0, %al
callq 0xc0d0
movq $0x0, 0x30(%rsp)
jmp 0x80be6
cmpq $0x0, 0x30(%rsp)
je 0x80c8d
movq 0x1358b7(%rip), %rax    # 0x1b64b0
movq 0x8(%rax), %rdi
callq 0x1c340
movq 0x1358a7(%rip), %rax    # 0x1b64b0
movq 0x18(%rax), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
callq 0x86510
movq 0x38(%rsp), %rax
movq (%rax), %rcx
movq 0x135885(%rip), %rax    # 0x1b64b0
addq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
movq 0x135876(%rip), %rax    # 0x1b64b0
testb $0x1, 0x30(%rax)
je 0x80c4d
movq 0x38(%rsp), %rax
movq (%rax), %rdi
callq 0x167a0
movq 0x13585c(%rip), %rax    # 0x1b64b0
movq 0x20(%rax), %rax
movq 0x135851(%rip), %rcx    # 0x1b64b0
cmpq 0x28(%rcx), %rax
jbe 0x80c7b
movq 0x135844(%rip), %rax    # 0x1b64b0
movq 0x20(%rax), %rcx
movq 0x135839(%rip), %rax    # 0x1b64b0
movq %rcx, 0x28(%rax)
movq 0x13582e(%rip), %rax    # 0x1b64b0
movq 0x8(%rax), %rdi
callq 0x1c3e0
jmp 0x80ca3
movq 0x38(%rsp), %rdi
leaq 0xecfd3(%rip), %rsi     # 0x16dc6c
movl $0x1cd, %edx            # imm = 0x1CD
callq 0xdab0
movq 0x30(%rsp), %rax
addq $0x68, %rsp
retq
nopl (%rax)