Here is what I understand from your description.
Parent company P acquires controlled subsidiary S either paying exactly the fair value of the assets and liabilities acquired or paying less and recording a gain on a bargain purchase. Either way no Goodwill was recognized on acquisition of S1.
Next, you have S “merging” with another company C. “Merging” has no meaning in IFRS so we need to understand what the transaction really was and will likely depend on whether C is also controlled by P or not.
So, I cannot address your question without the following information.
(1) Is C another subsidiary of P or an entity that is not under the common control of P?
(2) Did S acquire C or did C acquire some percentage of S? The issue is whether P still controls S and/or the new entity S+C.
When you respond, I’ll try to help.