We say that a function $f:\mathbb{R}\to\mathbb{R}$ has the intermediate value property (ivp) if for $a<b$ in $\mathbb{R}$ we have $$f([a,b]) \supseteq [\min\{f(a),f(b)\}, \max\{f(a), f(b)\}].$$ The intermediate value theorem states that continous functions have the ivp. Is there a noncontinuous function $f:\mathbb{R}\to\mathbb{R}$ with the ivp and the property that $f^{1}(\{c\})$ is closed for all $c\in\mathbb{R}$?

1$\begingroup$ Related: math.stackexchange.com/questions/1121654/… and math.stackexchange.com/questions/622076/… The accepted answer to the second in fact provides some sufficient conditions that answer your question. $\endgroup$ – Willie Wong Aug 10 '16 at 8:52

$\begingroup$ Functions satisfying the Intermediate Value Theorem are sometimes called Darboux functions. $\endgroup$ – Goldstern Sep 5 '16 at 10:47
What kind of conditions do you prefer?
Say, local bounded variation is enough: if $f$ is discontinuous at a point $a$, there exist two numbers $A<B$ such that $f$ takes the values less than $A$ and more than $B$ in any (punctured) neighborhood of $a$. Clearly variation of $f$ in any such neighborhood is infinite.
Of course if the preimage of any point $f^{1}(c)$ is closed, we also may conclude that $f$ is continuous: take $c$ between $A$ and $B$ but $c\ne f(a)$, then $f^{1}(c)$ does not contain $a$, but contains points arbitrarily close to $a$, hence $f^{1}(c)$ is not closed.

$\begingroup$ Sorry, my question was badly phrased, edited it.. $\endgroup$ – Dominic van der Zypen Aug 10 '16 at 9:04