static int mux_chr_write(CharDriverState *chr, const uint8_t *buf, int len)

{

    MuxDriver *d = chr->opaque;

    int ret;

    if (!d->timestamps) {

        ret = d->drv->chr_write(d->drv, buf, len);

    } else {

        int i;



        ret = 0;

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

            if (d->linestart) {

                char buf1[64];

                int64_t ti;

                int secs;



                ti = qemu_get_clock(rt_clock);

                if (d->timestamps_start == -1)

                    d->timestamps_start = ti;

                ti -= d->timestamps_start;

                secs = ti / 1000;

                snprintf(buf1, sizeof(buf1),

                         "[%02d:%02d:%02d.%03d] ",

                         secs / 3600,

                         (secs / 60) % 60,

                         secs % 60,

                         (int)(ti % 1000));

                d->drv->chr_write(d->drv, (uint8_t *)buf1, strlen(buf1));

                d->linestart = 0;

            }

            ret += d->drv->chr_write(d->drv, buf+i, 1);

            if (buf[i] == '\n') {

                d->linestart = 1;

            }

        }

    }

    return ret;

}

static int mux_chr_write(CharDriverState *chr, const uint8_t *buf, int len)

{

    MuxDriver *d = chr->opaque;

    int ret;

    if (!d->timestamps) {

        ret = d->drv->chr_write(d->drv, buf, len);

    } else {

        int i;



        ret = 0;

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

            if (d->linestart) {

                char buf1[64];

                int64_t ti;

                int secs;



                ti = qemu_get_clock(rt_clock);

                if (d->timestamps_start == -1)

                    d->timestamps_start = ti;

                ti -= d->timestamps_start;

                secs = ti / 1000;

                snprintf(buf1, sizeof(buf1),

                         "[%02d:%02d:%02d.%03d] ",

                         secs / 3600,

                         (secs / 60) % 60,

                         secs % 60,

                         (int)(ti % 1000));

                d->drv->chr_write(d->drv, (uint8_t *)buf1, strlen(buf1));

                d->linestart = 0;

            }

            ret += d->drv->chr_write(d->drv, buf+i, 1);

            if (buf[i] == '\n') {

                d->linestart = 1;

            }

        }

    }

    return ret;

}

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

{

    MuxDriver *d = VAR_0->opaque;

    int VAR_3;

    if (!d->timestamps) {

        VAR_3 = d->drv->chr_write(d->drv, VAR_1, VAR_2);

    } else {

        int VAR_4;



        VAR_3 = 0;

        for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) {

            if (d->linestart) {

                char VAR_5[64];

                int64_t ti;

                int VAR_6;



                ti = qemu_get_clock(rt_clock);

                if (d->timestamps_start == -1)

                    d->timestamps_start = ti;

                ti -= d->timestamps_start;

                VAR_6 = ti / 1000;

                snprintf(VAR_5, sizeof(VAR_5),

                         "[%02d:%02d:%02d.%03d] ",

                         VAR_6 / 3600,

                         (VAR_6 / 60) % 60,

                         VAR_6 % 60,

                         (int)(ti % 1000));

                d->drv->chr_write(d->drv, (uint8_t *)VAR_5, strlen(VAR_5));

                d->linestart = 0;

            }

            VAR_3 += d->drv->chr_write(d->drv, VAR_1+VAR_4, 1);

            if (VAR_1[VAR_4] == '\n') {

                d->linestart = 1;

            }

        }

    }

    return VAR_3;

}

static int FUNC_0(CharDriverState *VAR_0, const uint8_t *VAR_1, int VAR_2)
{ MuxDriver *d = VAR_0->opaque; int VAR_3; if (!d->timestamps) { VAR_3 = d->drv->chr_write(d->drv, VAR_1, VAR_2); } else { int VAR_4; VAR_3 = 0; for (VAR_4 = 0; VAR_4 < VAR_2; VAR_4++) { if (d->linestart) { char VAR_5[64]; int64_t ti; int VAR_6; ti = qemu_get_clock(rt_clock); if (d->timestamps_start == -1)
d->timestamps_start = ti; ti -= d->timestamps_start; VAR_6 = ti / 1000; snprintf(VAR_5, sizeof(VAR_5),
"[%02d:%02d:%02d.%03d] ",
VAR_6 / 3600,
(VAR_6 / 60) % 60,
VAR_6 % 60,
(int)(ti % 1000)); d->drv->chr_write(d->drv, (uint8_t *)VAR_5, strlen(VAR_5)); d->linestart = 0; } VAR_3 += d->drv->chr_write(d->drv, VAR_1+VAR_4, 1); if (VAR_1[VAR_4] == '\n') { d->linestart = 1; } } } return VAR_3; }