# Buggy code
def _is_sane_register_variable(self, variable):
    """
    Filters all registers that are surly not members of function arguments.
    This can be seen as a workaround, since VariableRecoveryFast sometimes gives input variables of cc_ndep (which
    is a VEX-specific register) :-(

    :param SimRegisterVariable variable: The variable to test.
    :return:                             True if it is an acceptable function argument, False otherwise.
    :rtype:                              bool
    """

    arch = self.project.arch

    if arch.name == "AARCH64":
        return 16 <= variable.reg < 80  # x0-x7

    elif arch.name == "AMD64":
        return (
            24 <= variable.reg < 40  # rcx, rdx
            or 64 <= variable.reg < 104  # rsi, rdi, r8, r9, r10
        )
        # 224 <= variable.reg < 480)  # xmm0-xmm7

    elif is_arm_arch(arch):
        return 8 <= variable.reg < 24  # r0-r3

    elif arch.name == "MIPS32":
        return 24 <= variable.reg < 40  # a0-a3

    elif arch.name == "MIPS64":
        return 48 <= variable.reg < 80 or 112 <= variable.reg < 208  # a0-a3 or t4-t7

    elif arch.name == "PPC32":
        return 28 <= variable.reg < 60  # r3-r10

    elif arch.name == "X86":
        return (
            8 <= variable.reg < 24  # eax, ebx, ecx, edx
            or 160 <= variable.reg < 288
        )  # xmm0-xmm7

    else:
        l.critical("Unsupported architecture %s.", arch.name)
        return True


# Traceback (AttributeError)
Traceback (most recent call last):
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/main_window.py", line 496, in decompile_current_function
self.workspace.decompile_current_function()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/workspace.py", line 265, in decompile_current_function
view.decompile_current_function()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/disassembly_view.py", line 382, in decompile_current_function
self.workspace.decompile_function(self._current_function.am_obj)
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/workspace.py", line 279, in decompile_function
view.function = func
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/code_view.py", line 66, in function
self.decompile()
File "/home/dnivra/angr-dev/angr-management/angrmanagement/ui/views/code_view.py", line 43, in decompile
d = self.workspace.instance.project.analyses.Decompiler(
File "/home/dnivra/angr-dev/angr/angr/analyses/analysis.py", line 115, in __call__
oself.__init__(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/decompiler.py", line 24, in __init__
self._decompile()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/decompiler.py", line 41, in _decompile
clinic = self.project.analyses.Clinic(self.func,
File "/home/dnivra/angr-dev/angr/angr/analyses/analysis.py", line 115, in __call__
oself.__init__(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 70, in __init__
self._analyze()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 138, in _analyze
ail_graph = self._make_returns(ail_graph)
File "/home/dnivra/angr-dev/angr/angr/utils/timing.py", line 28, in timed_func
return func(*args, **kwargs)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 457, in _make_returns
AILGraphWalker(ail_graph, _handler, replace_nodes=True).walk()
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailgraph_walker.py", line 23, in walk
r = self.handler(node)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 453, in _handler
walker.walk(block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailblock_walker.py", line 37, in walk
self._handle_stmt(i, stmt, block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/ailblock_walker.py", line 50, in _handle_stmt
return handler(stmt_idx, stmt, block)
File "/home/dnivra/angr-dev/angr/angr/analyses/decompiler/clinic.py", line 434, in _handle_Return
and self.function.calling_convention.ret_val is not None:
AttributeError: 'NoneType' object has no attribute 'ret_val'

# Fixed code
def _is_sane_register_variable(self, variable: SimRegisterVariable) -> bool:
    """
    Filters all registers that are surly not members of function arguments.
    This can be seen as a workaround, since VariableRecoveryFast sometimes gives input variables of cc_ndep (which
    is a VEX-specific register) :-(

    :param variable: The variable to test.
    :return:         True if it is an acceptable function argument, False otherwise.
    :rtype:          bool
    """

    arch = self.project.arch

    if arch.name == "AARCH64":
        return 16 <= variable.reg < 80  # x0-x7

    elif arch.name == "AMD64":
        return (
            24 <= variable.reg < 40  # rcx, rdx
            or 64 <= variable.reg < 104  # rsi, rdi, r8, r9, r10
        )
        # 224 <= variable.reg < 480)  # xmm0-xmm7

    elif is_arm_arch(arch):
        return 8 <= variable.reg < 24  # r0-r3

    elif arch.name == "MIPS32":
        return 24 <= variable.reg < 40  # a0-a3

    elif arch.name == "MIPS64":
        return 48 <= variable.reg < 80 or 112 <= variable.reg < 208  # a0-a3 or t4-t7

    elif arch.name == "PPC32":
        return 28 <= variable.reg < 60  # r3-r10

    elif arch.name == "X86":
        return (
            8 <= variable.reg < 24  # eax, ebx, ecx, edx
            or 160 <= variable.reg < 288
        )  # xmm0-xmm7

    else:
        l.critical("Unsupported architecture %s.", arch.name)
        return True