  We present MORDOR (MORphological DecOmposeR, a new algorithm for structural
decomposition of simulated galaxies based on stellar kinematics. The code
measures the properties of up to five structural components (a thin/cold and a
thick/warm disc, a classical and a secular bulge, and a spherical stellar
halo), and determines the properties of a stellar bar (if present). A
comparison with other algorithms presented in the literature yields overall
good agreement, with MORDOR displaying a higher flexibility in correctly
decomposing systems and identifying bars in crowded environments (e.g. with
ongoing fly-bys, often observable in cosmological simulations). We use MORDOR
to analyse galaxies in the TNG50 simulation and find the following: ($i$) the
thick disc component undergoes the strongest evolution in the binding
energy-circularity plane, as expected when disc galaxies decrease their
turbulent-rotational support with cosmic time; ($ii$) smaller galaxies (with
stellar mass, $10^{9} \lesssim M_{*} / {\rm M_{\odot}} \leq 5 \times 10^{9}$)
undergo a major growth in their disc components after $z\sim 1$, whereas
($iii$) the most massive galaxies ($5 \times 10^{10} < M_{*} / {\rm M_{\odot}}
\leq 5\times10^{11}$) evolve toward more spheroidal dominated objects down to
$z=0$ due to frequent gravitational interactions with satellites; ($iv$) the
fraction of barred galaxies grows rapidly at high redshift and stabilizes below
$z\sim 2$, except for the most massive galaxies that show a decrease in the bar
occupation fraction at low redshift; ($v$) galaxies with $M_{*} \sim
10^{11}~{\rm M_{\odot}}$ exhibit the highest relative occurrence of bars at
$z=0$, in agreement with observational studies. We publicly release MORDOR and
the morphological catalogue of TNG50 galaxies.
