Fix the price of inputs, so the cost function (it does not matter if it is the SR or LR) can be written as a function of the quantity only, $C(Q)$. We define:
If $MC(Q) \lt ATC(Q)$ then $ATC \searrow$
If $MC(Q) \gt ATC(Q)$ then $ATC \nearrow$
If $MC(Q) = ATC(Q)$ then $ATC$ 's slope is zero.
In words, if the marginal cost is below the average total cost, then the average total cost must be decreasing; if the marginal cost is above the average total cost, then the average total cost must be increasing; when the marginal cost is equal the average total cost, then the average total cost slope is zero.
This last property implies that if the MC is U-shaped and the ATC crosses it, then it crosses the ATC at its minimum.
Everything here remains true if you use AVC instead of ATC. Please, refer to the textbook or the Mathematica file for pictures.
We assume that firms:
$\pi(q) = p \cdot q - c(q)$
Notice that we assume constant input prices, so we write the cost function as a function of the quantity only.
To maximize profit we need that:
$\pi'(q) = \underbrace{p}_{MR} - \underbrace{c'(q)}_{MC(q)} = 0 \Rightarrow MC(q) = p$
We also need the marginal cost to be increasing, so:
$q^S = MC^{-1}(p)$ provided that $MC'(q) \gt 0$
is the supply decision of a firm with cost function $c(q)$.
In the previous short-run analysis, the firm might choose to produce a quantity and incur negative profits but in the long run, such firm will exit the industry.
In order for a firm to leave the industry must be that the market price $p$ is such that:
$\pi(q) = p \cdot q - c(q) \lt 0$ for all $q \gt 0$, or
$\pi(q) = \left(p - \underbrace{c(q)/q}_{ATC(q)}\right) \cdot q \lt 0$ for all $q$, or
$\min_q ATC(q) \gt p$