static void vhost_set_memory(MemoryListener *listener,

                             MemoryRegionSection *section,

                             bool add)

{

    struct vhost_dev *dev = container_of(listener, struct vhost_dev,

                                         memory_listener);

    hwaddr start_addr = section->offset_within_address_space;

    ram_addr_t size = int128_get64(section->size);

    bool log_dirty = memory_region_is_logging(section->mr);

    int s = offsetof(struct vhost_memory, regions) +

        (dev->mem->nregions + 1) * sizeof dev->mem->regions[0];

    void *ram;



    dev->mem = g_realloc(dev->mem, s);



    if (log_dirty) {

        add = false;

    }



    assert(size);



    /* Optimize no-change case. At least cirrus_vga does this a lot at this time. */

    ram = memory_region_get_ram_ptr(section->mr) + section->offset_within_region;

    if (add) {

        if (!vhost_dev_cmp_memory(dev, start_addr, size, (uintptr_t)ram)) {

            /* Region exists with same address. Nothing to do. */

            return;

        }

    } else {

        if (!vhost_dev_find_reg(dev, start_addr, size)) {

            /* Removing region that we don't access. Nothing to do. */

            return;

        }

    }



    vhost_dev_unassign_memory(dev, start_addr, size);

    if (add) {

        /* Add given mapping, merging adjacent regions if any */

        vhost_dev_assign_memory(dev, start_addr, size, (uintptr_t)ram);

    } else {

        /* Remove old mapping for this memory, if any. */

        vhost_dev_unassign_memory(dev, start_addr, size);

    }

    dev->mem_changed_start_addr = MIN(dev->mem_changed_start_addr, start_addr);

    dev->mem_changed_end_addr = MAX(dev->mem_changed_end_addr, start_addr + size - 1);

    dev->memory_changed = true;

}

static void vhost_set_memory(MemoryListener *listener,

                             MemoryRegionSection *section,

                             bool add)

{

    struct vhost_dev *dev = container_of(listener, struct vhost_dev,

                                         memory_listener);

    hwaddr start_addr = section->offset_within_address_space;

    ram_addr_t size = int128_get64(section->size);

    bool log_dirty = memory_region_is_logging(section->mr);

    int s = offsetof(struct vhost_memory, regions) +

        (dev->mem->nregions + 1) * sizeof dev->mem->regions[0];

    void *ram;



    dev->mem = g_realloc(dev->mem, s);



    if (log_dirty) {

        add = false;

    }



    assert(size);



    

    ram = memory_region_get_ram_ptr(section->mr) + section->offset_within_region;

    if (add) {

        if (!vhost_dev_cmp_memory(dev, start_addr, size, (uintptr_t)ram)) {

            

            return;

        }

    } else {

        if (!vhost_dev_find_reg(dev, start_addr, size)) {

            

            return;

        }

    }



    vhost_dev_unassign_memory(dev, start_addr, size);

    if (add) {

        

        vhost_dev_assign_memory(dev, start_addr, size, (uintptr_t)ram);

    } else {

        

        vhost_dev_unassign_memory(dev, start_addr, size);

    }

    dev->mem_changed_start_addr = MIN(dev->mem_changed_start_addr, start_addr);

    dev->mem_changed_end_addr = MAX(dev->mem_changed_end_addr, start_addr + size - 1);

    dev->memory_changed = true;

}

static void FUNC_0(MemoryListener *VAR_0,

                             MemoryRegionSection *VAR_1,

                             bool VAR_2)

{

    struct vhost_dev *VAR_3 = container_of(VAR_0, struct vhost_dev,

                                         memory_listener);

    hwaddr start_addr = VAR_1->offset_within_address_space;

    ram_addr_t size = int128_get64(VAR_1->size);

    bool log_dirty = memory_region_is_logging(VAR_1->mr);

    int VAR_4 = offsetof(struct vhost_memory, regions) +

        (VAR_3->mem->nregions + 1) * sizeof VAR_3->mem->regions[0];

    void *VAR_5;



    VAR_3->mem = g_realloc(VAR_3->mem, VAR_4);



    if (log_dirty) {

        VAR_2 = false;

    }



    assert(size);



    

    VAR_5 = memory_region_get_ram_ptr(VAR_1->mr) + VAR_1->offset_within_region;

    if (VAR_2) {

        if (!vhost_dev_cmp_memory(VAR_3, start_addr, size, (uintptr_t)VAR_5)) {

            

            return;

        }

    } else {

        if (!vhost_dev_find_reg(VAR_3, start_addr, size)) {

            

            return;

        }

    }



    vhost_dev_unassign_memory(VAR_3, start_addr, size);

    if (VAR_2) {

        

        vhost_dev_assign_memory(VAR_3, start_addr, size, (uintptr_t)VAR_5);

    } else {

        

        vhost_dev_unassign_memory(VAR_3, start_addr, size);

    }

    VAR_3->mem_changed_start_addr = MIN(VAR_3->mem_changed_start_addr, start_addr);

    VAR_3->mem_changed_end_addr = MAX(VAR_3->mem_changed_end_addr, start_addr + size - 1);

    VAR_3->memory_changed = true;

}

static void FUNC_0(MemoryListener *VAR_0,
MemoryRegionSection *VAR_1,
bool VAR_2)
{ struct vhost_dev *VAR_3 = container_of(VAR_0, struct vhost_dev,
memory_listener); hwaddr start_addr = VAR_1->offset_within_address_space; ram_addr_t size = int128_get64(VAR_1->size); bool log_dirty = memory_region_is_logging(VAR_1->mr); int VAR_4 = offsetof(struct vhost_memory, regions) +
(VAR_3->mem->nregions + 1) * sizeof VAR_3->mem->regions[0]; void *VAR_5; VAR_3->mem = g_realloc(VAR_3->mem, VAR_4); if (log_dirty) { VAR_2 = false; } assert(size); VAR_5 = memory_region_get_ram_ptr(VAR_1->mr) + VAR_1->offset_within_region; if (VAR_2) { if (!vhost_dev_cmp_memory(VAR_3, start_addr, size, (uintptr_t)VAR_5)) { return; } } else { if (!vhost_dev_find_reg(VAR_3, start_addr, size)) { return; } } vhost_dev_unassign_memory(VAR_3, start_addr, size); if (VAR_2) { vhost_dev_assign_memory(VAR_3, start_addr, size, (uintptr_t)VAR_5); } else { vhost_dev_unassign_memory(VAR_3, start_addr, size); } VAR_3->mem_changed_start_addr = MIN(VAR_3->mem_changed_start_addr, start_addr); VAR_3->mem_changed_end_addr = MAX(VAR_3->mem_changed_end_addr, start_addr + size - 1); VAR_3->memory_changed = true; }