I'm pretty sure I mathed it all out right.

So. U.S./Germany tie, they both go through, regardless of the other match.

Portugal/Ghana tie, U.S. and Germany go through and their match doesn't matter.

Portugal wins, Germany wins - Germany goes through. U.S. goes through as long as the combined goal differential between the matches is less than five. Portugal squeaks through if it's more than five. If it's 5 even, then it's based on which team scored more. Portugal needs to score at least three more than the U.S. does in its match for them to win that way. If they tie by that method, drawing of lots because of the U.S.-Portugal tie.

Portugal wins, U.S. wins - U.S. goes through. Germany goes through as long as the combined goal differential between the matches is less than eight. Portugal squeaks through if it's more than eight (lolnope, not going to happen). If it's eight even, then based on which team scored more. No point even running the numbers - Portugal's probably boned if that happens, especially if it winds up being a tie.

Ghana wins, Germany wins - Germany goes through. 1-0 in both games goes to most total goals, anything better puts Ghana through on goal differential. If it's most total goals, Ghana needs to score two better than the U.S. does in its match to get through (only one better means the U.S. goes through based on their game with Ghana).

Ghana wins, U.S. wins - U.S. goes through. Germany goes through as long as the combined goal differential between the matches is less than five. Ghana squeaks through if it's more than five. If it's five even , then based on which team scored more. Ghana needs to score four better than Germany does in its game in order to get through this way. If only three better, drawing of lots due to the Ghana-Germany tie.