static int csrhci_write(struct CharDriverState *chr,

                const uint8_t *buf, int len)

{

    struct csrhci_s *s = (struct csrhci_s *) chr->opaque;

    int plen = s->in_len;



    if (!s->enable)

        return 0;



    s->in_len += len;

    memcpy(s->inpkt + plen, buf, len);



    while (1) {

        if (s->in_len >= 2 && plen < 2)

            s->in_hdr = csrhci_header_len(s->inpkt) + 1;



        if (s->in_len >= s->in_hdr && plen < s->in_hdr)

            s->in_data = csrhci_data_len(s->inpkt) + s->in_hdr;



        if (s->in_len >= s->in_data) {

            csrhci_in_packet(s, s->inpkt);



            memmove(s->inpkt, s->inpkt + s->in_len, s->in_len - s->in_data);

            s->in_len -= s->in_data;

            s->in_hdr = INT_MAX;

            s->in_data = INT_MAX;

            plen = 0;

        } else

            break;

    }



    return len;

}

static int csrhci_write(struct CharDriverState *chr,

                const uint8_t *buf, int len)

{

    struct csrhci_s *s = (struct csrhci_s *) chr->opaque;

    int plen = s->in_len;



    if (!s->enable)

        return 0;



    s->in_len += len;

    memcpy(s->inpkt + plen, buf, len);



    while (1) {

        if (s->in_len >= 2 && plen < 2)

            s->in_hdr = csrhci_header_len(s->inpkt) + 1;



        if (s->in_len >= s->in_hdr && plen < s->in_hdr)

            s->in_data = csrhci_data_len(s->inpkt) + s->in_hdr;



        if (s->in_len >= s->in_data) {

            csrhci_in_packet(s, s->inpkt);



            memmove(s->inpkt, s->inpkt + s->in_len, s->in_len - s->in_data);

            s->in_len -= s->in_data;

            s->in_hdr = INT_MAX;

            s->in_data = INT_MAX;

            plen = 0;

        } else

            break;

    }



    return len;

}

    int plen = s->in_len;     s->in_len += len;     memcpy(s->inpkt + plen, buf, len);     while (1) {         if (s->in_len >= 2 && plen < 2)         if (s->in_len >= s->in_hdr && plen < s->in_hdr)             s->in_data = csrhci_data_len(s->inpkt) + s->in_hdr;         if (s->in_len >= s->in_data) {             memmove(s->inpkt, s->inpkt + s->in_len, s->in_len - s->in_data);             s->in_len -= s->in_data;             s->in_hdr = INT_MAX;             s->in_data = INT_MAX;             plen = 0;         } else             break;     return len;
static int FUNC_0(struct CharDriverState *VAR_0,

                const uint8_t *VAR_1, int VAR_2)

{

    struct csrhci_s *VAR_3 = (struct csrhci_s *) VAR_0->opaque;

    int VAR_4 = VAR_3->in_len;



    if (!VAR_3->enable)

        return 0;



    VAR_3->in_len += VAR_2;

    memcpy(VAR_3->inpkt + VAR_4, VAR_1, VAR_2);



    while (1) {

        if (VAR_3->in_len >= 2 && VAR_4 < 2)

            VAR_3->in_hdr = csrhci_header_len(VAR_3->inpkt) + 1;



        if (VAR_3->in_len >= VAR_3->in_hdr && VAR_4 < VAR_3->in_hdr)

            VAR_3->in_data = csrhci_data_len(VAR_3->inpkt) + VAR_3->in_hdr;



        if (VAR_3->in_len >= VAR_3->in_data) {

            csrhci_in_packet(VAR_3, VAR_3->inpkt);



            memmove(VAR_3->inpkt, VAR_3->inpkt + VAR_3->in_len, VAR_3->in_len - VAR_3->in_data);

            VAR_3->in_len -= VAR_3->in_data;

            VAR_3->in_hdr = INT_MAX;

            VAR_3->in_data = INT_MAX;

            VAR_4 = 0;

        } else

            break;

    }



    return VAR_2;

}

static int FUNC_0(struct CharDriverState *VAR_0,
const uint8_t *VAR_1, int VAR_2)
{ struct csrhci_s *VAR_3 = (struct csrhci_s *) VAR_0->opaque; int VAR_4 = VAR_3->in_len; if (!VAR_3->enable)
return 0; VAR_3->in_len += VAR_2; memcpy(VAR_3->inpkt + VAR_4, VAR_1, VAR_2); while (1) { if (VAR_3->in_len >= 2 && VAR_4 < 2)
VAR_3->in_hdr = csrhci_header_len(VAR_3->inpkt) + 1; if (VAR_3->in_len >= VAR_3->in_hdr && VAR_4 < VAR_3->in_hdr)
VAR_3->in_data = csrhci_data_len(VAR_3->inpkt) + VAR_3->in_hdr; if (VAR_3->in_len >= VAR_3->in_data) { csrhci_in_packet(VAR_3, VAR_3->inpkt); memmove(VAR_3->inpkt, VAR_3->inpkt + VAR_3->in_len, VAR_3->in_len - VAR_3->in_data); VAR_3->in_len -= VAR_3->in_data; VAR_3->in_hdr = INT_MAX; VAR_3->in_data = INT_MAX; VAR_4 = 0; } else break; } return VAR_2; }