Complexity of critical functions for Hamiltonian systems