// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x98, %rsp
movq %rdi, 0x88(%rsp)
movl %esi, 0x84(%rsp)
movl %edx, 0x80(%rsp)
movq 0x88(%rsp), %rdi
movl 0x84(%rsp), %esi
movl 0x80(%rsp), %edx
movb $0x0, %al
callq 0x23b0
movl %eax, 0x7c(%rsp)
cmpl $0x20000, 0x7c(%rsp)    # imm = 0x20000
jl 0x4214
xorl %eax, %eax
cmpl 0xb070(%rip), %eax      # 0xf210
jg 0x41fb
movq 0xae37(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x58(%rsp)
xorl %edi, %edi
callq 0x4890
movq 0x58(%rsp), %rdi
movq %rax, %rdx
movl 0xb0c9(%rip), %r8d      # 0xf290
movl 0x7c(%rsp), %eax
leaq 0x7116(%rip), %rsi      # 0xb2e8
leaq 0x713e(%rip), %rcx      # 0xb317
movl $0x197, %r9d            # imm = 0x197
movl %eax, (%rsp)
movl $0x20000, 0x8(%rsp)     # imm = 0x20000
movb $0x0, %al
callq 0x2370
movl $0x1, %edi
callq 0x40f0
movl 0x7c(%rsp), %edi
callq 0x2080
movl $0xffffffde, 0x94(%rsp) # imm = 0xFFFFFFDE
jmp 0x4430
movl 0x80(%rsp), %edx
movl $0x3, %eax
movl $0x1, %ecx
cmpl $0x0, %edx
cmovel %ecx, %eax
movl %eax, 0x78(%rsp)
movq 0xb01a(%rip), %rax      # 0xf250
movq 0xb020(%rax), %rax
movq 0xb00c(%rip), %rcx      # 0xf250
imulq 0xb028(%rcx), %rax
movq %rax, 0x50(%rsp)
movq 0xaff8(%rip), %rax      # 0xf250
testb $0x1, 0xb030(%rax)
je 0x426c
movl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x427d
movq 0xafdd(%rip), %rax      # 0xf250
movl 0xb01c(%rax), %eax
movl %eax, 0x4c(%rsp)
movq 0x50(%rsp), %rax
movl 0x4c(%rsp), %ecx
movslq %ecx, %rcx
imulq %rcx, %rax
movq %rax, 0x70(%rsp)
movq 0x70(%rsp), %rsi
movl 0x78(%rsp), %edx
movl 0x7c(%rsp), %r8d
xorl %eax, %eax
movl %eax, %r9d
movl $0x1, %ecx
movq %r9, %rdi
callq 0x23c0
movq %rax, 0x68(%rsp)
cmpq $0x0, 0x68(%rsp)
jne 0x4383
callq 0x2230
movl (%rax), %eax
movl %eax, 0x64(%rsp)
xorl %eax, %eax
cmpl 0xaf3a(%rip), %eax      # 0xf210
jg 0x4368
movq 0xacfd(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x28(%rsp)
xorl %edi, %edi
callq 0x4890
movq %rax, 0x30(%rsp)
movl 0xaf93(%rip), %eax      # 0xf290
movl %eax, 0x38(%rsp)
movl 0x78(%rsp), %eax
movl %eax, 0x3c(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x64(%rsp), %edi
callq 0x21e0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rdx
movl 0x38(%rsp), %r8d
movl 0x3c(%rsp), %r11d
movq 0x40(%rsp), %r10
leaq 0x6feb(%rip), %rsi      # 0xb327
leaq 0x6fd4(%rip), %rcx      # 0xb317
movl $0x1a8, %r9d            # imm = 0x1A8
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x2370
movl $0x1, %edi
callq 0x40f0
movl 0x7c(%rsp), %edi
callq 0x2080
xorl %eax, %eax
subl 0x64(%rsp), %eax
movl %eax, 0x94(%rsp)
jmp 0x4430
movl $0x3, %eax
cmpl 0xae82(%rip), %eax      # 0xf210
jg 0x43f0
movq 0xac49(%rip), %rax      # 0xefe0
movq (%rax), %rax
movq %rax, 0x20(%rsp)
movl $0x3, %edi
callq 0x4890
movq 0x20(%rsp), %rdi
movq %rax, %rdx
movl 0xaed8(%rip), %r8d      # 0xf290
movl 0x7c(%rsp), %r11d
movq 0x68(%rsp), %r10
movq 0x70(%rsp), %rax
leaq 0x6f83(%rip), %rsi      # 0xb351
leaq 0x6f42(%rip), %rcx      # 0xb317
movl $0x1ad, %r9d            # imm = 0x1AD
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
movb $0x0, %al
callq 0x2370
movl 0x7c(%rsp), %ecx
movslq 0x7c(%rsp), %rdx
leaq 0xaea0(%rip), %rax      # 0xf2a0
shlq $0x4, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movq 0x68(%rsp), %rcx
movslq 0x7c(%rsp), %rdx
leaq 0xae86(%rip), %rax      # 0xf2a0
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
movl 0x7c(%rsp), %eax
movl %eax, 0x94(%rsp)
movl 0x94(%rsp), %eax
addq $0x98, %rsp
retq
nop