code: def useless_ifelse_outputs(fgraph, node):
      """Remove outputs that are shared across the IfElse branches."""
      # TODO: This should be a PyTensor canonicalization
      op = node.op
      if_var, *inputs = node.inputs
      shared_inputs = set(inputs[op.n_outs :]).intersection(
          inputs[: op.n_outs]
      )
      if not shared_inputs:
          return None
  
      replacements = {}
      for shared_inp in shared_inputs:
          idx = inputs.index(shared_inp)
          replacements[node.outputs[idx]] = shared_inp
  
      # IfElse isn't needed at all
      if len(shared_inputs) == op.n_outs:
          return replacements
  
      # Create subset IfElse with remaining nodes
      remaining_inputs = [
          inp for inp in inputs if inp not in shared_inputs
      ]
      new_outs = (
          IfElse(n_outs=len(remaining_inputs) // 2)
          .make_node(if_var, *remaining_inputs)
          .outputs
      )
      for inp, new_out in zip(remaining_inputs, new_outs):
          idx = inputs.index(inp)
          replacements[node.outputs[idx]] = new_out
  
      return replacements
  
imports: from typing import List, Optional, Tuple, Union, cast
  import pytensor
  import pytensor.tensor
  from pytensor.graph.basic import Apply, Constant, Variable
  from pytensor.graph.fg import FunctionGraph
  from pytensor.graph.op import Op, compute_test_value
  from pytensor.graph.rewriting.basic import EquilibriumGraphRewriter, node_rewriter
  from pytensor.ifelse import IfElse, ifelse
  from pytensor.scalar import Switch
  from pytensor.scalar import switch
  from pytensor.tensor.basic import Join, MakeVector, switch
  from pytensor.tensor.random.rewriting import local_dimshuffle_rv_lift, local_rv_size_lift, local_subtensor_rv_lift
  from pytensor.tensor.rewriting.shape import ShapeFeature
  from pytensor.tensor.shape import shape_tuple
  from pytensor.tensor.subtensor import AdvancedSubtensor, AdvancedSubtensor1, as_index_literal, get_canonical_form_slice, is_basic_idx
  from pytensor.tensor.type import TensorType
  from pytensor.tensor.type_other import NoneConst, NoneTypeT, SliceConstant, SliceType
  from pytensor.tensor.variable import TensorVariable
  from pymc.logprob.abstract import MeasurableElemwise, MeasurableVariable, _logprob, _logprob_helper
  from pymc.logprob.rewriting import PreserveRVMappings, assume_measured_ir_outputs, local_lift_DiracDelta, measurable_ir_rewrites_db, subtensor_ops
  from pymc.logprob.utils import check_potential_measurability, replace_rvs_by_values
  from pymc.pytensorf import constant_fold
label_desc: Use image node_id 9 for calling a global function with example usage: useless_ifelse_outputs(fgraph, node) and returns: replacements, None, replacements