def remove_pin_from_model(pin, model):
    """
    Removes the pin from model name if present.

    Arguments
    ---------

    pin: str
        Pin name
    mode: str
        Timing model name

    Returns
    -------

    str
        Updated timing model name

    >>> remove_pin_from_model("q", "ff_init_d_q")
    'ff_init_d'
    >>> remove_pin_from_model("q", "ff_init_d_ql")
    'ff_init_d_ql'
    >>> remove_pin_from_model("logic_out", "ff_init_d_logic_out")
    'ff_init_d'
    >>> remove_pin_from_model("logic_out", "ff_init_d_second_out")
    'ff_init_d_second_out'
    """

    if len(pin.split('_')) == 1:
        # pin name is one word, search it in the model
        tmp = model.split('_')
        if pin in tmp:
            tmp.remove(pin)
            return "_".join(tmp)
        else:
            return model
    else:
        # pin name is multi word, search for a string
        return "_".join(list(filter(None, model.replace(pin, '').split('_'))))