int load_elf(const char *filename, int64_t virt_to_phys_addend,

             uint64_t *pentry)

{

    int fd, 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 WORDS_BIGENDIAN

    data_order = ELFDATA2MSB;

#else

    data_order = ELFDATA2LSB;

#endif

    must_swab = data_order != e_ident[EI_DATA];

    

    lseek(fd, 0, SEEK_SET);

    if (e_ident[EI_CLASS] == ELFCLASS64) {

        ret = load_elf64(fd, virt_to_phys_addend, must_swab, pentry);

    } else {

        ret = load_elf32(fd, virt_to_phys_addend, must_swab, pentry);

    }



    close(fd);

    return ret;



 fail:

    close(fd);

    return -1;

}

int load_elf(const char *filename, int64_t virt_to_phys_addend,

             uint64_t *pentry)

{

    int fd, 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 WORDS_BIGENDIAN

    data_order = ELFDATA2MSB;

#else

    data_order = ELFDATA2LSB;

#endif

    must_swab = data_order != e_ident[EI_DATA];

    

    lseek(fd, 0, SEEK_SET);

    if (e_ident[EI_CLASS] == ELFCLASS64) {

        ret = load_elf64(fd, virt_to_phys_addend, must_swab, pentry);

    } else {

        ret = load_elf32(fd, virt_to_phys_addend, must_swab, pentry);

    }



    close(fd);

    return ret;



 fail:

    close(fd);

    return -1;

}

int FUNC_0(const char *VAR_0, int64_t VAR_1,

             uint64_t *VAR_2)

{

    int VAR_3, VAR_4, VAR_5, VAR_6;

    uint8_t e_ident[EI_NIDENT];



    VAR_3 = open(VAR_0, O_RDONLY | O_BINARY);

    if (VAR_3 < 0) {

        perror(VAR_0);

        return -1;

    }

    if (read(VAR_3, 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 WORDS_BIGENDIAN

    VAR_4 = ELFDATA2MSB;

#else

    VAR_4 = ELFDATA2LSB;

#endif

    VAR_5 = VAR_4 != e_ident[EI_DATA];

    

    lseek(VAR_3, 0, SEEK_SET);

    if (e_ident[EI_CLASS] == ELFCLASS64) {

        VAR_6 = load_elf64(VAR_3, VAR_1, VAR_5, VAR_2);

    } else {

        VAR_6 = load_elf32(VAR_3, VAR_1, VAR_5, VAR_2);

    }



    close(VAR_3);

    return VAR_6;



 fail:

    close(VAR_3);

    return -1;

}

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