void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,

                               unsigned int *out_bytes)

{

    unsigned int idx;

    unsigned int total_bufs, in_total, out_total;



    idx = vq->last_avail_idx;



    total_bufs = in_total = out_total = 0;

    while (virtqueue_num_heads(vq, idx)) {

        unsigned int max, num_bufs, indirect = 0;

        hwaddr desc_pa;

        int i;



        max = vq->vring.num;

        num_bufs = total_bufs;

        i = virtqueue_get_head(vq, idx++);

        desc_pa = vq->vring.desc;



        if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) {

            if (vring_desc_len(desc_pa, i) % sizeof(VRingDesc)) {

                error_report("Invalid size for indirect buffer table");

                exit(1);

            }



            /* If we've got too many, that implies a descriptor loop. */

            if (num_bufs >= max) {

                error_report("Looped descriptor");

                exit(1);

            }



            /* loop over the indirect descriptor table */

            indirect = 1;

            max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);

            num_bufs = i = 0;

            desc_pa = vring_desc_addr(desc_pa, i);

        }



        do {

            /* If we've got too many, that implies a descriptor loop. */

            if (++num_bufs > max) {

                error_report("Looped descriptor");

                exit(1);

            }



            if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_WRITE) {

                in_total += vring_desc_len(desc_pa, i);

            } else {

                out_total += vring_desc_len(desc_pa, i);

            }

        } while ((i = virtqueue_next_desc(desc_pa, i, max)) != max);



        if (!indirect)

            total_bufs = num_bufs;

        else

            total_bufs++;

    }

    if (in_bytes) {

        *in_bytes = in_total;

    }

    if (out_bytes) {

        *out_bytes = out_total;

    }

}

void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,

                               unsigned int *out_bytes)

{

    unsigned int idx;

    unsigned int total_bufs, in_total, out_total;



    idx = vq->last_avail_idx;



    total_bufs = in_total = out_total = 0;

    while (virtqueue_num_heads(vq, idx)) {

        unsigned int max, num_bufs, indirect = 0;

        hwaddr desc_pa;

        int i;



        max = vq->vring.num;

        num_bufs = total_bufs;

        i = virtqueue_get_head(vq, idx++);

        desc_pa = vq->vring.desc;



        if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) {

            if (vring_desc_len(desc_pa, i) % sizeof(VRingDesc)) {

                error_report("Invalid size for indirect buffer table");

                exit(1);

            }



            

            if (num_bufs >= max) {

                error_report("Looped descriptor");

                exit(1);

            }



            

            indirect = 1;

            max = vring_desc_len(desc_pa, i) / sizeof(VRingDesc);

            num_bufs = i = 0;

            desc_pa = vring_desc_addr(desc_pa, i);

        }



        do {

            

            if (++num_bufs > max) {

                error_report("Looped descriptor");

                exit(1);

            }



            if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_WRITE) {

                in_total += vring_desc_len(desc_pa, i);

            } else {

                out_total += vring_desc_len(desc_pa, i);

            }

        } while ((i = virtqueue_next_desc(desc_pa, i, max)) != max);



        if (!indirect)

            total_bufs = num_bufs;

        else

            total_bufs++;

    }

    if (in_bytes) {

        *in_bytes = in_total;

    }

    if (out_bytes) {

        *out_bytes = out_total;

    }

}

void FUNC_0(VirtQueue *VAR_0, unsigned int *VAR_1,

                               unsigned int *VAR_2)

{

    unsigned int VAR_3;

    unsigned int VAR_4, VAR_5, VAR_6;



    VAR_3 = VAR_0->last_avail_idx;



    VAR_4 = VAR_5 = VAR_6 = 0;

    while (virtqueue_num_heads(VAR_0, VAR_3)) {

        unsigned int VAR_7, VAR_8, VAR_9 = 0;

        hwaddr desc_pa;

        int VAR_10;



        VAR_7 = VAR_0->vring.num;

        VAR_8 = VAR_4;

        VAR_10 = virtqueue_get_head(VAR_0, VAR_3++);

        desc_pa = VAR_0->vring.desc;



        if (vring_desc_flags(desc_pa, VAR_10) & VRING_DESC_F_INDIRECT) {

            if (vring_desc_len(desc_pa, VAR_10) % sizeof(VRingDesc)) {

                error_report("Invalid size for VAR_9 buffer table");

                exit(1);

            }



            

            if (VAR_8 >= VAR_7) {

                error_report("Looped descriptor");

                exit(1);

            }



            

            VAR_9 = 1;

            VAR_7 = vring_desc_len(desc_pa, VAR_10) / sizeof(VRingDesc);

            VAR_8 = VAR_10 = 0;

            desc_pa = vring_desc_addr(desc_pa, VAR_10);

        }



        do {

            

            if (++VAR_8 > VAR_7) {

                error_report("Looped descriptor");

                exit(1);

            }



            if (vring_desc_flags(desc_pa, VAR_10) & VRING_DESC_F_WRITE) {

                VAR_5 += vring_desc_len(desc_pa, VAR_10);

            } else {

                VAR_6 += vring_desc_len(desc_pa, VAR_10);

            }

        } while ((VAR_10 = virtqueue_next_desc(desc_pa, VAR_10, VAR_7)) != VAR_7);



        if (!VAR_9)

            VAR_4 = VAR_8;

        else

            VAR_4++;

    }

    if (VAR_1) {

        *VAR_1 = VAR_5;

    }

    if (VAR_2) {

        *VAR_2 = VAR_6;

    }

}

void FUNC_0(VirtQueue *VAR_0, unsigned int *VAR_1,
unsigned int *VAR_2)
{ unsigned int VAR_3; unsigned int VAR_4, VAR_5, VAR_6; VAR_3 = VAR_0->last_avail_idx; VAR_4 = VAR_5 = VAR_6 = 0; while (virtqueue_num_heads(VAR_0, VAR_3)) { unsigned int VAR_7, VAR_8, VAR_9 = 0; hwaddr desc_pa; int VAR_10; VAR_7 = VAR_0->vring.num; VAR_8 = VAR_4; VAR_10 = virtqueue_get_head(VAR_0, VAR_3++); desc_pa = VAR_0->vring.desc; if (vring_desc_flags(desc_pa, VAR_10) & VRING_DESC_F_INDIRECT) { if (vring_desc_len(desc_pa, VAR_10) % sizeof(VRingDesc)) { error_report("Invalid size for VAR_9 buffer table"); exit(1); } if (VAR_8 >= VAR_7) { error_report("Looped descriptor"); exit(1); } VAR_9 = 1; VAR_7 = vring_desc_len(desc_pa, VAR_10) / sizeof(VRingDesc); VAR_8 = VAR_10 = 0; desc_pa = vring_desc_addr(desc_pa, VAR_10); } do { if (++VAR_8 > VAR_7) { error_report("Looped descriptor"); exit(1); } if (vring_desc_flags(desc_pa, VAR_10) & VRING_DESC_F_WRITE) { VAR_5 += vring_desc_len(desc_pa, VAR_10); } else { VAR_6 += vring_desc_len(desc_pa, VAR_10); } } while ((VAR_10 = virtqueue_next_desc(desc_pa, VAR_10, VAR_7)) != VAR_7); if (!VAR_9)
VAR_4 = VAR_8; else
VAR_4++; } if (VAR_1) { *VAR_1 = VAR_5; } if (VAR_2) { *VAR_2 = VAR_6; } }