The worst piece of code I've seen that was written and maintained by professionals. I may have written about it here before, like, 10 years ago...
Aaanyway, it was written in C++, in the ninties by people that got employed as programmers because they could type on a keyboard.
It was a massive monster of 1.500 000 rows of code, on top of another 500 000 lines of code for a framework that kindof did CORBA stuff, but only for C++ and Java. That bit was written by a university student as university work for the company.
And about 25 000 lines of tcsh-scripts that made up the mess of a build system that broke as often as it actually built it.
At the very core of the product was a pair of siamese twin classes, one mammoth of 27000 lines of code, where 90% of that (or more) was two methods, one weighing in at like 3000 lines, and the other the rest. The other class was a lot smaller, but that was simply because everyone had grown afraid of changing anything in the first class and just started on a new class. they both imported the other, so to build the horrible shit you first had to build with a fake of one of them, and then you could build the other, and then rebuild the first again.
These two classes did pretty much every single thing wrong, had memory leaks, spaghetti code, lasagna, copy pasta and variables with nonsensical names. And shoveled around data structures with field names like "reserved0, reserved1, reservedByGnu, reserved3, reserved5 and so on. And there was a lot of bit munging to shove multiple things into the same longlong, or short. Or bools and a short into a char[3] and equally dumb stuff.
Me being a stubborn fucktard that does not have enough sense to fear things hacked away in those classes with abandon, and actually started cleaning the shit up. Along with actually daring to touch and eventually making sense of the build system.
This whole mess was so bad that manglement gave up on it and started a new project built from scratch in Java 1.4.2. And got it off to a great start by trying to force the new shit to be written in half a year, with a fair amount of pressure on the poor teams to get shit done. And when someone said they couldn't make the deadlines, manglement just told them to skip testing.
So, the devs simply started copying the C++-files to the java project, renamed them to .java, and hammered them until the compiler accepted them.
Two years later that project kindof caught up with the old codebase that I and 12 others kept working on, while about 70-80 people munged up the new and shiny. So we swapped over, and nothing really worked. But after a year of panicked hacking away at the new not quite as horrible mess the code was kindof passable at least.
It's been a decade or so since I worked on it, and as all anecdotes, mine gets better with time. But it's pretty accurate still.