int usb_device_detach(USBDevice *dev)

{

    USBBus *bus = usb_bus_from_device(dev);

    USBPort *port;



    if (!dev->attached) {

        error_report("Error: tried to detach unattached usb device %s\n",

                dev->product_desc);

        return -1;

    }

    dev->attached--;



    QTAILQ_FOREACH(port, &bus->used, next) {

        if (port->dev == dev)

            break;

    }

    assert(port != NULL);



    QTAILQ_REMOVE(&bus->used, port, next);

    bus->nused--;



    usb_attach(port, NULL);



    QTAILQ_INSERT_TAIL(&bus->free, port, next);

    bus->nfree++;

    return 0;

}

int usb_device_detach(USBDevice *dev)

{

    USBBus *bus = usb_bus_from_device(dev);

    USBPort *port;



    if (!dev->attached) {

        error_report("Error: tried to detach unattached usb device %s\n",

                dev->product_desc);

        return -1;

    }

    dev->attached--;



    QTAILQ_FOREACH(port, &bus->used, next) {

        if (port->dev == dev)

            break;

    }

    assert(port != NULL);



    QTAILQ_REMOVE(&bus->used, port, next);

    bus->nused--;



    usb_attach(port, NULL);



    QTAILQ_INSERT_TAIL(&bus->free, port, next);

    bus->nfree++;

    return 0;

}

int FUNC_0(USBDevice *VAR_0)

{

    USBBus *bus = usb_bus_from_device(VAR_0);

    USBPort *port;



    if (!VAR_0->attached) {

        error_report("Error: tried to detach unattached usb device %s\n",

                VAR_0->product_desc);

        return -1;

    }

    VAR_0->attached--;



    QTAILQ_FOREACH(port, &bus->used, next) {

        if (port->VAR_0 == VAR_0)

            break;

    }

    assert(port != NULL);



    QTAILQ_REMOVE(&bus->used, port, next);

    bus->nused--;



    usb_attach(port, NULL);



    QTAILQ_INSERT_TAIL(&bus->free, port, next);

    bus->nfree++;

    return 0;

}

int FUNC_0(USBDevice *VAR_0)
{ USBBus *bus = usb_bus_from_device(VAR_0); USBPort *port; if (!VAR_0->attached) { error_report("Error: tried to detach unattached usb device %s\n",
VAR_0->product_desc); return -1; } VAR_0->attached--; QTAILQ_FOREACH(port, &bus->used, next) { if (port->VAR_0 == VAR_0)
break; } assert(port != NULL); QTAILQ_REMOVE(&bus->used, port, next); bus->nused--; usb_attach(port, NULL); QTAILQ_INSERT_TAIL(&bus->free, port, next); bus->nfree++; return 0; }