// File: /workspace/github_cpp_makefile_star2_O1/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
subq $0x28, %rsp
movl %ecx, %r13d
movq %rdx, %rbx
movl %esi, %r14d
movq %rdi, %r15
movl $0x1, %eax
leaq -0x30(%rbp), %rdx
movl %eax, (%rdx)
leaq -0x2c(%rbp), %r8
movl %eax, (%r8)
movq $0x0, (%rsp)
leaq 0x596b(%rip), %rdi      # 0x1143e
leaq 0x5a85(%rip), %rcx      # 0x1155f
leaq 0x5a8f(%rip), %r9       # 0x11570
movl $0x2f2, %esi            # imm = 0x2F2
xorl %eax, %eax
callq 0xbc11
testb %al, %al
je 0xbc0c
movl $0x2, %eax
leaq -0x30(%rbp), %rdx
movl %eax, (%rdx)
leaq -0x2c(%rbp), %r8
movl %eax, (%r8)
movq $0x0, (%rsp)
leaq 0x5928(%rip), %rdi      # 0x1143e
leaq 0x5a63(%rip), %rcx      # 0x11580
leaq 0x5a6d(%rip), %r9       # 0x11591
movl $0x2f3, %esi            # imm = 0x2F3
xorl %eax, %eax
callq 0xbc11
testb %al, %al
je 0xbc0c
testq %rbx, %rbx
je 0xbbfb
andl 0x18(%r15), %r13d
movl %r13d, %r12d
andl $0x3, %r12d
andl $0x1, %r13d
movl %r12d, %edx
orl $0x2, %edx
cmpl $0x2, %r12d
cmovbl %r13d, %edx
movl 0x10(%r15), %r8d
movslq %r14d, %r9
xorl %r13d, %r13d
xorl %edi, %edi
movq %rbx, %rsi
movl $0x1, %ecx
callq 0x35c0
cmpq $-0x1, %rax
cmoveq %r13, %rax
testq %rax, %rax
jne 0xbbfd
addq $0x8, %r15
movq %r15, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xbf5c
movq %rax, %r13
movq %r15, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xbf5c
movq %rax, -0x38(%rbp)
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xbe84
callq 0x3050
movl (%rax), %edi
callq 0x3130
movq %rax, 0x8(%rsp)
movq -0x38(%rbp), %rax
movq %rax, (%rsp)
leaq 0x5864(%rip), %rdi      # 0x1143e
leaq 0x59c0(%rip), %rdx      # 0x115a1
movl $0x320, %esi            # imm = 0x320
movl %r14d, %ecx
movq %rbx, %r8
movl %r12d, %r9d
xorl %eax, %eax
callq 0x8d6f
callq 0x31e0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31e0