ram_addr_t migration_bitmap_find_and_reset_dirty(MemoryRegion *mr,

                                                 ram_addr_t start)

{

    unsigned long base = mr->ram_addr >> TARGET_PAGE_BITS;

    unsigned long nr = base + (start >> TARGET_PAGE_BITS);

    uint64_t mr_size = TARGET_PAGE_ALIGN(memory_region_size(mr));

    unsigned long size = base + (mr_size >> TARGET_PAGE_BITS);



    unsigned long next;



    if (ram_bulk_stage && nr > base) {

        next = nr + 1;

    } else {

        next = find_next_bit(migration_bitmap, size, nr);

    }



    if (next < size) {

        clear_bit(next, migration_bitmap);

        migration_dirty_pages--;

    }

    return (next - base) << TARGET_PAGE_BITS;

}

ram_addr_t migration_bitmap_find_and_reset_dirty(MemoryRegion *mr,

                                                 ram_addr_t start)

{

    unsigned long base = mr->ram_addr >> TARGET_PAGE_BITS;

    unsigned long nr = base + (start >> TARGET_PAGE_BITS);

    uint64_t mr_size = TARGET_PAGE_ALIGN(memory_region_size(mr));

    unsigned long size = base + (mr_size >> TARGET_PAGE_BITS);



    unsigned long next;



    if (ram_bulk_stage && nr > base) {

        next = nr + 1;

    } else {

        next = find_next_bit(migration_bitmap, size, nr);

    }



    if (next < size) {

        clear_bit(next, migration_bitmap);

        migration_dirty_pages--;

    }

    return (next - base) << TARGET_PAGE_BITS;

}

ram_addr_t FUNC_0(MemoryRegion *mr,

                                                 ram_addr_t start)

{

    unsigned long VAR_0 = mr->ram_addr >> TARGET_PAGE_BITS;

    unsigned long VAR_1 = VAR_0 + (start >> TARGET_PAGE_BITS);

    uint64_t mr_size = TARGET_PAGE_ALIGN(memory_region_size(mr));

    unsigned long VAR_2 = VAR_0 + (mr_size >> TARGET_PAGE_BITS);



    unsigned long VAR_3;



    if (ram_bulk_stage && VAR_1 > VAR_0) {

        VAR_3 = VAR_1 + 1;

    } else {

        VAR_3 = find_next_bit(migration_bitmap, VAR_2, VAR_1);

    }



    if (VAR_3 < VAR_2) {

        clear_bit(VAR_3, migration_bitmap);

        migration_dirty_pages--;

    }

    return (VAR_3 - VAR_0) << TARGET_PAGE_BITS;

}

ram_addr_t FUNC_0(MemoryRegion *mr,
ram_addr_t start)
{ unsigned long VAR_0 = mr->ram_addr >> TARGET_PAGE_BITS; unsigned long VAR_1 = VAR_0 + (start >> TARGET_PAGE_BITS); uint64_t mr_size = TARGET_PAGE_ALIGN(memory_region_size(mr)); unsigned long VAR_2 = VAR_0 + (mr_size >> TARGET_PAGE_BITS); unsigned long VAR_3; if (ram_bulk_stage && VAR_1 > VAR_0) { VAR_3 = VAR_1 + 1; } else { VAR_3 = find_next_bit(migration_bitmap, VAR_2, VAR_1); } if (VAR_3 < VAR_2) { clear_bit(VAR_3, migration_bitmap); migration_dirty_pages--; } return (VAR_3 - VAR_0) << TARGET_PAGE_BITS; }