  We study totally disconnected locally compact second countable (t.d.l.c.s.c.)
groups that contain a compact open subgroup with finite rank. We show such
groups that additionally admit a pro-$\pi$ compact open subgroup for some
finite set of primes $\pi$ are virtually an extension of a finite direct
product of topologically simple groups by an elementary group. This result, in
particular, applies to l.c.s.c. $p$-adic Lie groups. We go on to prove a
decomposition result for all t.d.l.c.s.c. groups containing a compact open
subgroup with finite rank. In the course of proving these theorems, we
demonstrate independently interesting structure results for t.d.l.c.s.c. groups
with a compact open pro-nilpotent subgroup and for topologically simple
l.c.s.c. $p$-adic Lie groups.
