def reverse(ifst, require_superinitial=True):
    """
    Constructively reverses an FST's transduction.

    This operation reverses an FST. If A transduces string x to y with weight a,
    then the reverse of A transduces the reverse of x to the reverse of y with
    weight a.Reverse(). (Typically, a = a.Reverse() and Arc = RevArc, e.g.,
    TropicalWeight and LogWeight.) In general, e.g., when the weights only form
    a left or right semiring, the output arc type must match the input arc type.

    Args:
        ifst: The input FST.
        require_superinitial: Should a superinitial state be created?

    Returns:
        A reversed FST.
    """
    ofst = ifst._mutable_fst_type()
    ifst._ops.reverse(ifst, ofst, require_superinitial)
    return ofst