  We show that the semidirect product of a group $C$ by $A*_D B$ is isomorphic
to the free product of $A\rtimes C$ and $B\rtimes C$ amalgamated at $D\rtimes
C$, where $A$, $B$ and $C$ are arbitrary groups. Moreover, we apply this
theorem to prove that any group $G$ that acts without inversion on a tree $T$
that possesses a segment $\Gamma$ for its quotient graph, such that, if the
stabilizers of the vertex set $\{\,P,Q\,\}$ and edge $y$ of a lift of $\,
\Gamma$ in $T$ are of the form $G_{P}\!\rtimes H$, $G_{Q}\!\rtimes H$ and
$G_{y}\! \rtimes H$, then $G$ is isomorphic to the semidirect product of $H$ by
$(\,G_P \,*_{G_y} \,G_Q \,)$.
  Using our results we conclude with a non-standard verification of the
isomorphism between $GL_2(\mathbb{Z})$ and the free product of the dihedral
groups $D_4$ and $D_6$ amalgamated at their Klein-four group.
