int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),

             void *translate_opaque, 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(filename, fd, translate_fn, translate_opaque, must_swab,

                         pentry, lowaddr, highaddr, elf_machine, clear_lsb);

    } else {

        ret = load_elf32(filename, fd, translate_fn, translate_opaque, must_swab,

                         pentry, lowaddr, highaddr, elf_machine, clear_lsb);

    }



    close(fd);

    return ret;



 fail:

    close(fd);

    return -1;

}

int load_elf(const char *filename, uint64_t (*translate_fn)(void *, uint64_t),

             void *translate_opaque, 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(filename, fd, translate_fn, translate_opaque, must_swab,

                         pentry, lowaddr, highaddr, elf_machine, clear_lsb);

    } else {

        ret = load_elf32(filename, fd, translate_fn, translate_opaque, must_swab,

                         pentry, lowaddr, highaddr, elf_machine, clear_lsb);

    }



    close(fd);

    return ret;



 fail:

    close(fd);

    return -1;

}

    if (target_data_order != e_ident[EI_DATA])         return -1;
int FUNC_0(const char *VAR_0, VAR_1 (*translate_fn)(void *, VAR_1),

             void *VAR_2, VAR_1 *VAR_3, VAR_1 *VAR_4,

             VAR_1 *VAR_5, int VAR_6, int VAR_7, int VAR_8)

{

    int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13;

    uint8_t e_ident[EI_NIDENT];



    VAR_9 = open(VAR_0, O_RDONLY | O_BINARY);

    if (VAR_9 < 0) {

        perror(VAR_0);

        return -1;

    }

    if (read(VAR_9, 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_10 = ELFDATA2MSB;

#else

    VAR_10 = ELFDATA2LSB;

#endif

    VAR_12 = VAR_10 != e_ident[EI_DATA];

    if (VAR_6) {

        VAR_11 = ELFDATA2MSB;

    } else {

        VAR_11 = ELFDATA2LSB;

    }



    if (VAR_11 != e_ident[EI_DATA])

        return -1;



    lseek(VAR_9, 0, SEEK_SET);

    if (e_ident[EI_CLASS] == ELFCLASS64) {

        VAR_13 = load_elf64(VAR_0, VAR_9, translate_fn, VAR_2, VAR_12,

                         VAR_3, VAR_4, VAR_5, VAR_7, VAR_8);

    } else {

        VAR_13 = load_elf32(VAR_0, VAR_9, translate_fn, VAR_2, VAR_12,

                         VAR_3, VAR_4, VAR_5, VAR_7, VAR_8);

    }



    close(VAR_9);

    return VAR_13;



 fail:

    close(VAR_9);

    return -1;

}

int FUNC_0(const char *VAR_0, VAR_1 (*translate_fn)(void *, VAR_1),
void *VAR_2, VAR_1 *VAR_3, VAR_1 *VAR_4,
VAR_1 *VAR_5, int VAR_6, int VAR_7, int VAR_8)
{ int VAR_9, VAR_10, VAR_11, VAR_12, VAR_13; uint8_t e_ident[EI_NIDENT]; VAR_9 = open(VAR_0, O_RDONLY | O_BINARY); if (VAR_9 < 0) { perror(VAR_0); return -1; } if (read(VAR_9, 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_10 = ELFDATA2MSB; #else
VAR_10 = ELFDATA2LSB; #endif
VAR_12 = VAR_10 != e_ident[EI_DATA]; if (VAR_6) { VAR_11 = ELFDATA2MSB; } else { VAR_11 = ELFDATA2LSB; } if (VAR_11 != e_ident[EI_DATA])
return -1; lseek(VAR_9, 0, SEEK_SET); if (e_ident[EI_CLASS] == ELFCLASS64) { VAR_13 = load_elf64(VAR_0, VAR_9, translate_fn, VAR_2, VAR_12,
VAR_3, VAR_4, VAR_5, VAR_7, VAR_8); } else { VAR_13 = load_elf32(VAR_0, VAR_9, translate_fn, VAR_2, VAR_12,
VAR_3, VAR_4, VAR_5, VAR_7, VAR_8); } close(VAR_9); return VAR_13; fail:
close(VAR_9); return -1; }