int load_elf(const char *filename, int64_t address_offset,

             uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr,

             int big_endian, int elf_machine, int clear_lsb)

{

    int fd, data_order, target_data_order, must_swab, ret;

    uint8_t e_ident[EI_NIDENT];



    fd = open(filename, O_RDONLY | O_BINARY);

    if (fd < 0) {

        perror(filename);

        return -1;

    }

    if (read(fd, e_ident, sizeof(e_ident)) != sizeof(e_ident))

        goto fail;

    if (e_ident[0] != ELFMAG0 ||

        e_ident[1] != ELFMAG1 ||

        e_ident[2] != ELFMAG2 ||

        e_ident[3] != ELFMAG3)

        goto fail;

#ifdef HOST_WORDS_BIGENDIAN

    data_order = ELFDATA2MSB;

#else

    data_order = ELFDATA2LSB;

#endif

    must_swab = data_order != e_ident[EI_DATA];

    if (big_endian) {

        target_data_order = ELFDATA2MSB;

    } else {

        target_data_order = ELFDATA2LSB;

    }



    if (target_data_order != e_ident[EI_DATA])

        return -1;



    lseek(fd, 0, SEEK_SET);

    if (e_ident[EI_CLASS] == ELFCLASS64) {

        ret = load_elf64(fd, address_offset, must_swab, pentry,

                         lowaddr, highaddr, elf_machine, clear_lsb);

    } else {

        ret = load_elf32(fd, address_offset, must_swab, pentry,

                         lowaddr, highaddr, elf_machine, clear_lsb);

    }



    close(fd);

    return ret;



 fail:

    close(fd);

    return -1;

}

int load_elf(const char *filename, int64_t address_offset,

             uint64_t *pentry, uint64_t *lowaddr, uint64_t *highaddr,

             int big_endian, int elf_machine, int clear_lsb)

{

    int fd, data_order, target_data_order, must_swab, ret;

    uint8_t e_ident[EI_NIDENT];



    fd = open(filename, O_RDONLY | O_BINARY);

    if (fd < 0) {

        perror(filename);

        return -1;

    }

    if (read(fd, e_ident, sizeof(e_ident)) != sizeof(e_ident))

        goto fail;

    if (e_ident[0] != ELFMAG0 ||

        e_ident[1] != ELFMAG1 ||

        e_ident[2] != ELFMAG2 ||

        e_ident[3] != ELFMAG3)

        goto fail;

#ifdef HOST_WORDS_BIGENDIAN

    data_order = ELFDATA2MSB;

#else

    data_order = ELFDATA2LSB;

#endif

    must_swab = data_order != e_ident[EI_DATA];

    if (big_endian) {

        target_data_order = ELFDATA2MSB;

    } else {

        target_data_order = ELFDATA2LSB;

    }



    if (target_data_order != e_ident[EI_DATA])

        return -1;



    lseek(fd, 0, SEEK_SET);

    if (e_ident[EI_CLASS] == ELFCLASS64) {

        ret = load_elf64(fd, address_offset, must_swab, pentry,

                         lowaddr, highaddr, elf_machine, clear_lsb);

    } else {

        ret = load_elf32(fd, address_offset, must_swab, pentry,

                         lowaddr, highaddr, elf_machine, clear_lsb);

    }



    close(fd);

    return ret;



 fail:

    close(fd);

    return -1;

}

int FUNC_0(const char *VAR_0, int64_t VAR_1,

             uint64_t *VAR_2, uint64_t *VAR_3, uint64_t *VAR_4,

             int VAR_5, int VAR_6, int VAR_7)

{

    int VAR_8, VAR_9, VAR_10, VAR_11, VAR_12;

    uint8_t e_ident[EI_NIDENT];



    VAR_8 = open(VAR_0, O_RDONLY | O_BINARY);

    if (VAR_8 < 0) {

        perror(VAR_0);

        return -1;

    }

    if (read(VAR_8, e_ident, sizeof(e_ident)) != sizeof(e_ident))

        goto fail;

    if (e_ident[0] != ELFMAG0 ||

        e_ident[1] != ELFMAG1 ||

        e_ident[2] != ELFMAG2 ||

        e_ident[3] != ELFMAG3)

        goto fail;

#ifdef HOST_WORDS_BIGENDIAN

    VAR_9 = ELFDATA2MSB;

#else

    VAR_9 = ELFDATA2LSB;

#endif

    VAR_11 = VAR_9 != e_ident[EI_DATA];

    if (VAR_5) {

        VAR_10 = ELFDATA2MSB;

    } else {

        VAR_10 = ELFDATA2LSB;

    }



    if (VAR_10 != e_ident[EI_DATA])

        return -1;



    lseek(VAR_8, 0, SEEK_SET);

    if (e_ident[EI_CLASS] == ELFCLASS64) {

        VAR_12 = load_elf64(VAR_8, VAR_1, VAR_11, VAR_2,

                         VAR_3, VAR_4, VAR_6, VAR_7);

    } else {

        VAR_12 = load_elf32(VAR_8, VAR_1, VAR_11, VAR_2,

                         VAR_3, VAR_4, VAR_6, VAR_7);

    }



    close(VAR_8);

    return VAR_12;



 fail:

    close(VAR_8);

    return -1;

}

int FUNC_0(const char *VAR_0, int64_t VAR_1,
uint64_t *VAR_2, uint64_t *VAR_3, uint64_t *VAR_4,
int VAR_5, int VAR_6, int VAR_7)
{ int VAR_8, VAR_9, VAR_10, VAR_11, VAR_12; uint8_t e_ident[EI_NIDENT]; VAR_8 = open(VAR_0, O_RDONLY | O_BINARY); if (VAR_8 < 0) { perror(VAR_0); return -1; } if (read(VAR_8, e_ident, sizeof(e_ident)) != sizeof(e_ident))
goto fail; if (e_ident[0] != ELFMAG0 ||
e_ident[1] != ELFMAG1 ||
e_ident[2] != ELFMAG2 ||
e_ident[3] != ELFMAG3)
goto fail; #ifdef HOST_WORDS_BIGENDIAN
VAR_9 = ELFDATA2MSB; #else
VAR_9 = ELFDATA2LSB; #endif
VAR_11 = VAR_9 != e_ident[EI_DATA]; if (VAR_5) { VAR_10 = ELFDATA2MSB; } else { VAR_10 = ELFDATA2LSB; } if (VAR_10 != e_ident[EI_DATA])
return -1; lseek(VAR_8, 0, SEEK_SET); if (e_ident[EI_CLASS] == ELFCLASS64) { VAR_12 = load_elf64(VAR_8, VAR_1, VAR_11, VAR_2,
VAR_3, VAR_4, VAR_6, VAR_7); } else { VAR_12 = load_elf32(VAR_8, VAR_1, VAR_11, VAR_2,
VAR_3, VAR_4, VAR_6, VAR_7); } close(VAR_8); return VAR_12; fail:
close(VAR_8); return -1; }