# Path: symsynd/utils.py
# def parse_addr(x):
#     if x is None:
#         return 0
#     if isinstance(x, int_types):
#         return x
#     if isinstance(x, basestring):
#         if x[:2] == '0x':
#             return int(x[2:], 16)
#         return int(x)
#     raise ValueError('Unsupported address format %r' % (x,))


from symsynd.utils import parse_addr
SIGILL = 4
SIGBUS = 10
SIGSEGV = 11


def get_previous_instruction(addr, cpu_name):
    if cpu_name.startswith('arm64'):
        return (addr & -4) - 4
    elif cpu_name.startswith('arm'):
        return (addr & -2) - 2
    else:
        return addr - 1


def get_next_instruction(addr, cpu_name):
    if cpu_name.startswith('arm64'):
        return (addr & -4) + 4
    elif cpu_name.startswith('arm'):
        return (addr & -2) + 2
    else:
        return addr + 1


def get_ip_register(registers, cpu_name):
    rv = None
    if registers:
        if cpu_name[:3] == 'arm':
            rv = registers.get('pc')
        elif cpu_name == 'x86_64':
            rv = registers.get('rip')

# Path: symsynd/utils.py
# def parse_addr(x):
#     if x is None:
#         return 0
#     if isinstance(x, int_types):
#         return x
#     if isinstance(x, basestring):
#         if x[:2] == '0x':
#             return int(x[2:], 16)
#         return int(x)
#     raise ValueError('Unsupported address format %r' % (x,))


# Path: symsynd/heuristics.py
from symsynd.utils import parse_addr

SIGILL = 4
SIGBUS = 10
SIGSEGV = 11


def get_previous_instruction(addr, cpu_name):
    if cpu_name.startswith('arm64'):
        return (addr & -4) - 4
    elif cpu_name.startswith('arm'):
        return (addr & -2) - 2
    else:
        return addr - 1


def get_next_instruction(addr, cpu_name):
    if cpu_name.startswith('arm64'):
        return (addr & -4) + 4
    elif cpu_name.startswith('arm'):
        return (addr & -2) + 2
    else:
        return addr + 1


def get_ip_register(registers, cpu_name):
    rv = None
    if registers:
        if cpu_name[:3] == 'arm':
            rv = registers.get('pc')
        elif cpu_name == 'x86_64':
            rv = registers.get('rip')

    if rv is not None: