// File: /workspace/github_cpp_makefile_star2_O2/mshabbirhasan[P]ups-indel/include/seqan/file/file_mapping.h
// Function: void* seqan::mapFileSegment<void, int, long, seqan::FileMappingMode>(seqan::FileMapping<void>&, int, long, seqan::FileMappingMode)
inline void *
mapFileSegment(FileMapping<TSpec> &mapping, TPos fileOfs, TSize size, TFileMappingMode mode)
{
    SEQAN_ASSERT_EQ((int)OPEN_RDONLY, (int)MAP_RDONLY);
    SEQAN_ASSERT_EQ((int)OPEN_WRONLY, (int)MAP_WRONLY);

    void *addr;
    if (size == 0)
        return NULL;
    mode = (FileMappingMode)(mode & (mapping.openMode & OPEN_MASK));

#ifdef PLATFORM_WINDOWS

    DWORD access = ((mode & OPEN_MASK) == OPEN_RDONLY) ? FILE_MAP_READ : FILE_MAP_ALL_ACCESS;
    LARGE_INTEGER largeOfs;
    largeOfs.QuadPart = fileOfs;

    addr = MapViewOfFile(
        mapping.handle,                 // _In_     HANDLE hFileMappingObject,
        access,                         // _In_     DWORD dwDesiredAccess,
        largeOfs.HighPart,              // _In_     DWORD dwFileOffsetHigh,
        largeOfs.LowPart,               // _In_     DWORD dwFileOffsetLow,
        size);                          // _In_     SIZE_T dwNumberOfBytesToMap (0 = map the whole file)
#else
    int prot = 0;

    if (mode & MAP_RDONLY) prot |= PROT_READ;
    if (mode & MAP_WRONLY) prot |= PROT_WRITE;

    int flags = 0;
    if ((mode & MAP_COPYONWRITE) != 0)
        flags |= MAP_PRIVATE;
    else
        flags |= MAP_SHARED;

    addr = mmap(
        NULL,
        size,
        prot,
        flags,
        mapping.file.handle,
        fileOfs);
//    std::cerr << "mmap(0,"<<size<<','<<prot<<','<<flags<<','<<mapping.file.handle<<','<<fileOfs<<")="<<addr<<std::endl;

    if (addr == MAP_FAILED)
        addr = NULL;
#endif
    if (addr == NULL)
    {
        SEQAN_FAIL("mapFileSegment(%i,%i,%i) failed (filesize=%i): \"%s\"", fileOfs, size, mode, seqan::size(mapping.file), strerror(errno));
    }
    return addr;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r12d
movq %rdx, %rbx
movl %esi, %r14d
movq %rdi, %r15
pushq $0x1
popq %rax
leaq -0x30(%rbp), %rdx
movl %eax, (%rdx)
leaq -0x2c(%rbp), %r8
movl %eax, (%r8)
leaq 0x402c(%rip), %rdi      # 0xd472
leaq 0x4164(%rip), %rcx      # 0xd5b1
leaq 0x416e(%rip), %r9       # 0xd5c2
movl $0x2f2, %esi            # imm = 0x2F2
callq 0x9545
testb %al, %al
je 0x9540
pushq $0x2
popq %rax
leaq -0x30(%rbp), %rdx
movl %eax, (%rdx)
leaq -0x2c(%rbp), %r8
movl %eax, (%r8)
leaq 0x3ff5(%rip), %rdi      # 0xd472
leaq 0x414e(%rip), %rcx      # 0xd5d2
leaq 0x4158(%rip), %r9       # 0xd5e3
movl $0x2f3, %esi            # imm = 0x2F3
callq 0x9545
testb %al, %al
je 0x9540
testq %rbx, %rbx
je 0x952f
andl 0x18(%r15), %r12d
movl %r12d, %r13d
andl $0x3, %r13d
andl $0x1, %r12d
movl %r13d, %edx
orl $0x2, %edx
cmpl $0x2, %r13d
cmovbl %r12d, %edx
movl 0x10(%r15), %r8d
movslq %r14d, %r9
pushq $0x1
popq %rcx
xorl %edi, %edi
movq %rbx, %rsi
callq 0x35a0
movq %rax, %rcx
incq %rcx
cmpq $0x1, %rcx
ja 0x9531
addq $0x8, %r15
movq %r15, %rdi
callq 0x955f
movq %rax, %r15
callq 0x3060
movl (%rax), %edi
callq 0x3130
movq %rax, %r10
leaq 0x3f6a(%rip), %rdi      # 0xd472
leaq 0x40e4(%rip), %rdx      # 0xd5f3
movl $0x320, %esi            # imm = 0x320
movl %r14d, %ecx
movq %rbx, %r8
movl %r13d, %r9d
xorl %eax, %eax
pushq %r10
pushq %r15
callq 0x6d12
popq %rax
popq %rcx
callq 0x31f0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31f0