int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size)

{

    target_phys_addr_t end = addr + size;

    uint8_t *s, *d = dest;

    size_t l = 0;

    Rom *rom;



    QTAILQ_FOREACH(rom, &roms, next) {

        if (rom->fw_file) {

            continue;

        }

        if (rom->addr + rom->romsize < addr)

            continue;

        if (rom->addr > end)

            break;

        if (!rom->data)

            continue;



        d = dest + (rom->addr - addr);

        s = rom->data;

        l = rom->romsize;



        if (rom->addr < addr) {

            d = dest;

            s += (addr - rom->addr);

            l -= (addr - rom->addr);

        }

        if ((d + l) > (dest + size)) {

            l = dest - d;

        }



        memcpy(d, s, l);

    }



    return (d + l) - dest;

}

int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size)

{

    target_phys_addr_t end = addr + size;

    uint8_t *s, *d = dest;

    size_t l = 0;

    Rom *rom;



    QTAILQ_FOREACH(rom, &roms, next) {

        if (rom->fw_file) {

            continue;

        }

        if (rom->addr + rom->romsize < addr)

            continue;

        if (rom->addr > end)

            break;

        if (!rom->data)

            continue;



        d = dest + (rom->addr - addr);

        s = rom->data;

        l = rom->romsize;



        if (rom->addr < addr) {

            d = dest;

            s += (addr - rom->addr);

            l -= (addr - rom->addr);

        }

        if ((d + l) > (dest + size)) {

            l = dest - d;

        }



        memcpy(d, s, l);

    }



    return (d + l) - dest;

}

int FUNC_0(uint8_t *VAR_0, target_phys_addr_t VAR_1, size_t VAR_2)

{

    target_phys_addr_t end = VAR_1 + VAR_2;

    uint8_t *s, *d = VAR_0;

    size_t l = 0;

    Rom *rom;



    QTAILQ_FOREACH(rom, &roms, next) {

        if (rom->fw_file) {

            continue;

        }

        if (rom->VAR_1 + rom->romsize < VAR_1)

            continue;

        if (rom->VAR_1 > end)

            break;

        if (!rom->data)

            continue;



        d = VAR_0 + (rom->VAR_1 - VAR_1);

        s = rom->data;

        l = rom->romsize;



        if (rom->VAR_1 < VAR_1) {

            d = VAR_0;

            s += (VAR_1 - rom->VAR_1);

            l -= (VAR_1 - rom->VAR_1);

        }

        if ((d + l) > (VAR_0 + VAR_2)) {

            l = VAR_0 - d;

        }



        memcpy(d, s, l);

    }



    return (d + l) - VAR_0;

}

int FUNC_0(uint8_t *VAR_0, target_phys_addr_t VAR_1, size_t VAR_2)
{ target_phys_addr_t end = VAR_1 + VAR_2; uint8_t *s, *d = VAR_0; size_t l = 0; Rom *rom; QTAILQ_FOREACH(rom, &roms, next) { if (rom->fw_file) { continue; } if (rom->VAR_1 + rom->romsize < VAR_1)
continue; if (rom->VAR_1 > end)
break; if (!rom->data)
continue; d = VAR_0 + (rom->VAR_1 - VAR_1); s = rom->data; l = rom->romsize; if (rom->VAR_1 < VAR_1) { d = VAR_0; s += (VAR_1 - rom->VAR_1); l -= (VAR_1 - rom->VAR_1); } if ((d + l) > (VAR_0 + VAR_2)) { l = VAR_0 - d; } memcpy(d, s, l); } return (d + l) - VAR_0; }