Composition of functions question

Am restricting this question to the elementary context of Riemann integrals and continuous functions $f,g.$ Because this came up in the context of another question, I would prefer to keep the examples from that question, at the risk of artificiality.

Let $g:[0,4]\to \mathbb{R}$ such that

$$\int_0^1g(x)dx = \int_3^4 4-g(x)dx.~~~~~(1)$$

An example would be $g(x) = x(x-3)^2.$

It is I think not true in general that the above implies

$$\int_0^1 f(g(x))dx = \int_3^4 f(4- g(x))dx ~~~~~(2)$$

however the equality happens to hold with this $g(x).$

My attempt to justify the implication ran as follows. Using an arbitrarily fine Riemann sum approximation of the L.H.S. integral in (1) we get an arbitrarily close approximation to the integral. Using the same process for the R.H.S we (at least in this special case, which is part of my assumptions) have a rearrangement of summands, hence the same approximation.

Regarded as a sum of (say) rectangles on subintervals of $[0,1],$ it seems that we may apply $f$ to the approximation of $g$ in each subinterval and get a Riemann sum for the L.H.S. of (2). Since on the R.H.S. of (2) we are applying $f$ to the same summands (up to rearrangement) it would seem that as the subintervals shrink the equality in (2) should follow.

My question is, where is the flaw in this naive reasoning, if there is one? Are there additional assumptions that would make the implication true?

Solutions Collecting From Web of "Composition of functions question"

For this $g:\mathbb{R}\rightarrow\mathbb{R}, x\mapsto x(x-3)^2$ the implication seems to be true because of a benevolent symmetry: Lets consider the restrictions $g_1:=g|_{[0,1]}$ and $g_1:=g|_{[3,4]}$. plot of $g$

One can prove that $g_1$ and $g_2$ are invertible (bacause of monotonicity on the restricted intervals) and I think (considering the picture – try to prove this formally) that the relation
holds for all $y\in[0,4]$. (EDIT: It is easy to check, that $g(x)=4-g(4-x)$. From this I deduced the relation.) This is the symmetry, of which we will make use of. The rest is just integration by substitution (the details with the occurring improper integrals are left to the reader and I will ignore them neatly):
\int_3^4 f(4-\underbrace{g(x)}_{g_2(x)})dx
&= \int_{g_2(3)=0}^{g_2(4)=4} f(4-y)(g_2^{-1})'(y)dy \\
&= -\int_{0}^{4} f(4-y)(g_1^{-1})'(4-y)dy \\
&= \int_{0}^{4} f(y)(g_1^{-1})'(y)dy \\
&= \int_{g_1^{-1}(0)=0}^{g_1^{-1}(4)=1} f(g_1(x))g_1′(x)(g_1^{-1})'(g_1(x))dx \\
&\stackrel{\dagger}{=} \int_{0}^{1} f(g(x))dx.
The equality $\dagger$ holds because $g_1′(x)(g_1^{-1})'(g_1(x)) = g_1′(x)\frac{1}{g_1′(g_1^{-1}(g_1(x)))} = g_1′(x)\frac{1}{g_1′(x)} = 1.$

To construct one counter example of the implication (for arbitrary $g$) you have to try to find $g$, which violates the symmetry $(g_2^{-1})'(4-y)=-(g_1^{-1})'(y)$. I try to make it plausible without a explicit construction: Since the continuous functions are dense in $L^p$ spaces, its okay just to construct a discontinuous Riemann integrable function for $g$. Consider $g:=4\chi_{[0,\frac{1}{2}]}+2\chi_{[3,4]}$ for example. Then the condition for $g$ is fulfilled. Now take a continuous $f$ with $f(0)=f(4)=0$, $f(2)=1$, then you have
$$\int_0^1 f(g(x))dx = \int_0^1 0\ dx = 0$$
$$\int_3^4 f(g(x))dx = \int_3^4 1\ dx = 1.$$
With an approximation argument you will get a contradiction for the original statement with continuous $g$.