static int vfio_mmap_bar(VFIOBAR *bar, MemoryRegion *mem, MemoryRegion *submem,

                         void **map, size_t size, off_t offset,

                         const char *name)

{

    int ret = 0;



    if (size && bar->flags & VFIO_REGION_INFO_FLAG_MMAP) {

        int prot = 0;



        if (bar->flags & VFIO_REGION_INFO_FLAG_READ) {

            prot |= PROT_READ;

        }



        if (bar->flags & VFIO_REGION_INFO_FLAG_WRITE) {

            prot |= PROT_WRITE;

        }



        *map = mmap(NULL, size, prot, MAP_SHARED,

                    bar->fd, bar->fd_offset + offset);

        if (*map == MAP_FAILED) {

            *map = NULL;

            ret = -errno;

            goto empty_region;

        }



        memory_region_init_ram_ptr(submem, name, size, *map);

    } else {

empty_region:

        /* Create a zero sized sub-region to make cleanup easy. */

        memory_region_init(submem, name, 0);

    }



    memory_region_add_subregion(mem, offset, submem);



    return ret;

}

static int vfio_mmap_bar(VFIOBAR *bar, MemoryRegion *mem, MemoryRegion *submem,

                         void **map, size_t size, off_t offset,

                         const char *name)

{

    int ret = 0;



    if (size && bar->flags & VFIO_REGION_INFO_FLAG_MMAP) {

        int prot = 0;



        if (bar->flags & VFIO_REGION_INFO_FLAG_READ) {

            prot |= PROT_READ;

        }



        if (bar->flags & VFIO_REGION_INFO_FLAG_WRITE) {

            prot |= PROT_WRITE;

        }



        *map = mmap(NULL, size, prot, MAP_SHARED,

                    bar->fd, bar->fd_offset + offset);

        if (*map == MAP_FAILED) {

            *map = NULL;

            ret = -errno;

            goto empty_region;

        }



        memory_region_init_ram_ptr(submem, name, size, *map);

    } else {

empty_region:

        

        memory_region_init(submem, name, 0);

    }



    memory_region_add_subregion(mem, offset, submem);



    return ret;

}

static int FUNC_0(VFIOBAR *VAR_0, MemoryRegion *VAR_1, MemoryRegion *VAR_2,

                         void **VAR_3, size_t VAR_4, off_t VAR_5,

                         const char *VAR_6)

{

    int VAR_7 = 0;



    if (VAR_4 && VAR_0->flags & VFIO_REGION_INFO_FLAG_MMAP) {

        int VAR_8 = 0;



        if (VAR_0->flags & VFIO_REGION_INFO_FLAG_READ) {

            VAR_8 |= PROT_READ;

        }



        if (VAR_0->flags & VFIO_REGION_INFO_FLAG_WRITE) {

            VAR_8 |= PROT_WRITE;

        }



        *VAR_3 = mmap(NULL, VAR_4, VAR_8, MAP_SHARED,

                    VAR_0->fd, VAR_0->fd_offset + VAR_5);

        if (*VAR_3 == MAP_FAILED) {

            *VAR_3 = NULL;

            VAR_7 = -errno;

            goto empty_region;

        }



        memory_region_init_ram_ptr(VAR_2, VAR_6, VAR_4, *VAR_3);

    } else {

empty_region:

        

        memory_region_init(VAR_2, VAR_6, 0);

    }



    memory_region_add_subregion(VAR_1, VAR_5, VAR_2);



    return VAR_7;

}

static int FUNC_0(VFIOBAR *VAR_0, MemoryRegion *VAR_1, MemoryRegion *VAR_2,
void **VAR_3, size_t VAR_4, off_t VAR_5,
const char *VAR_6)
{ int VAR_7 = 0; if (VAR_4 && VAR_0->flags & VFIO_REGION_INFO_FLAG_MMAP) { int VAR_8 = 0; if (VAR_0->flags & VFIO_REGION_INFO_FLAG_READ) { VAR_8 |= PROT_READ; } if (VAR_0->flags & VFIO_REGION_INFO_FLAG_WRITE) { VAR_8 |= PROT_WRITE; } *VAR_3 = mmap(NULL, VAR_4, VAR_8, MAP_SHARED,
VAR_0->fd, VAR_0->fd_offset + VAR_5); if (*VAR_3 == MAP_FAILED) { *VAR_3 = NULL; VAR_7 = -errno; goto empty_region; } memory_region_init_ram_ptr(VAR_2, VAR_6, VAR_4, *VAR_3); } else { empty_region:
memory_region_init(VAR_2, VAR_6, 0); } memory_region_add_subregion(VAR_1, VAR_5, VAR_2); return VAR_7; }