void usb_packet_complete(USBDevice *dev, USBPacket *p)

{

    USBEndpoint *ep = p->ep;

    int ret;



    assert(p->state == USB_PACKET_ASYNC);

    assert(QTAILQ_FIRST(&ep->queue) == p);

    usb_packet_set_state(p, USB_PACKET_COMPLETE);

    QTAILQ_REMOVE(&ep->queue, p, queue);

    dev->port->ops->complete(dev->port, p);



    while (!QTAILQ_EMPTY(&ep->queue)) {

        p = QTAILQ_FIRST(&ep->queue);

        if (p->state == USB_PACKET_ASYNC) {

            break;

        }

        assert(p->state == USB_PACKET_QUEUED);

        ret = usb_process_one(p);

        if (ret == USB_RET_ASYNC) {

            usb_packet_set_state(p, USB_PACKET_ASYNC);

            break;

        }

        p->result = ret;

        usb_packet_set_state(p, USB_PACKET_COMPLETE);

        QTAILQ_REMOVE(&ep->queue, p, queue);

        dev->port->ops->complete(dev->port, p);

    }

}

void usb_packet_complete(USBDevice *dev, USBPacket *p)

{

    USBEndpoint *ep = p->ep;

    int ret;



    assert(p->state == USB_PACKET_ASYNC);

    assert(QTAILQ_FIRST(&ep->queue) == p);

    usb_packet_set_state(p, USB_PACKET_COMPLETE);

    QTAILQ_REMOVE(&ep->queue, p, queue);

    dev->port->ops->complete(dev->port, p);



    while (!QTAILQ_EMPTY(&ep->queue)) {

        p = QTAILQ_FIRST(&ep->queue);

        if (p->state == USB_PACKET_ASYNC) {

            break;

        }

        assert(p->state == USB_PACKET_QUEUED);

        ret = usb_process_one(p);

        if (ret == USB_RET_ASYNC) {

            usb_packet_set_state(p, USB_PACKET_ASYNC);

            break;

        }

        p->result = ret;

        usb_packet_set_state(p, USB_PACKET_COMPLETE);

        QTAILQ_REMOVE(&ep->queue, p, queue);

        dev->port->ops->complete(dev->port, p);

    }

}

    assert(p->state == USB_PACKET_ASYNC);         assert(p->state == USB_PACKET_QUEUED);
void FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)

{

    USBEndpoint *ep = VAR_1->ep;

    int VAR_2;



    assert(VAR_1->state == USB_PACKET_ASYNC);

    assert(QTAILQ_FIRST(&ep->queue) == VAR_1);

    usb_packet_set_state(VAR_1, USB_PACKET_COMPLETE);

    QTAILQ_REMOVE(&ep->queue, VAR_1, queue);

    VAR_0->port->ops->complete(VAR_0->port, VAR_1);



    while (!QTAILQ_EMPTY(&ep->queue)) {

        VAR_1 = QTAILQ_FIRST(&ep->queue);

        if (VAR_1->state == USB_PACKET_ASYNC) {

            break;

        }

        assert(VAR_1->state == USB_PACKET_QUEUED);

        VAR_2 = usb_process_one(VAR_1);

        if (VAR_2 == USB_RET_ASYNC) {

            usb_packet_set_state(VAR_1, USB_PACKET_ASYNC);

            break;

        }

        VAR_1->result = VAR_2;

        usb_packet_set_state(VAR_1, USB_PACKET_COMPLETE);

        QTAILQ_REMOVE(&ep->queue, VAR_1, queue);

        VAR_0->port->ops->complete(VAR_0->port, VAR_1);

    }

}

void FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)
{ USBEndpoint *ep = VAR_1->ep; int VAR_2; assert(VAR_1->state == USB_PACKET_ASYNC); assert(QTAILQ_FIRST(&ep->queue) == VAR_1); usb_packet_set_state(VAR_1, USB_PACKET_COMPLETE); QTAILQ_REMOVE(&ep->queue, VAR_1, queue); VAR_0->port->ops->complete(VAR_0->port, VAR_1); while (!QTAILQ_EMPTY(&ep->queue)) { VAR_1 = QTAILQ_FIRST(&ep->queue); if (VAR_1->state == USB_PACKET_ASYNC) { break; } assert(VAR_1->state == USB_PACKET_QUEUED); VAR_2 = usb_process_one(VAR_1); if (VAR_2 == USB_RET_ASYNC) { usb_packet_set_state(VAR_1, USB_PACKET_ASYNC); break; } VAR_1->result = VAR_2; usb_packet_set_state(VAR_1, USB_PACKET_COMPLETE); QTAILQ_REMOVE(&ep->queue, VAR_1, queue); VAR_0->port->ops->complete(VAR_0->port, VAR_1); } }