sh: Make checkend() a real function instead of an emulated nested function.

No functional change is intended, but the generated code is slightly
different.