The formal question:
Given $f(x)$, a continuous-but-not-necessarily-differentiable-everywhere function.
Define $g(x)$ as:
$$g(x) = \begin{cases} 0 & \text{if } x \leq 0 \\ \int_0^x \max(f(x) - f(t), 0) \, \mathrm{d}t & \text{if } x > 0 \end{cases}$$
Is $g(x)$ continuous and differentiable everywhere?
Context: I have a path in 2D space built out of connected line segments, and a robot with some position (not necessarily on the path). I need to assign a "marker" on the path to the robot's current position to know which direction it wants to go next.
I have a measure of how close the robot is to the marker (squared Euclidean distance) and for some window on the path. This is $f(x)$; it's continuous but not differentiable because the path makes hard turns wherever we move from one segment to the next.
I want to use that to measure how "good" the marker is. That is, I want to introduce a penalty into the solver for making a bad choice of marker when there was an earlier choice which would have been better (I don't need to care about better later choices).
A choice of marker is bad if there is a closer point on the path it could have selected, so I'd like to use $g(x)$ as my penalty for selecting a bad marker (note that when $f(x)$ is the minimum value of $f$ over $[0,x]$, it's $0$). Since the solver uses gradient descent, I can only work with differentiable functions.
Example:
Take $f(x) = |x-1|$.
Then
$$g(x) = \begin{cases} 0 & \text{if } x < 1 \\ (x-1)^2 & \text{if } 1 \leq x < 2 \\ (x-1)^2 - \frac{(x-2)^2}{2} & \text{if } x \geq 2 \end{cases}$$
Which is indeed continuous and differentiable everywhere. In general it intuitively seems like this should always be true, but it doesn't follow directly from FTOC because of that $f(x)$ inside the integrand.