Evolution of Fungal Endophytes and Their Functional Transitions Between Endophytism and Saprotrophism