static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)

{

    int pages = -1;

    uint64_t bytes_xmit;

    ram_addr_t current_addr;

    uint8_t *p;

    int ret;

    bool send_async = true;

    RAMBlock *block = pss->block;

    ram_addr_t offset = pss->page << TARGET_PAGE_BITS;



    p = block->host + offset;

    trace_ram_save_page(block->idstr, (uint64_t)offset, p);



    /* In doubt sent page as normal */

    bytes_xmit = 0;

    ret = ram_control_save_page(rs->f, block->offset,

                           offset, TARGET_PAGE_SIZE, &bytes_xmit);

    if (bytes_xmit) {

        rs->bytes_transferred += bytes_xmit;

        pages = 1;

    }



    XBZRLE_cache_lock();



    current_addr = block->offset + offset;



    if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {

        if (ret != RAM_SAVE_CONTROL_DELAYED) {

            if (bytes_xmit > 0) {

                rs->norm_pages++;

            } else if (bytes_xmit == 0) {

                rs->zero_pages++;

            }

        }

    } else {

        pages = save_zero_page(rs, block, offset, p);

        if (pages > 0) {

            /* Must let xbzrle know, otherwise a previous (now 0'd) cached

             * page would be stale

             */

            xbzrle_cache_zero_page(rs, current_addr);

            ram_release_pages(block->idstr, offset, pages);

        } else if (!rs->ram_bulk_stage &&

                   !migration_in_postcopy() && migrate_use_xbzrle()) {

            pages = save_xbzrle_page(rs, &p, current_addr, block,

                                     offset, last_stage);

            if (!last_stage) {

                /* Can't send this cached data async, since the cache page

                 * might get updated before it gets to the wire

                 */

                send_async = false;

            }

        }

    }



    /* XBZRLE overflow or normal page */

    if (pages == -1) {

        rs->bytes_transferred += save_page_header(rs, block,

                                                  offset | RAM_SAVE_FLAG_PAGE);

        if (send_async) {

            qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE,

                                  migrate_release_ram() &

                                  migration_in_postcopy());

        } else {

            qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE);

        }

        rs->bytes_transferred += TARGET_PAGE_SIZE;

        pages = 1;

        rs->norm_pages++;

    }



    XBZRLE_cache_unlock();



    return pages;

}

static int ram_save_page(RAMState *rs, PageSearchStatus *pss, bool last_stage)

{

    int pages = -1;

    uint64_t bytes_xmit;

    ram_addr_t current_addr;

    uint8_t *p;

    int ret;

    bool send_async = true;

    RAMBlock *block = pss->block;

    ram_addr_t offset = pss->page << TARGET_PAGE_BITS;



    p = block->host + offset;

    trace_ram_save_page(block->idstr, (uint64_t)offset, p);



    

    bytes_xmit = 0;

    ret = ram_control_save_page(rs->f, block->offset,

                           offset, TARGET_PAGE_SIZE, &bytes_xmit);

    if (bytes_xmit) {

        rs->bytes_transferred += bytes_xmit;

        pages = 1;

    }



    XBZRLE_cache_lock();



    current_addr = block->offset + offset;



    if (ret != RAM_SAVE_CONTROL_NOT_SUPP) {

        if (ret != RAM_SAVE_CONTROL_DELAYED) {

            if (bytes_xmit > 0) {

                rs->norm_pages++;

            } else if (bytes_xmit == 0) {

                rs->zero_pages++;

            }

        }

    } else {

        pages = save_zero_page(rs, block, offset, p);

        if (pages > 0) {

            





            xbzrle_cache_zero_page(rs, current_addr);

            ram_release_pages(block->idstr, offset, pages);

        } else if (!rs->ram_bulk_stage &&

                   !migration_in_postcopy() && migrate_use_xbzrle()) {

            pages = save_xbzrle_page(rs, &p, current_addr, block,

                                     offset, last_stage);

            if (!last_stage) {

                





                send_async = false;

            }

        }

    }



    

    if (pages == -1) {

        rs->bytes_transferred += save_page_header(rs, block,

                                                  offset | RAM_SAVE_FLAG_PAGE);

        if (send_async) {

            qemu_put_buffer_async(rs->f, p, TARGET_PAGE_SIZE,

                                  migrate_release_ram() &

                                  migration_in_postcopy());

        } else {

            qemu_put_buffer(rs->f, p, TARGET_PAGE_SIZE);

        }

        rs->bytes_transferred += TARGET_PAGE_SIZE;

        pages = 1;

        rs->norm_pages++;

    }



    XBZRLE_cache_unlock();



    return pages;

}

        rs->bytes_transferred += save_page_header(rs, block,
static int FUNC_0(RAMState *VAR_0, PageSearchStatus *VAR_1, bool VAR_2)

{

    int VAR_3 = -1;

    uint64_t bytes_xmit;

    ram_addr_t current_addr;

    uint8_t *p;

    int VAR_4;

    bool send_async = true;

    RAMBlock *block = VAR_1->block;

    ram_addr_t offset = VAR_1->page << TARGET_PAGE_BITS;



    p = block->host + offset;

    trace_ram_save_page(block->idstr, (uint64_t)offset, p);



    

    bytes_xmit = 0;

    VAR_4 = ram_control_save_page(VAR_0->f, block->offset,

                           offset, TARGET_PAGE_SIZE, &bytes_xmit);

    if (bytes_xmit) {

        VAR_0->bytes_transferred += bytes_xmit;

        VAR_3 = 1;

    }



    XBZRLE_cache_lock();



    current_addr = block->offset + offset;



    if (VAR_4 != RAM_SAVE_CONTROL_NOT_SUPP) {

        if (VAR_4 != RAM_SAVE_CONTROL_DELAYED) {

            if (bytes_xmit > 0) {

                VAR_0->norm_pages++;

            } else if (bytes_xmit == 0) {

                VAR_0->zero_pages++;

            }

        }

    } else {

        VAR_3 = save_zero_page(VAR_0, block, offset, p);

        if (VAR_3 > 0) {

            





            xbzrle_cache_zero_page(VAR_0, current_addr);

            ram_release_pages(block->idstr, offset, VAR_3);

        } else if (!VAR_0->ram_bulk_stage &&

                   !migration_in_postcopy() && migrate_use_xbzrle()) {

            VAR_3 = save_xbzrle_page(VAR_0, &p, current_addr, block,

                                     offset, VAR_2);

            if (!VAR_2) {

                





                send_async = false;

            }

        }

    }



    

    if (VAR_3 == -1) {

        VAR_0->bytes_transferred += save_page_header(VAR_0, block,

                                                  offset | RAM_SAVE_FLAG_PAGE);

        if (send_async) {

            qemu_put_buffer_async(VAR_0->f, p, TARGET_PAGE_SIZE,

                                  migrate_release_ram() &

                                  migration_in_postcopy());

        } else {

            qemu_put_buffer(VAR_0->f, p, TARGET_PAGE_SIZE);

        }

        VAR_0->bytes_transferred += TARGET_PAGE_SIZE;

        VAR_3 = 1;

        VAR_0->norm_pages++;

    }



    XBZRLE_cache_unlock();



    return VAR_3;

}

static int FUNC_0(RAMState *VAR_0, PageSearchStatus *VAR_1, bool VAR_2)
{ int VAR_3 = -1; uint64_t bytes_xmit; ram_addr_t current_addr; uint8_t *p; int VAR_4; bool send_async = true; RAMBlock *block = VAR_1->block; ram_addr_t offset = VAR_1->page << TARGET_PAGE_BITS; p = block->host + offset; trace_ram_save_page(block->idstr, (uint64_t)offset, p); bytes_xmit = 0; VAR_4 = ram_control_save_page(VAR_0->f, block->offset,
offset, TARGET_PAGE_SIZE, &bytes_xmit); if (bytes_xmit) { VAR_0->bytes_transferred += bytes_xmit; VAR_3 = 1; } XBZRLE_cache_lock(); current_addr = block->offset + offset; if (VAR_4 != RAM_SAVE_CONTROL_NOT_SUPP) { if (VAR_4 != RAM_SAVE_CONTROL_DELAYED) { if (bytes_xmit > 0) { VAR_0->norm_pages++; } else if (bytes_xmit == 0) { VAR_0->zero_pages++; } } } else { VAR_3 = save_zero_page(VAR_0, block, offset, p); if (VAR_3 > 0) { xbzrle_cache_zero_page(VAR_0, current_addr); ram_release_pages(block->idstr, offset, VAR_3); } else if (!VAR_0->ram_bulk_stage && !migration_in_postcopy() && migrate_use_xbzrle()) { VAR_3 = save_xbzrle_page(VAR_0, &p, current_addr, block,
offset, VAR_2); if (!VAR_2) { send_async = false; } } } if (VAR_3 == -1) { VAR_0->bytes_transferred += save_page_header(VAR_0, block,
offset | RAM_SAVE_FLAG_PAGE); if (send_async) { qemu_put_buffer_async(VAR_0->f, p, TARGET_PAGE_SIZE,
migrate_release_ram() &
migration_in_postcopy()); } else { qemu_put_buffer(VAR_0->f, p, TARGET_PAGE_SIZE); } VAR_0->bytes_transferred += TARGET_PAGE_SIZE; VAR_3 = 1; VAR_0->norm_pages++; } XBZRLE_cache_unlock(); return VAR_3; }