static int write_console_data(SCLPEvent *event, const uint8_t *buf, int len)

{

    int ret = 0;

    const uint8_t *buf_offset;



    SCLPConsoleLM *scon = SCLPLM_CONSOLE(event);



    if (!scon->chr) {

        /* If there's no backend, we can just say we consumed all data. */

        return len;

    }



    buf_offset = buf;

    while (len > 0) {

        ret = qemu_chr_fe_write(scon->chr, buf, len);

        if (ret == 0) {

            /* a pty doesn't seem to be connected - no error */

            len = 0;

        } else if (ret == -EAGAIN || (ret > 0 && ret < len)) {

            len -= ret;

            buf_offset += ret;

        } else {

            len = 0;

        }

    }



    return ret;

}

static int write_console_data(SCLPEvent *event, const uint8_t *buf, int len)

{

    int ret = 0;

    const uint8_t *buf_offset;



    SCLPConsoleLM *scon = SCLPLM_CONSOLE(event);



    if (!scon->chr) {

        

        return len;

    }



    buf_offset = buf;

    while (len > 0) {

        ret = qemu_chr_fe_write(scon->chr, buf, len);

        if (ret == 0) {

            

            len = 0;

        } else if (ret == -EAGAIN || (ret > 0 && ret < len)) {

            len -= ret;

            buf_offset += ret;

        } else {

            len = 0;

        }

    }



    return ret;

}

static int FUNC_0(SCLPEvent *VAR_0, const uint8_t *VAR_1, int VAR_2)

{

    int VAR_3 = 0;

    const uint8_t *VAR_4;



    SCLPConsoleLM *scon = SCLPLM_CONSOLE(VAR_0);



    if (!scon->chr) {

        

        return VAR_2;

    }



    VAR_4 = VAR_1;

    while (VAR_2 > 0) {

        VAR_3 = qemu_chr_fe_write(scon->chr, VAR_1, VAR_2);

        if (VAR_3 == 0) {

            

            VAR_2 = 0;

        } else if (VAR_3 == -EAGAIN || (VAR_3 > 0 && VAR_3 < VAR_2)) {

            VAR_2 -= VAR_3;

            VAR_4 += VAR_3;

        } else {

            VAR_2 = 0;

        }

    }



    return VAR_3;

}

static int FUNC_0(SCLPEvent *VAR_0, const uint8_t *VAR_1, int VAR_2)
{ int VAR_3 = 0; const uint8_t *VAR_4; SCLPConsoleLM *scon = SCLPLM_CONSOLE(VAR_0); if (!scon->chr) { return VAR_2; } VAR_4 = VAR_1; while (VAR_2 > 0) { VAR_3 = qemu_chr_fe_write(scon->chr, VAR_1, VAR_2); if (VAR_3 == 0) { VAR_2 = 0; } else if (VAR_3 == -EAGAIN || (VAR_3 > 0 && VAR_3 < VAR_2)) { VAR_2 -= VAR_3; VAR_4 += VAR_3; } else { VAR_2 = 0; } } return VAR_3; }