static int save_xbzrle_page(QEMUFile *f, uint8_t **current_data,

                            ram_addr_t current_addr, RAMBlock *block,

                            ram_addr_t offset, int cont, bool last_stage)

{

    int encoded_len = 0, bytes_sent = -1;

    uint8_t *prev_cached_page;



    if (!cache_is_cached(XBZRLE.cache, current_addr)) {

        acct_info.xbzrle_cache_miss++;

        if (!last_stage) {

            if (cache_insert(XBZRLE.cache, current_addr, *current_data) == -1) {

                return -1;

            } else {

                /* update *current_data when the page has been

                   inserted into cache */

                *current_data = get_cached_data(XBZRLE.cache, current_addr);

            }

        }

        return -1;

    }



    prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);



    /* save current buffer into memory */

    memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE);



    /* XBZRLE encoding (if there is no overflow) */

    encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,

                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,

                                       TARGET_PAGE_SIZE);

    if (encoded_len == 0) {

        DPRINTF("Skipping unmodified page\n");

        return 0;

    } else if (encoded_len == -1) {

        DPRINTF("Overflow\n");

        acct_info.xbzrle_overflows++;

        /* update data in the cache */

        if (!last_stage) {

            memcpy(prev_cached_page, *current_data, TARGET_PAGE_SIZE);

            *current_data = prev_cached_page;

        }

        return -1;

    }



    /* we need to update the data in the cache, in order to get the same data */

    if (!last_stage) {

        memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE);

    }



    /* Send XBZRLE based compressed page */

    bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);

    qemu_put_byte(f, ENCODING_FLAG_XBZRLE);

    qemu_put_be16(f, encoded_len);

    qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);

    bytes_sent += encoded_len + 1 + 2;

    acct_info.xbzrle_pages++;

    acct_info.xbzrle_bytes += bytes_sent;



    return bytes_sent;

}

static int save_xbzrle_page(QEMUFile *f, uint8_t **current_data,

                            ram_addr_t current_addr, RAMBlock *block,

                            ram_addr_t offset, int cont, bool last_stage)

{

    int encoded_len = 0, bytes_sent = -1;

    uint8_t *prev_cached_page;



    if (!cache_is_cached(XBZRLE.cache, current_addr)) {

        acct_info.xbzrle_cache_miss++;

        if (!last_stage) {

            if (cache_insert(XBZRLE.cache, current_addr, *current_data) == -1) {

                return -1;

            } else {

                



                *current_data = get_cached_data(XBZRLE.cache, current_addr);

            }

        }

        return -1;

    }



    prev_cached_page = get_cached_data(XBZRLE.cache, current_addr);



    

    memcpy(XBZRLE.current_buf, *current_data, TARGET_PAGE_SIZE);



    

    encoded_len = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,

                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,

                                       TARGET_PAGE_SIZE);

    if (encoded_len == 0) {

        DPRINTF("Skipping unmodified page\n");

        return 0;

    } else if (encoded_len == -1) {

        DPRINTF("Overflow\n");

        acct_info.xbzrle_overflows++;

        

        if (!last_stage) {

            memcpy(prev_cached_page, *current_data, TARGET_PAGE_SIZE);

            *current_data = prev_cached_page;

        }

        return -1;

    }



    

    if (!last_stage) {

        memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE);

    }



    

    bytes_sent = save_block_hdr(f, block, offset, cont, RAM_SAVE_FLAG_XBZRLE);

    qemu_put_byte(f, ENCODING_FLAG_XBZRLE);

    qemu_put_be16(f, encoded_len);

    qemu_put_buffer(f, XBZRLE.encoded_buf, encoded_len);

    bytes_sent += encoded_len + 1 + 2;

    acct_info.xbzrle_pages++;

    acct_info.xbzrle_bytes += bytes_sent;



    return bytes_sent;

}

    if (!cache_is_cached(XBZRLE.cache, current_addr)) {             if (cache_insert(XBZRLE.cache, current_addr, *current_data) == -1) {
static int FUNC_0(QEMUFile *VAR_0, uint8_t **VAR_1,

                            ram_addr_t VAR_2, RAMBlock *VAR_3,

                            ram_addr_t VAR_4, int VAR_5, bool VAR_6)

{

    int VAR_7 = 0, VAR_8 = -1;

    uint8_t *prev_cached_page;



    if (!cache_is_cached(XBZRLE.cache, VAR_2)) {

        acct_info.xbzrle_cache_miss++;

        if (!VAR_6) {

            if (cache_insert(XBZRLE.cache, VAR_2, *VAR_1) == -1) {

                return -1;

            } else {

                



                *VAR_1 = get_cached_data(XBZRLE.cache, VAR_2);

            }

        }

        return -1;

    }



    prev_cached_page = get_cached_data(XBZRLE.cache, VAR_2);



    

    memcpy(XBZRLE.current_buf, *VAR_1, TARGET_PAGE_SIZE);



    

    VAR_7 = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,

                                       TARGET_PAGE_SIZE, XBZRLE.encoded_buf,

                                       TARGET_PAGE_SIZE);

    if (VAR_7 == 0) {

        DPRINTF("Skipping unmodified page\n");

        return 0;

    } else if (VAR_7 == -1) {

        DPRINTF("Overflow\n");

        acct_info.xbzrle_overflows++;

        

        if (!VAR_6) {

            memcpy(prev_cached_page, *VAR_1, TARGET_PAGE_SIZE);

            *VAR_1 = prev_cached_page;

        }

        return -1;

    }



    

    if (!VAR_6) {

        memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE);

    }



    

    VAR_8 = save_block_hdr(VAR_0, VAR_3, VAR_4, VAR_5, RAM_SAVE_FLAG_XBZRLE);

    qemu_put_byte(VAR_0, ENCODING_FLAG_XBZRLE);

    qemu_put_be16(VAR_0, VAR_7);

    qemu_put_buffer(VAR_0, XBZRLE.encoded_buf, VAR_7);

    VAR_8 += VAR_7 + 1 + 2;

    acct_info.xbzrle_pages++;

    acct_info.xbzrle_bytes += VAR_8;



    return VAR_8;

}

static int FUNC_0(QEMUFile *VAR_0, uint8_t **VAR_1,
ram_addr_t VAR_2, RAMBlock *VAR_3,
ram_addr_t VAR_4, int VAR_5, bool VAR_6)
{ int VAR_7 = 0, VAR_8 = -1; uint8_t *prev_cached_page; if (!cache_is_cached(XBZRLE.cache, VAR_2)) { acct_info.xbzrle_cache_miss++; if (!VAR_6) { if (cache_insert(XBZRLE.cache, VAR_2, *VAR_1) == -1) { return -1; } else { *VAR_1 = get_cached_data(XBZRLE.cache, VAR_2); } } return -1; } prev_cached_page = get_cached_data(XBZRLE.cache, VAR_2); memcpy(XBZRLE.current_buf, *VAR_1, TARGET_PAGE_SIZE); VAR_7 = xbzrle_encode_buffer(prev_cached_page, XBZRLE.current_buf,
TARGET_PAGE_SIZE, XBZRLE.encoded_buf,
TARGET_PAGE_SIZE); if (VAR_7 == 0) { DPRINTF("Skipping unmodified page\n"); return 0; } else if (VAR_7 == -1) { DPRINTF("Overflow\n"); acct_info.xbzrle_overflows++; if (!VAR_6) { memcpy(prev_cached_page, *VAR_1, TARGET_PAGE_SIZE); *VAR_1 = prev_cached_page; } return -1; } if (!VAR_6) { memcpy(prev_cached_page, XBZRLE.current_buf, TARGET_PAGE_SIZE); } VAR_8 = save_block_hdr(VAR_0, VAR_3, VAR_4, VAR_5, RAM_SAVE_FLAG_XBZRLE); qemu_put_byte(VAR_0, ENCODING_FLAG_XBZRLE); qemu_put_be16(VAR_0, VAR_7); qemu_put_buffer(VAR_0, XBZRLE.encoded_buf, VAR_7); VAR_8 += VAR_7 + 1 + 2; acct_info.xbzrle_pages++; acct_info.xbzrle_bytes += VAR_8; return VAR_8; }