This has been an interesting thread, and Dan's colorful descriptions got me thinking, 'Suppose we could write the Code Exorciser that he asks for, how well would it work?' In other words, what would we gain, if we had such a tool? Even though we do not have such a tool, we could simulate (with manual labor) what it is supposed to do, and assess whether it would be worth developing.
Fortunately, I had available to me a nice test case. Here was a well-established and widely used code with a history of over 30 years. I had recently found a bug in FTN95 that showed up when applied to the code, spent quite a bit of time creating a small reproducer and reporting the bug (see https://forums.silverfrost.com/Forum/Topic/3332 ). The original code, at http://www.tampa.phys.ucl.ac.uk/rmat/src/inner/swmol3/swmol3.f, is 143 kbytes, mostly F77 and a few allocatable local arrays. My manually created reproducer is 245 bytes.
Here is what I did.
Step 1: Choose a test case (input data) for which the bug surfaced. Compile with /debug and locate the line where the program aborted, and obtain the traceback. (prog. size: 143 kb)
Step 2: Place a STOP statement above the line located in Step 1, compile with /timing, and run again. From the .TMR report that was generated, obtain a list of subprograms that were not executed during the run. Remove the STOP statement placed in this step. (prog. size: 143 kb)
Step 3: Remove the source code of the unused subprograms, and replace that by dummy subprograms that had just STOP 'Subroutine xxx was called'. Compile and run to verify that the bug is still present. (prog. size: 50 kb)
Step 4: Remove the source lines in the main program that came logically after the subroutine call that caused the abort. Compile and run to verify that the bug is still present. (prog. size: 43 kb)
Step 5: Further reduction by removing unused variables. FTN95 gave me a list of unused variables, but I did not want to spend the time to remove them manually. Instead, I used SPAG with clutter removal set at level 5. The resulting program ran, but the bug had disappeared. (prog. size: 49 kb).
Conclusions: The tool that Dan wants would have taken care of Steps 4 and 5 with little effort from the user. Unfortunately, the reduction in size (from full code to reproducer) was just 1/3 (compare to the 1/600 that resulted from manual code simplification). Furthermore, clutter removal had the unfortunate effect of making the bug disappear.
Side result: It is curious that SPAG's removing the declarations of unused local allocatable arrays caused the bug to disappear. This finding may help with fixing the bug reported in https://forums.silverfrost.com/Forum/Topic/3332 . Is FTN95 generating code to deallocate, just before the RETURN statement, arrays that, since they were never used, it decided earlier not to allocate?