void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,

                        void *opaque, QJSON *vmdesc)

{

    VMStateField *field = vmsd->fields;



    trace_vmstate_save_state_top(vmsd->name);



    if (vmsd->pre_save) {

        vmsd->pre_save(opaque);

    }



    if (vmdesc) {

        json_prop_str(vmdesc, "vmsd_name", vmsd->name);

        json_prop_int(vmdesc, "version", vmsd->version_id);

        json_start_array(vmdesc, "fields");

    }



    while (field->name) {

        if (!field->field_exists ||

            field->field_exists(opaque, vmsd->version_id)) {

            void *first_elem = opaque + field->offset;

            int i, n_elems = vmstate_n_elems(opaque, field);

            int size = vmstate_size(opaque, field);

            int64_t old_offset, written_bytes;

            QJSON *vmdesc_loop = vmdesc;



            trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems);

            if (field->flags & VMS_POINTER) {

                first_elem = *(void **)first_elem;

                assert(first_elem  || !n_elems);

            }

            for (i = 0; i < n_elems; i++) {

                void *curr_elem = first_elem + size * i;



                vmsd_desc_field_start(vmsd, vmdesc_loop, field, i, n_elems);

                old_offset = qemu_ftell_fast(f);

                if (field->flags & VMS_ARRAY_OF_POINTER) {

                    assert(curr_elem);

                    curr_elem = *(void **)curr_elem;

                }

                if (field->flags & VMS_STRUCT) {

                    vmstate_save_state(f, field->vmsd, curr_elem, vmdesc_loop);

                } else {

                    field->info->put(f, curr_elem, size, field, vmdesc_loop);

                }



                written_bytes = qemu_ftell_fast(f) - old_offset;

                vmsd_desc_field_end(vmsd, vmdesc_loop, field, written_bytes, i);



                /* Compressed arrays only care about the first element */

                if (vmdesc_loop && vmsd_can_compress(field)) {

                    vmdesc_loop = NULL;

                }

            }

        } else {

            if (field->flags & VMS_MUST_EXIST) {

                error_report("Output state validation failed: %s/%s",

                        vmsd->name, field->name);

                assert(!(field->flags & VMS_MUST_EXIST));

            }

        }

        field++;

    }



    if (vmdesc) {

        json_end_array(vmdesc);

    }



    vmstate_subsection_save(f, vmsd, opaque, vmdesc);

}

void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,

                        void *opaque, QJSON *vmdesc)

{

    VMStateField *field = vmsd->fields;



    trace_vmstate_save_state_top(vmsd->name);



    if (vmsd->pre_save) {

        vmsd->pre_save(opaque);

    }



    if (vmdesc) {

        json_prop_str(vmdesc, "vmsd_name", vmsd->name);

        json_prop_int(vmdesc, "version", vmsd->version_id);

        json_start_array(vmdesc, "fields");

    }



    while (field->name) {

        if (!field->field_exists ||

            field->field_exists(opaque, vmsd->version_id)) {

            void *first_elem = opaque + field->offset;

            int i, n_elems = vmstate_n_elems(opaque, field);

            int size = vmstate_size(opaque, field);

            int64_t old_offset, written_bytes;

            QJSON *vmdesc_loop = vmdesc;



            trace_vmstate_save_state_loop(vmsd->name, field->name, n_elems);

            if (field->flags & VMS_POINTER) {

                first_elem = *(void **)first_elem;

                assert(first_elem  || !n_elems);

            }

            for (i = 0; i < n_elems; i++) {

                void *curr_elem = first_elem + size * i;



                vmsd_desc_field_start(vmsd, vmdesc_loop, field, i, n_elems);

                old_offset = qemu_ftell_fast(f);

                if (field->flags & VMS_ARRAY_OF_POINTER) {

                    assert(curr_elem);

                    curr_elem = *(void **)curr_elem;

                }

                if (field->flags & VMS_STRUCT) {

                    vmstate_save_state(f, field->vmsd, curr_elem, vmdesc_loop);

                } else {

                    field->info->put(f, curr_elem, size, field, vmdesc_loop);

                }



                written_bytes = qemu_ftell_fast(f) - old_offset;

                vmsd_desc_field_end(vmsd, vmdesc_loop, field, written_bytes, i);



                

                if (vmdesc_loop && vmsd_can_compress(field)) {

                    vmdesc_loop = NULL;

                }

            }

        } else {

            if (field->flags & VMS_MUST_EXIST) {

                error_report("Output state validation failed: %s/%s",

                        vmsd->name, field->name);

                assert(!(field->flags & VMS_MUST_EXIST));

            }

        }

        field++;

    }



    if (vmdesc) {

        json_end_array(vmdesc);

    }



    vmstate_subsection_save(f, vmsd, opaque, vmdesc);

}

                if (field->flags & VMS_STRUCT) {                 if (field->flags & VMS_STRUCT) {
void FUNC_0(QEMUFile *VAR_0, const VMStateDescription *VAR_1,

                        void *VAR_2, QJSON *VAR_3)

{

    VMStateField *field = VAR_1->fields;



    trace_vmstate_save_state_top(VAR_1->name);



    if (VAR_1->pre_save) {

        VAR_1->pre_save(VAR_2);

    }



    if (VAR_3) {

        json_prop_str(VAR_3, "vmsd_name", VAR_1->name);

        json_prop_int(VAR_3, "version", VAR_1->version_id);

        json_start_array(VAR_3, "fields");

    }



    while (field->name) {

        if (!field->field_exists ||

            field->field_exists(VAR_2, VAR_1->version_id)) {

            void *VAR_4 = VAR_2 + field->offset;

            int VAR_5, VAR_6 = vmstate_n_elems(VAR_2, field);

            int VAR_7 = vmstate_size(VAR_2, field);

            int64_t old_offset, written_bytes;

            QJSON *vmdesc_loop = VAR_3;



            trace_vmstate_save_state_loop(VAR_1->name, field->name, VAR_6);

            if (field->flags & VMS_POINTER) {

                VAR_4 = *(void **)VAR_4;

                assert(VAR_4  || !VAR_6);

            }

            for (VAR_5 = 0; VAR_5 < VAR_6; VAR_5++) {

                void *VAR_8 = VAR_4 + VAR_7 * VAR_5;



                vmsd_desc_field_start(VAR_1, vmdesc_loop, field, VAR_5, VAR_6);

                old_offset = qemu_ftell_fast(VAR_0);

                if (field->flags & VMS_ARRAY_OF_POINTER) {

                    assert(VAR_8);

                    VAR_8 = *(void **)VAR_8;

                }

                if (field->flags & VMS_STRUCT) {

                    FUNC_0(VAR_0, field->VAR_1, VAR_8, vmdesc_loop);

                } else {

                    field->info->put(VAR_0, VAR_8, VAR_7, field, vmdesc_loop);

                }



                written_bytes = qemu_ftell_fast(VAR_0) - old_offset;

                vmsd_desc_field_end(VAR_1, vmdesc_loop, field, written_bytes, VAR_5);



                

                if (vmdesc_loop && vmsd_can_compress(field)) {

                    vmdesc_loop = NULL;

                }

            }

        } else {

            if (field->flags & VMS_MUST_EXIST) {

                error_report("Output state validation failed: %s/%s",

                        VAR_1->name, field->name);

                assert(!(field->flags & VMS_MUST_EXIST));

            }

        }

        field++;

    }



    if (VAR_3) {

        json_end_array(VAR_3);

    }



    vmstate_subsection_save(VAR_0, VAR_1, VAR_2, VAR_3);

}

void FUNC_0(QEMUFile *VAR_0, const VMStateDescription *VAR_1,
void *VAR_2, QJSON *VAR_3)
{ VMStateField *field = VAR_1->fields; trace_vmstate_save_state_top(VAR_1->name); if (VAR_1->pre_save) { VAR_1->pre_save(VAR_2); } if (VAR_3) { json_prop_str(VAR_3, "vmsd_name", VAR_1->name); json_prop_int(VAR_3, "version", VAR_1->version_id); json_start_array(VAR_3, "fields"); } while (field->name) { if (!field->field_exists ||
field->field_exists(VAR_2, VAR_1->version_id)) { void *VAR_4 = VAR_2 + field->offset; int VAR_5, VAR_6 = vmstate_n_elems(VAR_2, field); int VAR_7 = vmstate_size(VAR_2, field); int64_t old_offset, written_bytes; QJSON *vmdesc_loop = VAR_3; trace_vmstate_save_state_loop(VAR_1->name, field->name, VAR_6); if (field->flags & VMS_POINTER) { VAR_4 = *(void **)VAR_4; assert(VAR_4  || !VAR_6); } for (VAR_5 = 0; VAR_5 < VAR_6; VAR_5++) { void *VAR_8 = VAR_4 + VAR_7 * VAR_5; vmsd_desc_field_start(VAR_1, vmdesc_loop, field, VAR_5, VAR_6); old_offset = qemu_ftell_fast(VAR_0); if (field->flags & VMS_ARRAY_OF_POINTER) { assert(VAR_8); VAR_8 = *(void **)VAR_8; } if (field->flags & VMS_STRUCT) { FUNC_0(VAR_0, field->VAR_1, VAR_8, vmdesc_loop); } else { field->info->put(VAR_0, VAR_8, VAR_7, field, vmdesc_loop); } written_bytes = qemu_ftell_fast(VAR_0) - old_offset; vmsd_desc_field_end(VAR_1, vmdesc_loop, field, written_bytes, VAR_5); if (vmdesc_loop && vmsd_can_compress(field)) { vmdesc_loop = NULL; } } } else { if (field->flags & VMS_MUST_EXIST) { error_report("Output state validation failed: %s/%s",
VAR_1->name, field->name); assert(!(field->flags & VMS_MUST_EXIST)); } } field++; } if (VAR_3) { json_end_array(VAR_3); } vmstate_subsection_save(VAR_0, VAR_1, VAR_2, VAR_3); }