Q:

How much of a codebase can be considered intellectual property?

If you write some code, generally you or your employer 'own' that code (I won't go into who 'owns' open source code because it's not what I'm talking about). It's yours/theirs to do with what you please. But at what point can you reasonably say "this code is mine"? It seems reasonable to say a 100,000+ LOC codebase written by in-house developers belongs to the company they work for. You could stretch further and say "this function is mine". It might be a very specialised function using an algorithm you created to perform some task, so really yes, that is yours because no one else created it, you did.
But what about boilerplate code and small snippets? What about "Hello World"? Millions of programmers have written a Hello World since the early 70's, but you couldn't say because you wrote one that you 'own' Hello World in your chosen language.
What factors distinguish code classed as something that can be owned from code "anyone could have written"? There's only a certain number of reasonable ways of achieving some programming task, and you surely can't claim ownership of any code that does the same thing just because you wrote one first (or can you?).
For example...
A friend of mine got a job for a trendy new startup (the kind where beanbags and having a wacky office environment took precedent over actually doing anything) that swiftly sank beneath the waves. He was given a project that could have been handled by one programmer and got through what he estimates as 10-15% of the actual programming before being let go. He also did all of the design phase and supposedly has documentation to prove it. I want (with him) to use what he already wrote to finish the project and launch it as our own, but he's worried his former employer may come after him and accuse him of stealing the company's (which is now defunct) property.
Ideally I'm looking for legal precedent if anyone knows of any, but I think it might be hard to come by if any exists at all.

A:

Yes and no. [note, the following is all written about US law. In other jurisdictions laws are, of course, different (though usually not drastically so.)]
In the US there are (at least) three different bodies of law that might apply to code: copyright, patents, trade secrets.
Copyright covers original expression. Anything you write is automatically, immediately protected under copyright. The copyright applies to the code itself, and anything "derived" from that code. It's up to the courts to decide exactly what "derived" means. One case that's long been viewed as a landmark in this area is Gates Rubber v. Bando Chemicals. The Court of Appeals for the tenth Circuit decision includes a section titled: "The Test for Determining Whether the Copyright of a Computer Program Has Been Infringed." Note that you can register a copyright, and that can be worthwhile, such as helping recover some damages you can't otherwise.
Patents are quite different from copyrights. Where a copyright covers expression of an idea, a patent covers a specific invention. Rather than being awarded automatically, a patent has to be applied for, and awarded only after the patent office has determined that there's no relevant prior art to prevent it from being awarded. A patent, however, covers things like somebody else independently discovering/inventing what's covered by the patent.
A trade secret could (at least theoretically) apply to some process or procedure embodied in the code. A trade secret mostly applies to a situation where (for example) you're trying to form an alliance with some other company, and in the process tell them things you don't tell the general public. If you've identified the fact that what you're telling them is a trade secret, and they then tell a competitor (or the general public, etc.) or more generally use that information in any way other than the originally intended purpose, it could constitute a trade secret violation. As a side-note: patents and copyright fall under federal law, so they're basically uniform nation-wide. Trade secrets mostly fall under state law, so the exact details vary by state.
Absent a reason to believe otherwise, I'd guess your interest here is primarily in copyright infringement. The key here would be showing that one piece of code was derived from the other. That is, it specifically would not apply in a case where there were only a limited number of ways of doing something, so anybody who wanted to do that had to use one of those ways. Since this would not indicate actual derivation, it would not indicate copyright violation.

