I created a Simulink library that contains an atomic subsystem configured to be reusable (SYS_MAT). That subsystem contains a Matlab Function.
I created a Simulink subsystem (SYS) that uses the library block (SYS_MAT) as a linked subsystem two times. First instance, it is driven by an input port. Second instance, it is driven by a Constant block. When I try to generate code from the Simulink subsystem (SYS) using Embedded Coder, the reusable library block generates duplicate code i.e. the function is not reused for the two instances of SYS_MAT. It seems that somehow driving the Matlab Function from a Constant block input impacts reusability.
I attached my simple test. To recreate the problem, open code_gen_test_duplication.slx, right click SYS block, C/C++ and build this subsystem. Inspect the code generation report for the dulicated code generation of SYS_MAT.c.