Thanks for the comment @alexyosifov and @ErhanOnur. As the cscf_get_ue_via(struct sip_msg *msg) is used from different modules, the best option would be probably to change the functions like this:
cscf_get_ue_first_via(struct sip_msg *msg) (use the original implementation) cscf_get_ue_last_via(struct sip_msg *msg) (use the proposed implementation)
Then the correct implementation can be used in the ims_registrar_pcscf module.
@ErhanOnur Could you prepare a pull request for this?