Let $C$ be a local martingale started at $0$ an define $S_t=\sup_{0\le a \le t}C_a$. For any twice continuously differentiable $f$, how is the equality $(S_t-C_t)f(S_t)=\int_0 ^{S_t}f(t)dt-\int_0 ^tf(S_s)dC_s$ obtained?
The only tool I know to apply is Ito's lemma, $f(S_t)=f(0)+\int_0^tf'(S_s)B_s+\frac{1}{2}f''(S_s)ds$. I am unsure if this can be applied directly since the second derivative doesn't appear in the equation. Even if the second derivative vanishes in this case, how do I evaluate the integrals on the right hand side?
Two Facts: 1 Since $S_t$ is continuous and non-decreasing, then $$\int_0^tf(S_t)\,dS_t=\int_0^{S_t}f(s)\,ds. \tag{1}$$ (You may prove (1) by variable transform formula for LS-integrals or Ito's formula.).
2 If $F=\{t: S_t=C_t\}$, then $$\int_0^\infty 1_{F^c}(t)\,dS_t=0. \tag{2}$$ (For $t_0\in F^c$, there exists a $\delta>0$ such that, $ S_t=S_{t_0}>C_t, \;\forall t\in (t_0-\delta,t_0+\delta).$)
Now using Ito's formula we have \begin{align} (S_t-C_t)f(S_t)&=\Bigl[\int_0^tf(S_s)\,dS_s-\int_0^tf(S_s)\,dC_s\Bigr] +\int_0^tf'(S_s)(S_s-C_s)\,dS_s\\ \text{(Using (1) and (2))}\quad &=\int_0^{S_t}f(s)\,ds-\int_0^tf(S_s)\,dC_s+\int_0^tf'(S_s)(S_s-C_s)1_{\{S_s=C_s\}}(s)\,dS_s\\ &=\int_0^{S_t}f(s)\,ds-\int_0^tf(S_s)\,dC_s. \end{align}