int load_aout(const char *filename, target_phys_addr_t addr, int max_sz,

              int bswap_needed, target_phys_addr_t target_page_size)

{

    int fd, size, ret;

    struct exec e;

    uint32_t magic;



    fd = open(filename, O_RDONLY | O_BINARY);

    if (fd < 0)

        return -1;



    size = read(fd, &e, sizeof(e));

    if (size < 0)

        goto fail;



    if (bswap_needed) {

        bswap_ahdr(&e);

    }



    magic = N_MAGIC(e);

    switch (magic) {

    case ZMAGIC:

    case QMAGIC:

    case OMAGIC:

        if (e.a_text + e.a_data > max_sz)

            goto fail;

	lseek(fd, N_TXTOFF(e), SEEK_SET);

	size = read_targphys(filename, fd, addr, e.a_text + e.a_data);

	if (size < 0)

	    goto fail;

	break;

    case NMAGIC:

        if (N_DATADDR(e, target_page_size) + e.a_data > max_sz)

            goto fail;

	lseek(fd, N_TXTOFF(e), SEEK_SET);

	size = read_targphys(filename, fd, addr, e.a_text);

	if (size < 0)

	    goto fail;

        ret = read_targphys(filename, fd, addr + N_DATADDR(e, target_page_size),

                            e.a_data);

	if (ret < 0)

	    goto fail;

	size += ret;

	break;

    default:

	goto fail;

    }

    close(fd);

    return size;

 fail:

    close(fd);

    return -1;

}

int load_aout(const char *filename, target_phys_addr_t addr, int max_sz,

              int bswap_needed, target_phys_addr_t target_page_size)

{

    int fd, size, ret;

    struct exec e;

    uint32_t magic;



    fd = open(filename, O_RDONLY | O_BINARY);

    if (fd < 0)

        return -1;



    size = read(fd, &e, sizeof(e));

    if (size < 0)

        goto fail;



    if (bswap_needed) {

        bswap_ahdr(&e);

    }



    magic = N_MAGIC(e);

    switch (magic) {

    case ZMAGIC:

    case QMAGIC:

    case OMAGIC:

        if (e.a_text + e.a_data > max_sz)

            goto fail;

	lseek(fd, N_TXTOFF(e), SEEK_SET);

	size = read_targphys(filename, fd, addr, e.a_text + e.a_data);

	if (size < 0)

	    goto fail;

	break;

    case NMAGIC:

        if (N_DATADDR(e, target_page_size) + e.a_data > max_sz)

            goto fail;

	lseek(fd, N_TXTOFF(e), SEEK_SET);

	size = read_targphys(filename, fd, addr, e.a_text);

	if (size < 0)

	    goto fail;

        ret = read_targphys(filename, fd, addr + N_DATADDR(e, target_page_size),

                            e.a_data);

	if (ret < 0)

	    goto fail;

	size += ret;

	break;

    default:

	goto fail;

    }

    close(fd);

    return size;

 fail:

    close(fd);

    return -1;

}

    int fd, size, ret;
int FUNC_0(const char *VAR_0, target_phys_addr_t VAR_1, int VAR_2,

              int VAR_3, target_phys_addr_t VAR_4)

{

    int VAR_5, VAR_6, VAR_7;

    struct exec VAR_8;

    uint32_t magic;



    VAR_5 = open(VAR_0, O_RDONLY | O_BINARY);

    if (VAR_5 < 0)

        return -1;



    VAR_6 = read(VAR_5, &VAR_8, sizeof(VAR_8));

    if (VAR_6 < 0)

        goto fail;



    if (VAR_3) {

        bswap_ahdr(&VAR_8);

    }



    magic = N_MAGIC(VAR_8);

    switch (magic) {

    case ZMAGIC:

    case QMAGIC:

    case OMAGIC:

        if (VAR_8.a_text + VAR_8.a_data > VAR_2)

            goto fail;

	lseek(VAR_5, N_TXTOFF(VAR_8), SEEK_SET);

	VAR_6 = read_targphys(VAR_0, VAR_5, VAR_1, VAR_8.a_text + VAR_8.a_data);

	if (VAR_6 < 0)

	    goto fail;

	break;

    case NMAGIC:

        if (N_DATADDR(VAR_8, VAR_4) + VAR_8.a_data > VAR_2)

            goto fail;

	lseek(VAR_5, N_TXTOFF(VAR_8), SEEK_SET);

	VAR_6 = read_targphys(VAR_0, VAR_5, VAR_1, VAR_8.a_text);

	if (VAR_6 < 0)

	    goto fail;

        VAR_7 = read_targphys(VAR_0, VAR_5, VAR_1 + N_DATADDR(VAR_8, VAR_4),

                            VAR_8.a_data);

	if (VAR_7 < 0)

	    goto fail;

	VAR_6 += VAR_7;

	break;

    default:

	goto fail;

    }

    close(VAR_5);

    return VAR_6;

 fail:

    close(VAR_5);

    return -1;

}

int FUNC_0(const char *VAR_0, target_phys_addr_t VAR_1, int VAR_2,
int VAR_3, target_phys_addr_t VAR_4)
{ int VAR_5, VAR_6, VAR_7; struct exec VAR_8; uint32_t magic; VAR_5 = open(VAR_0, O_RDONLY | O_BINARY); if (VAR_5 < 0)
return -1; VAR_6 = read(VAR_5, &VAR_8, sizeof(VAR_8)); if (VAR_6 < 0)
goto fail; if (VAR_3) { bswap_ahdr(&VAR_8); } magic = N_MAGIC(VAR_8); switch (magic) { case ZMAGIC:
case QMAGIC:
case OMAGIC:
if (VAR_8.a_text + VAR_8.a_data > VAR_2)
goto fail; lseek(VAR_5, N_TXTOFF(VAR_8), SEEK_SET); VAR_6 = read_targphys(VAR_0, VAR_5, VAR_1, VAR_8.a_text + VAR_8.a_data); if (VAR_6 < 0)
goto fail; break; case NMAGIC:
if (N_DATADDR(VAR_8, VAR_4) + VAR_8.a_data > VAR_2)
goto fail; lseek(VAR_5, N_TXTOFF(VAR_8), SEEK_SET); VAR_6 = read_targphys(VAR_0, VAR_5, VAR_1, VAR_8.a_text); if (VAR_6 < 0)
goto fail; VAR_7 = read_targphys(VAR_0, VAR_5, VAR_1 + N_DATADDR(VAR_8, VAR_4),
VAR_8.a_data); if (VAR_7 < 0)
goto fail; VAR_6 += VAR_7; break; default:
goto fail; } close(VAR_5); return VAR_6; fail:
close(VAR_5); return -1; }