# Composition of almost everywhere continuous functions $\mathbb{R}\rightarrow\mathbb{R}$

If $f,g:\mathbb{R}\rightarrow\mathbb{R}$ are continuous it is well known that the composition $f\circ g$ is also continuous.

But what happens if we assume that $f,g$ are only almost everywhere continuous? Is the composition also almost everywhere continuous?

The question Composition of almost everywhere differentiable functions makes me believe the answer is negative, but I am unable to provide a counterexample for the case $f,g:\mathbb{R}\rightarrow \mathbb{R}$.

Example: take $g$ the Thomae function, $f$ the function $x \mapsto x^{-1}$ extended on $0$ by $f(0)=0$.
We can actually take $g$ to be a homeomorphism of $\mathbb {R}$ onto $\mathbb {R}.$ Let $K$ be a compact subset of $\mathbb {R},$ with $m(K) >0,$ having no interior (a "fat Cantor set"). Define
$$g(x) = \int_0^x d(t,K)\,dt,$$
where $d(t,K)$ is the distance from $t$ to $K.$ As is well known, $d(t,K)$ is continuous, hence $g$ is $C^1.$ Now $d(t,K)> 0$ for $t\in \mathbb {R}\setminus K,$ which is dense in $\mathbb {R}.$ It follows that $g$ is strictly increasing. We have $g\to \infty$ at $\infty,$ and $g\to -\infty$ at $-\infty.$ Thus $g$ is a $C^1$ homeomorphism of $\mathbb {R}$ onto $\mathbb {R}.$
Now $g'(x) = 0$ for all $x\in K.$ By a well known result, $m(g(K))=0.$ Define $f= \chi_{g(K)}.$ Then $f$ is continuous a.e. Let $x \in K.$ Then there is a sequence $x_n$ in $\mathbb {R}\setminus K$ such that $x_n\to x.$ Then $g(x_n) \not \in g(K)$ for all $n,$ so $f\circ g (x_n) = 0$ for all $n.$ But $f\circ g (x) = 1.$ Thus $f\circ g$ is discontinuous at each point of $K.$