Currently when simplifying to a library function for which no declaration exists a new declaration is created which defaults to the C calling convention. This can cause problems if the definition is of a different calling convention, so use the calling convention of the library call that's being replaced.
Fixes PR45524.
clang-format: please reformat the code