  Contour integrals of rational functions over ${\cal M}_{0,n}$, the moduli
space of $n$-punctured spheres, have recently appeared at the core of the
tree-level S-matrix of massless particles in arbitrary dimensions. The contour
is determined by the critical points of a certain Morse function on ${\cal
M}_{0,n}$. The integrand is a general rational function of the puncture
locations with poles of arbitrary order as two punctures coincide. In this note
we provide an algorithm for the analytic computation of any such integral. The
algorithm uses three ingredients: an operation we call general KLT, Petersen's
theorem applied to the existence of a 2-factor in any 4-regular graph and
Hamiltonian decompositions of certain 4-regular graphs. The procedure is
iterative and reduces the computation of a general integral to that of simple
building blocks. These are integrals which compute double-color-ordered partial
amplitudes in a bi-adjoint cubic scalar theory.
