The existence of "hooks" further complicates things. WordPress themes are essentially collections of event handler scripts, and those scripts can register callbacks such that when core WordPress functions are called, those callbacks are executed. So, you have WordPress calling the theme calling WordPress calling the theme...