# Path: symsynd/_compat.py
# PY2 = sys.version_info[0] == 2
# def to_bytes(x):


from symsynd._demangler import ffi, lib
from symsynd._compat import text_type


def _make_buffer():
    return ffi.new('char[16000]')


def _demangle(func, sym, buffer=None, simplified=False):
    if buffer is None:
        buffer = _make_buffer()
    if isinstance(sym, text_type):
        sym = sym.encode('utf-8')
    rv = func(sym, buffer, len(buffer), simplified and 1 or 0)
    if rv:
        return ffi.string(buffer).decode('utf-8', 'replace')


def demangle_swift_symbol(symbol, simplified=False):
    return _demangle(lib.demangle_swift, symbol, simplified=simplified)



# Path: symsynd/_compat.py
# PY2 = sys.version_info[0] == 2
# def to_bytes(x):


# Path: symsynd/demangle.py
from symsynd._demangler import ffi, lib
from symsynd._compat import text_type



def _make_buffer():
    return ffi.new('char[16000]')


def _demangle(func, sym, buffer=None, simplified=False):
    if buffer is None:
        buffer = _make_buffer()
    if isinstance(sym, text_type):
        sym = sym.encode('utf-8')
    rv = func(sym, buffer, len(buffer), simplified and 1 or 0)
    if rv:
        return ffi.string(buffer).decode('utf-8', 'replace')


def demangle_swift_symbol(symbol, simplified=False):
    return _demangle(lib.demangle_swift, symbol, simplified=simplified)



def demangle_cpp_symbol(symbol, simplified=False):