'At the end of a basic block, simulate the very last instruction to see if the return address is read from the
stack and written in PC. If so, the jumpkind of this IRSB will be set to Ijk_Ret. For detailed explanations,
please see the documentation of _arm_track_lr_on_stack().
:param int addr: The address of the basic block.
:param pyvex.IRSB irsb: The basic block object.
:param Function function: The function instance.
:return: None'

def _arm_track_read_lr_from_stack(self, addr, irsb, function):

    if (('lr_saved_on_stack' not in function.info) or (not function.info['lr_saved_on_stack'])):
        return
    sp_offset = self.project.arch.sp_offset
    initial_sp = 2147418112
    last_sp = None
    tmps = {}
    last_imark = next((stmt for stmt in reversed(irsb.statements) if isinstance(stmt, pyvex.IRStmt.IMark)), 0)
    tmp_irsb = self.project.factory.block((last_imark.addr + last_imark.delta)).vex
    for stmt in tmp_irsb.statements:
        if isinstance(stmt, pyvex.IRStmt.WrTmp):
            data = stmt.data
            if (isinstance(data, pyvex.IRExpr.Get) and (data.offset == sp_offset)):
                tmps[stmt.tmp] = initial_sp
            elif isinstance(data, pyvex.IRExpr.Binop):
                if (data.op == 'Iop_Add32'):
                    (arg0, arg1) = data.args
                    if (isinstance(arg0, pyvex.IRExpr.RdTmp) and isinstance(arg1, pyvex.IRExpr.Const)):
                        if (arg0.tmp in tmps):
                            tmps[stmt.tmp] = (tmps[arg0.tmp] + arg1.con.value)
            elif isinstance(data, pyvex.IRExpr.Load):
                if isinstance(data.addr, pyvex.IRExpr.RdTmp):
                    if (data.addr.tmp in tmps):
                        tmps[stmt.tmp] = ('load', tmps[data.addr.tmp])
        elif isinstance(stmt, pyvex.IRStmt.Put):
            if ((stmt.offset == sp_offset) and isinstance(stmt.data, pyvex.IRExpr.RdTmp)):
                if (stmt.data.tmp in tmps):
                    last_sp = tmps[stmt.data.tmp]
    if ((last_sp is not None) and isinstance(tmp_irsb.next, pyvex.IRExpr.RdTmp)):
        val = tmps[tmp_irsb.next.tmp]
        if (isinstance(val, tuple) and (val[0] == 'load')):
            memory_addr = val[1]
            lr_on_stack_offset = (memory_addr - last_sp)
            if (lr_on_stack_offset == function.info['lr_on_stack_offset']):
                irsb.jumpkind = 'Ijk_Ret'
