Currently, flang -c file.f generates flang_unparsed_source_file_0.o.
This is incorrect. This patch:
- simplifies the logic around output filename generation, and
- makes sure that file.o is produced instead of e.g. flang_unparsed_source_file_0.o when using the -c flag
The output filename generation is moved to a dedicated function. I've
also made a few minor improvements, e.g. marked variables as local,
added comments, refined error messages.