That's always been an interesting question. I am of the opinion that the soul doesn't leave the body immediately after breathing or even the heart stops, and modern science's criterion of brain death is absurd. I tend to lean toward rigor mortis beginning to set in as the sign that the soul, which animates the body, has departed. I believe that it's permitted to administer Last Rites up until that point.
I question it even then. To what extent is the soul dependent upon the state of the body to maintain its presence there? (And not all cells die at once.)
It's an extreme point of view, but N.M. Gwynne (of grammar and Latin fame), in his Britons Catholic Library catalog, called into doubt the departure of the soul until putrefaction has begun, about three days after death.
Don't know to what extent embalming would hasten the soul's departure. My father died on a Thursday and I did not sign the embalming papers until Monday, without being too graphic, he was kept in the facilities that funeral homes provide during that interim period.