// File: /workspace/github_cpp_makefile_star2_O3/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 0x5bea(%rip), %rdi      # 0x1143e
leaq 0x5d04(%rip), %rcx      # 0x1155f
leaq 0x5d0e(%rip), %r9       # 0x11570
movl $0x2f2, %esi            # imm = 0x2F2
xorl %eax, %eax
callq 0xb98e
testb %al, %al
je 0xb989
movl $0x2, %eax
leaq -0x30(%rbp), %rdx
movl %eax, (%rdx)
leaq -0x2c(%rbp), %r8
movl %eax, (%r8)
movq $0x0, (%rsp)
leaq 0x5ba7(%rip), %rdi      # 0x1143e
leaq 0x5ce2(%rip), %rcx      # 0x11580
leaq 0x5cec(%rip), %r9       # 0x11591
movl $0x2f3, %esi            # imm = 0x2F3
xorl %eax, %eax
callq 0xb98e
testb %al, %al
je 0xb989
testq %rbx, %rbx
je 0xb978
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 %edi, %edi
movq %rbx, %rsi
movl $0x1, %ecx
callq 0x35c0
movq %rax, %rcx
incq %rcx
cmpq $0x1, %rcx
ja 0xb97a
addq $0x8, %r15
movq %r15, %rdi
xorl %esi, %esi
movl $0x1, %edx
callq 0xbcd8
movq %rax, %r13
movq %r15, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0xbcd8
movq %rax, -0x38(%rbp)
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0xbc01
callq 0x3050
movl (%rax), %edi
callq 0x3130
movq %rax, 0x8(%rsp)
movq -0x38(%rbp), %rax
movq %rax, (%rsp)
leaq 0x5ae7(%rip), %rdi      # 0x1143e
leaq 0x5c43(%rip), %rdx      # 0x115a1
movl $0x320, %esi            # imm = 0x320
movl %r14d, %ecx
movq %rbx, %r8
movl %r12d, %r9d
xorl %eax, %eax
callq 0x8c95
callq 0x31e0
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x31e0