static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,

                                int64_t max_ns)

{

    bool final = max_ns < 0;

    int htabslots = HTAB_SIZE(spapr) / HASH_PTE_SIZE_64;

    int examined = 0, sent = 0;

    int index = spapr->htab_save_index;

    int64_t starttime = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);



    assert(!spapr->htab_first_pass);



    do {

        int chunkstart, invalidstart;



        /* Consume non-dirty HPTEs */

        while ((index < htabslots)

               && !HPTE_DIRTY(HPTE(spapr->htab, index))) {

            index++;

            examined++;

        }



        chunkstart = index;

        /* Consume valid dirty HPTEs */

        while ((index < htabslots)

               && HPTE_DIRTY(HPTE(spapr->htab, index))

               && HPTE_VALID(HPTE(spapr->htab, index))) {

            CLEAN_HPTE(HPTE(spapr->htab, index));

            index++;

            examined++;

        }



        invalidstart = index;

        /* Consume invalid dirty HPTEs */

        while ((index < htabslots)

               && HPTE_DIRTY(HPTE(spapr->htab, index))

               && !HPTE_VALID(HPTE(spapr->htab, index))) {

            CLEAN_HPTE(HPTE(spapr->htab, index));

            index++;

            examined++;

        }



        if (index > chunkstart) {

            int n_valid = invalidstart - chunkstart;

            int n_invalid = index - invalidstart;



            qemu_put_be32(f, chunkstart);

            qemu_put_be16(f, n_valid);

            qemu_put_be16(f, n_invalid);

            qemu_put_buffer(f, HPTE(spapr->htab, chunkstart),

                            HASH_PTE_SIZE_64 * n_valid);

            sent += index - chunkstart;



            if (!final && (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - starttime) > max_ns) {

                break;

            }

        }



        if (examined >= htabslots) {

            break;

        }



        if (index >= htabslots) {

            assert(index == htabslots);

            index = 0;

        }

    } while ((examined < htabslots) && (!qemu_file_rate_limit(f) || final));



    if (index >= htabslots) {

        assert(index == htabslots);

        index = 0;

    }



    spapr->htab_save_index = index;



    return (examined >= htabslots) && (sent == 0) ? 1 : 0;

}

static int htab_save_later_pass(QEMUFile *f, sPAPREnvironment *spapr,

                                int64_t max_ns)

{

    bool final = max_ns < 0;

    int htabslots = HTAB_SIZE(spapr) / HASH_PTE_SIZE_64;

    int examined = 0, sent = 0;

    int index = spapr->htab_save_index;

    int64_t starttime = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);



    assert(!spapr->htab_first_pass);



    do {

        int chunkstart, invalidstart;



        

        while ((index < htabslots)

               && !HPTE_DIRTY(HPTE(spapr->htab, index))) {

            index++;

            examined++;

        }



        chunkstart = index;

        

        while ((index < htabslots)

               && HPTE_DIRTY(HPTE(spapr->htab, index))

               && HPTE_VALID(HPTE(spapr->htab, index))) {

            CLEAN_HPTE(HPTE(spapr->htab, index));

            index++;

            examined++;

        }



        invalidstart = index;

        

        while ((index < htabslots)

               && HPTE_DIRTY(HPTE(spapr->htab, index))

               && !HPTE_VALID(HPTE(spapr->htab, index))) {

            CLEAN_HPTE(HPTE(spapr->htab, index));

            index++;

            examined++;

        }



        if (index > chunkstart) {

            int n_valid = invalidstart - chunkstart;

            int n_invalid = index - invalidstart;



            qemu_put_be32(f, chunkstart);

            qemu_put_be16(f, n_valid);

            qemu_put_be16(f, n_invalid);

            qemu_put_buffer(f, HPTE(spapr->htab, chunkstart),

                            HASH_PTE_SIZE_64 * n_valid);

            sent += index - chunkstart;



            if (!final && (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - starttime) > max_ns) {

                break;

            }

        }



        if (examined >= htabslots) {

            break;

        }



        if (index >= htabslots) {

            assert(index == htabslots);

            index = 0;

        }

    } while ((examined < htabslots) && (!qemu_file_rate_limit(f) || final));



    if (index >= htabslots) {

        assert(index == htabslots);

        index = 0;

    }



    spapr->htab_save_index = index;



    return (examined >= htabslots) && (sent == 0) ? 1 : 0;

}

        while ((index < htabslots)         while ((index < htabslots)         while ((index < htabslots)
static int FUNC_0(QEMUFile *VAR_0, sPAPREnvironment *VAR_1,

                                int64_t VAR_2)

{

    bool final = VAR_2 < 0;

    int VAR_3 = HTAB_SIZE(VAR_1) / HASH_PTE_SIZE_64;

    int VAR_4 = 0, VAR_5 = 0;

    int VAR_6 = VAR_1->htab_save_index;

    int64_t starttime = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);



    assert(!VAR_1->htab_first_pass);



    do {

        int VAR_7, VAR_8;



        

        while ((VAR_6 < VAR_3)

               && !HPTE_DIRTY(HPTE(VAR_1->htab, VAR_6))) {

            VAR_6++;

            VAR_4++;

        }



        VAR_7 = VAR_6;

        

        while ((VAR_6 < VAR_3)

               && HPTE_DIRTY(HPTE(VAR_1->htab, VAR_6))

               && HPTE_VALID(HPTE(VAR_1->htab, VAR_6))) {

            CLEAN_HPTE(HPTE(VAR_1->htab, VAR_6));

            VAR_6++;

            VAR_4++;

        }



        VAR_8 = VAR_6;

        

        while ((VAR_6 < VAR_3)

               && HPTE_DIRTY(HPTE(VAR_1->htab, VAR_6))

               && !HPTE_VALID(HPTE(VAR_1->htab, VAR_6))) {

            CLEAN_HPTE(HPTE(VAR_1->htab, VAR_6));

            VAR_6++;

            VAR_4++;

        }



        if (VAR_6 > VAR_7) {

            int VAR_9 = VAR_8 - VAR_7;

            int VAR_10 = VAR_6 - VAR_8;



            qemu_put_be32(VAR_0, VAR_7);

            qemu_put_be16(VAR_0, VAR_9);

            qemu_put_be16(VAR_0, VAR_10);

            qemu_put_buffer(VAR_0, HPTE(VAR_1->htab, VAR_7),

                            HASH_PTE_SIZE_64 * VAR_9);

            VAR_5 += VAR_6 - VAR_7;



            if (!final && (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - starttime) > VAR_2) {

                break;

            }

        }



        if (VAR_4 >= VAR_3) {

            break;

        }



        if (VAR_6 >= VAR_3) {

            assert(VAR_6 == VAR_3);

            VAR_6 = 0;

        }

    } while ((VAR_4 < VAR_3) && (!qemu_file_rate_limit(VAR_0) || final));



    if (VAR_6 >= VAR_3) {

        assert(VAR_6 == VAR_3);

        VAR_6 = 0;

    }



    VAR_1->htab_save_index = VAR_6;



    return (VAR_4 >= VAR_3) && (VAR_5 == 0) ? 1 : 0;

}

static int FUNC_0(QEMUFile *VAR_0, sPAPREnvironment *VAR_1,
int64_t VAR_2)
{ bool final = VAR_2 < 0; int VAR_3 = HTAB_SIZE(VAR_1) / HASH_PTE_SIZE_64; int VAR_4 = 0, VAR_5 = 0; int VAR_6 = VAR_1->htab_save_index; int64_t starttime = qemu_clock_get_ns(QEMU_CLOCK_REALTIME); assert(!VAR_1->htab_first_pass); do { int VAR_7, VAR_8; while ((VAR_6 < VAR_3)
&& !HPTE_DIRTY(HPTE(VAR_1->htab, VAR_6))) { VAR_6++; VAR_4++; } VAR_7 = VAR_6; while ((VAR_6 < VAR_3)
&& HPTE_DIRTY(HPTE(VAR_1->htab, VAR_6))
&& HPTE_VALID(HPTE(VAR_1->htab, VAR_6))) { CLEAN_HPTE(HPTE(VAR_1->htab, VAR_6)); VAR_6++; VAR_4++; } VAR_8 = VAR_6; while ((VAR_6 < VAR_3)
&& HPTE_DIRTY(HPTE(VAR_1->htab, VAR_6))
&& !HPTE_VALID(HPTE(VAR_1->htab, VAR_6))) { CLEAN_HPTE(HPTE(VAR_1->htab, VAR_6)); VAR_6++; VAR_4++; } if (VAR_6 > VAR_7) { int VAR_9 = VAR_8 - VAR_7; int VAR_10 = VAR_6 - VAR_8; qemu_put_be32(VAR_0, VAR_7); qemu_put_be16(VAR_0, VAR_9); qemu_put_be16(VAR_0, VAR_10); qemu_put_buffer(VAR_0, HPTE(VAR_1->htab, VAR_7),
HASH_PTE_SIZE_64 * VAR_9); VAR_5 += VAR_6 - VAR_7; if (!final && (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) - starttime) > VAR_2) { break; } } if (VAR_4 >= VAR_3) { break; } if (VAR_6 >= VAR_3) { assert(VAR_6 == VAR_3); VAR_6 = 0; } } while ((VAR_4 < VAR_3) && (!qemu_file_rate_limit(VAR_0) || final)); if (VAR_6 >= VAR_3) { assert(VAR_6 == VAR_3); VAR_6 = 0; } VAR_1->htab_save_index = VAR_6; return (VAR_4 >= VAR_3) && (VAR_5 == 0) ? 1 : 0; }