Consolidate the regions covered by the process lock. Combine similar conditions tests into one, e.g. all process flags can be test with one logical operation.
Remove labels and goto by explicitly tracking state.
NB. While looking at the split of the conditions in swapout_procs() and swapout(), I think that the procedure is racy. For instance, a thread which was checked for sleep time in swapout_procs(), might become runnable (because the thread lock was dropped) and then removed from the runqueue again, when we reach the thread in swapout(). Then, we would still consider the process eligible, which is not.