Analytic energy second derivatives for general correlated wavefunctions, including a solution of the first-order coupled-perturbed configuration-interaction equations