The Stack Overflow stuff was a massive, massive pain, for several reasons.
For one, it's not clear how CC-BY-SA applies to code[1]. This involved many long meetings with copyright lawyers. They ended up asking for all this to be removed, which our C-level people eventuality agreed to.
We had to then go through several hundred "flagged" things (in a hundreds of thousands of lines codebase) and fix or justify everything.
Only a few cases were outright copy+paste of a big function or class, and those were at least straightforward: rewrite. Usually it was old code anyway, and replaced with newer style, much more concise code.
Tons were one- or two-line things, which involved lots of arguments along the lines of "that is the way to open a file in append mode in this language, and logFile is the appropriate variable name in this case!" This is really a failing of the tool they were using, but it still required answering.
The funniest was a handful that were our answers: they were copy+paste our team had done from our code to SO! (Nothing proprietary, just a few lines of an algorithm or solving whatever random problem).
Anyway, this experience left me extremely cautious about introducing any external code (as opposed to libraries) into a codebase. OSS libraries with permissive licenses (MIT, BSD, etc) are easy to deal with: it's straightforward to comply and being a library means the code is nicely compartmentalized if you need to replace/remove it.