XIA/U4ID: refine main_input_output()

main_input_output() was the largest function in U4ID principal,
and it was hard to follow.
This patch brakes main_input_output() into smaller functions, and
rearranges its code to improve readability further.

Thanks to this cleanup, a bug with UDP checksum was uncorvered,
and fixed.