Edited.
Let $g_0^\prime(x)=|x-1/2|,\; g_0(x)=\int_0^xg_1(t)dt,\; 0\leq x\leq1$. Then $g_0$ has continuus derivative, namely $g_0^\prime$, which is Lipschitz, but the second derivative is discontinuous. Let $L=\{(x,y):y=g_0(x)\}$ be the graph of $g_0$.
Now define $f(x,y)=0$ when $0\leq x\leq 1, y=g_0(x)$ and $f(x,y)=1$ otherwise $$f(x,y)=(\mathrm{dist}(x,y),L)^{-3}+1$$ otherwise. Evidently $f$ is measurable, and $\int_0^1 f(x,g_0(x))dx=0$, while $\int_0^1f(x,g(x))dx>0$$\int_0^1f(x,g(x))dx>c$ for every $C^2$ function $g$, where $c$ is an absolute constant.
RemarkOf course, the last fact requires an accurate proof, but on the other hand, it seems evident. YouMoreover, one can makereplace $f$ continuous and even smooth by taking a non-negative smooth function with$3$ in the same zero set as I describedexponent by some larger constant, to make it more evident. EvenThe idea is that when the polynomialgraph of $f(x,y)=(x-y)^2(x+y-1)^2$ will do$g$ is too close to $L$, the jobintegral is large.