Factor out looking for prologue end into a function