Let $f$ be a function that is recursive but not primitive recursive, and let $\mathcal M$ be a Turing machine which computes $f$. I am trying to prove that the function
$$ g(x) = \sup\{\mathcal M(y)|y\le x\} $$
is not primitive recursive. I know that a function is primitive recursive if and only if its graph is PR and is bounded by a PR function. Also I know that if a function is increasing then it is PR if and only if its image is PR.
I've mostly tried proof by contradiction: Assume $g$ is PR and show that $f$ is PR. It seems like $im(f)=im(g)$, and clearly $g$ is increasing. So therefore $im(f)=im(g)$ is PR. But we cannot yet conclude that $f$ is PR. Certainly also $f\le g$ and we are assuming that $g$ is PR, so we only need to show that the graph of $f$ is PR. But I don't see a way to prove that.