  We give sufficient and necessary geometric conditions, guaranteeing that an
immersed compact closed manifold $\Sigma^m\subset \R^n$ of class $C^1$ and of
arbitrary dimension and codimension (or, more generally, an Ahlfors-regular
compact set $\Sigma$ satisfying a mild general condition relating the size of
holes in $\Sigma$ to the flatness of $\Sigma$ measured in terms of beta
numbers) is in fact an embedded manifold of class $C^{1,\tau}\cap W^{2,p}$,
where $p>m$ and $\tau=1-m/p$. The results are based on a careful analysis of
Morrey estimates for integral curvature--like energies, with integrands
expressed geometrically, in terms of functions that are designed to measure
either (a) the shape of simplices with vertices on $\Sigma$ or (b) the size of
spheres tangent to $\Sigma$ at one point and passing through another point of
$\Sigma$.
  Appropriately defined \emph{maximal functions} of such integrands turn out to
be of class $L^p(\Sigma)$ for $p>m$ if and only if the local graph
representations of $\Sigma$ have second order derivatives in $L^p$ and $\Sigma$
is embedded. There are two ingredients behind this result. One of them is an
equivalent definition of Sobolev spaces, widely used nowadays in analysis on
metric spaces. The second one is a careful analysis of local Reifenberg
flatness (and of the decay of functions measuring that flatness) for sets with
finite curvature energies. In addition, for the geometric curvature energy
involving tangent spheres we provide a nontrivial lower bound that is attained
if and only if the admissible set $\Sigma$ is a round sphere.
