When they save of bunch of taxes they have done what’s in the best interest of the company
An action done on behalf of Company 1 which slightly hurts company 1 but provides large gains to company 2 would be illegal (unless they can argue that it was part of a larger strategy to benefit company 1).