A splitting theorem for manifolds