Improve detection of code that returns from function.

Test case missing because it needs quite complex setup and it is easier to
test it on real code.