Does it need to be 50 million lines of code?
When you design with security in mind you might have to prune old code and drop some risky optimizations, probably drop some features.
Using a higher-level language might help reduce the line count as well at the cost of performance and memory consumption.