static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len)

{

    uint64_t end = addr + len;



    if ((addr & 511) || len < 512)

        if (!sd->bdrv || bdrv_read(sd->bdrv, addr >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: read error on host side\n");

            return;

        }



    if (end > (addr & ~511) + 512) {

        memcpy(sd->buf + (addr & 511), sd->data, 512 - (addr & 511));

        if (bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: write error on host side\n");

            return;

        }



        if (bdrv_read(sd->bdrv, end >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: read error on host side\n");

            return;

        }

        memcpy(sd->buf, sd->data + 512 - (addr & 511), end & 511);

        if (bdrv_write(sd->bdrv, end >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: write error on host side\n");

        }

    } else {

        memcpy(sd->buf + (addr & 511), sd->data, len);

        if (!sd->bdrv || bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: write error on host side\n");

        }

    }

}

static void sd_blk_write(SDState *sd, uint64_t addr, uint32_t len)

{

    uint64_t end = addr + len;



    if ((addr & 511) || len < 512)

        if (!sd->bdrv || bdrv_read(sd->bdrv, addr >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: read error on host side\n");

            return;

        }



    if (end > (addr & ~511) + 512) {

        memcpy(sd->buf + (addr & 511), sd->data, 512 - (addr & 511));

        if (bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: write error on host side\n");

            return;

        }



        if (bdrv_read(sd->bdrv, end >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: read error on host side\n");

            return;

        }

        memcpy(sd->buf, sd->data + 512 - (addr & 511), end & 511);

        if (bdrv_write(sd->bdrv, end >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: write error on host side\n");

        }

    } else {

        memcpy(sd->buf + (addr & 511), sd->data, len);

        if (!sd->bdrv || bdrv_write(sd->bdrv, addr >> 9, sd->buf, 1) < 0) {

            fprintf(stderr, "sd_blk_write: write error on host side\n");

        }

    }

}

static void FUNC_0(SDState *VAR_0, uint64_t VAR_1, uint32_t VAR_2)

{

    uint64_t end = VAR_1 + VAR_2;



    if ((VAR_1 & 511) || VAR_2 < 512)

        if (!VAR_0->bdrv || bdrv_read(VAR_0->bdrv, VAR_1 >> 9, VAR_0->buf, 1) < 0) {

            fprintf(stderr, "FUNC_0: read error on host side\n");

            return;

        }



    if (end > (VAR_1 & ~511) + 512) {

        memcpy(VAR_0->buf + (VAR_1 & 511), VAR_0->data, 512 - (VAR_1 & 511));

        if (bdrv_write(VAR_0->bdrv, VAR_1 >> 9, VAR_0->buf, 1) < 0) {

            fprintf(stderr, "FUNC_0: write error on host side\n");

            return;

        }



        if (bdrv_read(VAR_0->bdrv, end >> 9, VAR_0->buf, 1) < 0) {

            fprintf(stderr, "FUNC_0: read error on host side\n");

            return;

        }

        memcpy(VAR_0->buf, VAR_0->data + 512 - (VAR_1 & 511), end & 511);

        if (bdrv_write(VAR_0->bdrv, end >> 9, VAR_0->buf, 1) < 0) {

            fprintf(stderr, "FUNC_0: write error on host side\n");

        }

    } else {

        memcpy(VAR_0->buf + (VAR_1 & 511), VAR_0->data, VAR_2);

        if (!VAR_0->bdrv || bdrv_write(VAR_0->bdrv, VAR_1 >> 9, VAR_0->buf, 1) < 0) {

            fprintf(stderr, "FUNC_0: write error on host side\n");

        }

    }

}

static void FUNC_0(SDState *VAR_0, uint64_t VAR_1, uint32_t VAR_2)
{ uint64_t end = VAR_1 + VAR_2; if ((VAR_1 & 511) || VAR_2 < 512)
if (!VAR_0->bdrv || bdrv_read(VAR_0->bdrv, VAR_1 >> 9, VAR_0->buf, 1) < 0) { fprintf(stderr, "FUNC_0: read error on host side\n"); return; } if (end > (VAR_1 & ~511) + 512) { memcpy(VAR_0->buf + (VAR_1 & 511), VAR_0->data, 512 - (VAR_1 & 511)); if (bdrv_write(VAR_0->bdrv, VAR_1 >> 9, VAR_0->buf, 1) < 0) { fprintf(stderr, "FUNC_0: write error on host side\n"); return; } if (bdrv_read(VAR_0->bdrv, end >> 9, VAR_0->buf, 1) < 0) { fprintf(stderr, "FUNC_0: read error on host side\n"); return; } memcpy(VAR_0->buf, VAR_0->data + 512 - (VAR_1 & 511), end & 511); if (bdrv_write(VAR_0->bdrv, end >> 9, VAR_0->buf, 1) < 0) { fprintf(stderr, "FUNC_0: write error on host side\n"); } } else { memcpy(VAR_0->buf + (VAR_1 & 511), VAR_0->data, VAR_2); if (!VAR_0->bdrv || bdrv_write(VAR_0->bdrv, VAR_1 >> 9, VAR_0->buf, 1) < 0) { fprintf(stderr, "FUNC_0: write error on host side\n"); } } }