Prefix global options with opt_

This cleans up some -Wshadow warnings
add print_allocated_list for lists which need to be freed
remove superfluous access check
remove dead assignment of shortdeps
refactor pkg resolution in more manageable chunks