void qmp_memsave(int64_t addr, int64_t size, const char *filename,

                 bool has_cpu, int64_t cpu_index, Error **errp)

{

    FILE *f;

    uint32_t l;

    CPUState *cpu;

    uint8_t buf[1024];



    if (!has_cpu) {

        cpu_index = 0;

    }



    cpu = qemu_get_cpu(cpu_index);

    if (cpu == NULL) {

        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",

                  "a CPU number");

        return;

    }



    f = fopen(filename, "wb");

    if (!f) {

        error_setg_file_open(errp, errno, filename);

        return;

    }



    while (size != 0) {

        l = sizeof(buf);

        if (l > size)

            l = size;

        cpu_memory_rw_debug(cpu, addr, buf, l, 0);

        if (fwrite(buf, 1, l, f) != l) {

            error_set(errp, QERR_IO_ERROR);

            goto exit;

        }

        addr += l;

        size -= l;

    }



exit:

    fclose(f);

}

void qmp_memsave(int64_t addr, int64_t size, const char *filename,

                 bool has_cpu, int64_t cpu_index, Error **errp)

{

    FILE *f;

    uint32_t l;

    CPUState *cpu;

    uint8_t buf[1024];



    if (!has_cpu) {

        cpu_index = 0;

    }



    cpu = qemu_get_cpu(cpu_index);

    if (cpu == NULL) {

        error_set(errp, QERR_INVALID_PARAMETER_VALUE, "cpu-index",

                  "a CPU number");

        return;

    }



    f = fopen(filename, "wb");

    if (!f) {

        error_setg_file_open(errp, errno, filename);

        return;

    }



    while (size != 0) {

        l = sizeof(buf);

        if (l > size)

            l = size;

        cpu_memory_rw_debug(cpu, addr, buf, l, 0);

        if (fwrite(buf, 1, l, f) != l) {

            error_set(errp, QERR_IO_ERROR);

            goto exit;

        }

        addr += l;

        size -= l;

    }



exit:

    fclose(f);

}

void FUNC_0(int64_t VAR_0, int64_t VAR_1, const char *VAR_2,

                 bool VAR_3, int64_t VAR_4, Error **VAR_5)

{

    FILE *f;

    uint32_t l;

    CPUState *cpu;

    uint8_t buf[1024];



    if (!VAR_3) {

        VAR_4 = 0;

    }



    cpu = qemu_get_cpu(VAR_4);

    if (cpu == NULL) {

        error_set(VAR_5, QERR_INVALID_PARAMETER_VALUE, "cpu-index",

                  "a CPU number");

        return;

    }



    f = fopen(VAR_2, "wb");

    if (!f) {

        error_setg_file_open(VAR_5, errno, VAR_2);

        return;

    }



    while (VAR_1 != 0) {

        l = sizeof(buf);

        if (l > VAR_1)

            l = VAR_1;

        cpu_memory_rw_debug(cpu, VAR_0, buf, l, 0);

        if (fwrite(buf, 1, l, f) != l) {

            error_set(VAR_5, QERR_IO_ERROR);

            goto exit;

        }

        VAR_0 += l;

        VAR_1 -= l;

    }



exit:

    fclose(f);

}

void FUNC_0(int64_t VAR_0, int64_t VAR_1, const char *VAR_2,
bool VAR_3, int64_t VAR_4, Error **VAR_5)
{ FILE *f; uint32_t l; CPUState *cpu; uint8_t buf[1024]; if (!VAR_3) { VAR_4 = 0; } cpu = qemu_get_cpu(VAR_4); if (cpu == NULL) { error_set(VAR_5, QERR_INVALID_PARAMETER_VALUE, "cpu-index",
"a CPU number"); return; } f = fopen(VAR_2, "wb"); if (!f) { error_setg_file_open(VAR_5, errno, VAR_2); return; } while (VAR_1 != 0) { l = sizeof(buf); if (l > VAR_1)
l = VAR_1; cpu_memory_rw_debug(cpu, VAR_0, buf, l, 0); if (fwrite(buf, 1, l, f) != l) { error_set(VAR_5, QERR_IO_ERROR); goto exit; } VAR_0 += l; VAR_1 -= l; } exit:
fclose(f); }