Generalized Nahm equations and classical Yang-Baxter equations