Compiler error or code error?

This part is not a problem:

For the rest, it’s clearly a compiler bug.

Which version of ifort are you using? You may upgrade to the lastest ifx version and see if the bug is still present or not.

Or, you can try finding a workaround. You may progressively comment parts of the new code, until the error disappear. At least you will have an idea about which part of the code results in the internal compiler error.