This all has to do with negation scope. This question also discusses this subject.
Your first sentence has a scope ambiguity. This paper says there are two readings: negated adjunct and negated head.
The part "not so I could drink coffee" is a negated adjunct.