Publish a paper with flaws, improve it, or let it go?
My thoughts on

How do you decide whether work is worth salvaging?

I think a better question is how to salvage, not how to decide whether to salvage.
You even suggest some possibilities

If the referees' reports suggest changes that you think make sense
then the review process is working. Make the changes and resubmit,
there or elsewhere.
Clean up some obvious bad places and post as a preprint.
Incorporate the good parts in another project.
Some dead ends should be acknowledged as such - and published. See What to do when you spend several months working on an idea that fails in a masters thesis?
Maybe the referees were right to reject. I have two manuscripts from
years ago that I never reworked or resubmitted.