int pci_parse_devaddr(const char *addr, int *domp, int *busp,

                      unsigned int *slotp, unsigned int *funcp)

{

    const char *p;

    char *e;

    unsigned long val;

    unsigned long dom = 0, bus = 0;

    unsigned int slot = 0;

    unsigned int func = 0;



    p = addr;

    val = strtoul(p, &e, 16);

    if (e == p)

	return -1;

    if (*e == ':') {

	bus = val;

	p = e + 1;

	val = strtoul(p, &e, 16);

	if (e == p)

	    return -1;

	if (*e == ':') {

	    dom = bus;

	    bus = val;

	    p = e + 1;

	    val = strtoul(p, &e, 16);

	    if (e == p)

		return -1;

	}

    }



    slot = val;



    if (funcp != NULL) {

        if (*e != '.')

            return -1;



        p = e + 1;

        val = strtoul(p, &e, 16);

        if (e == p)

            return -1;



        func = val;

    }



    /* if funcp == NULL func is 0 */

    if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7)

	return -1;



    if (*e)

	return -1;



    /* Note: QEMU doesn't implement domains other than 0 */

    if (!pci_find_bus(pci_find_root_bus(dom), bus))

	return -1;



    *domp = dom;

    *busp = bus;

    *slotp = slot;

    if (funcp != NULL)

        *funcp = func;

    return 0;

}

int pci_parse_devaddr(const char *addr, int *domp, int *busp,

                      unsigned int *slotp, unsigned int *funcp)

{

    const char *p;

    char *e;

    unsigned long val;

    unsigned long dom = 0, bus = 0;

    unsigned int slot = 0;

    unsigned int func = 0;



    p = addr;

    val = strtoul(p, &e, 16);

    if (e == p)

	return -1;

    if (*e == ':') {

	bus = val;

	p = e + 1;

	val = strtoul(p, &e, 16);

	if (e == p)

	    return -1;

	if (*e == ':') {

	    dom = bus;

	    bus = val;

	    p = e + 1;

	    val = strtoul(p, &e, 16);

	    if (e == p)

		return -1;

	}

    }



    slot = val;



    if (funcp != NULL) {

        if (*e != '.')

            return -1;



        p = e + 1;

        val = strtoul(p, &e, 16);

        if (e == p)

            return -1;



        func = val;

    }



    

    if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7)

	return -1;



    if (*e)

	return -1;



    

    if (!pci_find_bus(pci_find_root_bus(dom), bus))

	return -1;



    *domp = dom;

    *busp = bus;

    *slotp = slot;

    if (funcp != NULL)

        *funcp = func;

    return 0;

}

int FUNC_0(const char *VAR_0, int *VAR_1, int *VAR_2,

                      unsigned int *VAR_3, unsigned int *VAR_4)

{

    const char *VAR_5;

    char *VAR_6;

    unsigned long VAR_7;

    unsigned long VAR_8 = 0, VAR_9 = 0;

    unsigned int VAR_10 = 0;

    unsigned int VAR_11 = 0;



    VAR_5 = VAR_0;

    VAR_7 = strtoul(VAR_5, &VAR_6, 16);

    if (VAR_6 == VAR_5)

	return -1;

    if (*VAR_6 == ':') {

	VAR_9 = VAR_7;

	VAR_5 = VAR_6 + 1;

	VAR_7 = strtoul(VAR_5, &VAR_6, 16);

	if (VAR_6 == VAR_5)

	    return -1;

	if (*VAR_6 == ':') {

	    VAR_8 = VAR_9;

	    VAR_9 = VAR_7;

	    VAR_5 = VAR_6 + 1;

	    VAR_7 = strtoul(VAR_5, &VAR_6, 16);

	    if (VAR_6 == VAR_5)

		return -1;

	}

    }



    VAR_10 = VAR_7;



    if (VAR_4 != NULL) {

        if (*VAR_6 != '.')

            return -1;



        VAR_5 = VAR_6 + 1;

        VAR_7 = strtoul(VAR_5, &VAR_6, 16);

        if (VAR_6 == VAR_5)

            return -1;



        VAR_11 = VAR_7;

    }



    

    if (VAR_8 > 0xffff || VAR_9 > 0xff || VAR_10 > 0x1f || VAR_11 > 7)

	return -1;



    if (*VAR_6)

	return -1;



    

    if (!pci_find_bus(pci_find_root_bus(VAR_8), VAR_9))

	return -1;



    *VAR_1 = VAR_8;

    *VAR_2 = VAR_9;

    *VAR_3 = VAR_10;

    if (VAR_4 != NULL)

        *VAR_4 = VAR_11;

    return 0;

}

int FUNC_0(const char *VAR_0, int *VAR_1, int *VAR_2,
unsigned int *VAR_3, unsigned int *VAR_4)
{ const char *VAR_5; char *VAR_6; unsigned long VAR_7; unsigned long VAR_8 = 0, VAR_9 = 0; unsigned int VAR_10 = 0; unsigned int VAR_11 = 0; VAR_5 = VAR_0; VAR_7 = strtoul(VAR_5, &VAR_6, 16); if (VAR_6 == VAR_5)
return -1; if (*VAR_6 == ':') { VAR_9 = VAR_7; VAR_5 = VAR_6 + 1; VAR_7 = strtoul(VAR_5, &VAR_6, 16); if (VAR_6 == VAR_5)
return -1; if (*VAR_6 == ':') { VAR_8 = VAR_9; VAR_9 = VAR_7; VAR_5 = VAR_6 + 1; VAR_7 = strtoul(VAR_5, &VAR_6, 16); if (VAR_6 == VAR_5)
return -1; } } VAR_10 = VAR_7; if (VAR_4 != NULL) { if (*VAR_6 != '.')
return -1; VAR_5 = VAR_6 + 1; VAR_7 = strtoul(VAR_5, &VAR_6, 16); if (VAR_6 == VAR_5)
return -1; VAR_11 = VAR_7; } if (VAR_8 > 0xffff || VAR_9 > 0xff || VAR_10 > 0x1f || VAR_11 > 7)
return -1; if (*VAR_6)
return -1; if (!pci_find_bus(pci_find_root_bus(VAR_8), VAR_9))
return -1; *VAR_1 = VAR_8; *VAR_2 = VAR_9; *VAR_3 = VAR_10; if (VAR_4 != NULL)
*VAR_4 = VAR_11; return 0; }