Optimization-based Approaches to Safety-Critical Control with Applications to Space Systems