Counting integer points in polyhedra and applications to program optimization