// File: /workspace/github_c_makefile_star2_O2/00pauln00[P]yapio/yapio.c
// Function: yapio_mmap_open
static int
yapio_mmap_open(const char *file, int flags, mode_t mode)
{
    int fd = open(file, flags, mode);
    if (fd >= YAPIO_FD_MAP_SIZE_MAX)
    {
        log_msg(YAPIO_LL_FATAL, "fd=%d exceeds map table size %u",
                fd, YAPIO_FD_MAP_SIZE_MAX);
        close(fd);
        return -ERANGE;
    }

    int prot = mode == O_RDONLY ? PROT_READ : (PROT_READ | PROT_WRITE);

    size_t len = (yapioMyTestGroup->ytg_num_blks_per_rank *
                  yapioMyTestGroup->ytg_blk_sz *
                  (yapioMyTestGroup->ytg_file_per_process ?
                   1 : yapioMyTestGroup->ytg_num_ranks));

    void *addr = mmap(NULL, len, prot, MAP_SHARED, fd, 0);
    if (addr == NULL)
    {
        const int error = errno;
        log_msg(YAPIO_LL_FATAL, "mmap() prot=%d len=%zd: %s",
                prot, len, strerror(error));
        close(fd);
        return -error;
    }

    log_msg(YAPIO_LL_DEBUG, "fd=%d addr=%p len=%zd", fd, addr, len);

    yapioFdMap[fd].yfm_fd = fd;
    yapioFdMap[fd].yfm_addr = addr;

    return fd;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
xorl %eax, %eax
callq 0x23c0
movl %eax, %ebx
cmpl $0x20000, %eax          # imm = 0x20000
jl 0x58e8
cmpl $0x0, 0x6945(%rip)      # 0xc218
jns 0x59d4
movl %ebx, %edi
callq 0x2080
pushq $-0x22
popq %rbx
jmp 0x5984
xorl %eax, %eax
testl %ebp, %ebp
setne %al
leal 0x1(,%rax,2), %r15d
movq 0x6952(%rip), %rax      # 0xc250
movq 0xb028(%rax), %r14
imulq 0xb020(%rax), %r14
cmpb $0x0, 0xb030(%rax)
je 0x591b
pushq $0x1
popq %rax
jmp 0x5922
movslq 0xb01c(%rax), %rax
imulq %rax, %r14
pushq $0x1
popq %rcx
xorl %edi, %edi
movq %r14, %rsi
movl %r15d, %edx
movl %ebx, %r8d
xorl %r9d, %r9d
callq 0x23d0
testq %rax, %rax
je 0x5965
movq %rax, %r12
cmpl $0x3, 0x68cd(%rip)      # 0xc218
jge 0x598f
movslq %ebx, %rax
shlq $0x4, %rax
leaq 0x6915(%rip), %rcx      # 0xc270
movl %ebx, (%rax,%rcx)
movq %r12, 0x8(%rax,%rcx)
jmp 0x5984
callq 0x2240
movl (%rax), %ebp
cmpl $0x0, 0x68a5(%rip)      # 0xc218
jns 0x5a11
movl %ebx, %edi
callq 0x2080
negl %ebp
movl %ebp, %ebx
movl %ebx, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq 0x664a(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x68c8(%rip), %r8d      # 0xc268
subq $0x8, %rsp
leaq 0x27c8(%rip), %rsi      # 0x8173
leaq 0x27fd(%rip), %rdx      # 0x81af
leaq 0x2780(%rip), %rcx      # 0x8139
movl $0x1ad, %r9d            # imm = 0x1AD
xorl %eax, %eax
pushq %r14
pushq %r12
pushq %rbx
callq 0x2380
addq $0x20, %rsp
jmp 0x594d
movq 0x6605(%rip), %rax      # 0xbfe0
movq (%rax), %rdi
movl 0x6883(%rip), %r8d      # 0xc268
leaq 0x271e(%rip), %rsi      # 0x810a
leaq 0x27a5(%rip), %rdx      # 0x8198
leaq 0x273f(%rip), %rcx      # 0x8139
movl $0x197, %r9d            # imm = 0x197
xorl %eax, %eax
pushq $0x20000                # imm = 0x20000
pushq %rbx
callq 0x2380
popq %rcx
popq %rdx
jmp 0x5a62
movq 0x65c8(%rip), %rax      # 0xbfe0
movq (%rax), %rbx
movl 0x6846(%rip), %r12d     # 0xc268
movl %ebp, %edi
callq 0x21f0
movq %rax, %r10
subq $0x8, %rsp
leaq 0x2712(%rip), %rsi      # 0x8149
leaq 0x275a(%rip), %rdx      # 0x8198
leaq 0x26f4(%rip), %rcx      # 0x8139
movq %rbx, %rdi
movl %r12d, %r8d
movl $0x1a8, %r9d            # imm = 0x1A8
xorl %eax, %eax
pushq %r10
pushq %r14
pushq %r15
callq 0x2380
addq $0x20, %rsp
pushq $0x1
popq %rdi
callq 0x5874