def METHOD_NAME(fsm):
    """
    Generates a Mermaid text definition for a state diagram 
    representing the FSM.
    Details on Mermaid UML syntax:
    https://mermaid.js.org/syntax/stateDiagram.html
    :param fsm: the FSM code containing its transition table
    :returns: the mermaid.js text definition for FSM diagram
    """
    # Regex match to extract transition table from the FSM
    transition_table_match = re.search(r"make_transition_table\(([\s\S]*?)\);", fsm)
    if not transition_table_match:
        return
    transition_table = transition_table_match.group(1)
    # Remove comment lines
    transition_table = re.sub(r"//.*$", "", transition_table, flags=re.MULTILINE)
    # Remove all whitespace
    transition_table = re.sub(r"\s+", "", transition_table, flags=re.MULTILINE)
    diagram = ""
    transitions = transition_table.split(",")
    for transition in transitions:
        # Transitions have the following format:
        # src_state + event [guard] / action = dest_state
        # Extract dest_state from transition, which is after '=' sign
        transition, *rest = transition.split("=")
        dest_state = rest[0] if rest else ""
        # Extract action from transition, which is after '/' sign
        transition, *rest = transition.split("/")
        action = rest[0] if rest else ""
        # Extract guard contained between square brackets
        guard = next(iter(re.findall(r"\[(.*?)\]", transition)), "")
        # Extract src_state from transition, which is before '+' sign
        src_state = transition.split("+")[0]
        def remove_suffix(str, suffix):
            return str[: -len(suffix)] if str.endswith(suffix) else str
        # Remove suffixes from states, guard, action
        src_state = remove_suffix(src_state, "_S")
        dest_state = remove_suffix(dest_state, "_S")
        guard = remove_suffix(guard, "_G")
        action = remove_suffix(action, "_A")
        # Terminate state is marked with X in transition table.
        # Give terminate state custom styling with the
        # :::terminate classDef style
        if dest_state == "X":
            dest_state = "Terminate:::terminate"
        if src_state == "X":
            src_state = "Terminate:::terminate"
        # Initial state is marked with '*' prefix, so need to add
        # special transition from start to initial state in our diagram
        if src_state.startswith("*"):
            src_state = src_state[1:]
            diagram += f"[*] --> {src_state}\n"
        # If dest_state is omitted, it is an internal transition
        if not dest_state:
            dest_state = src_state
        diagram += f"{src_state} --> {dest_state}"
        if guard:
            diagram += f" : [{guard}]"
            if action:
                diagram += f"\\n<i>{action}</i>"
        elif action:
            diagram += f" : <i>{action}</i>"
        diagram += "\n"
    return diagram