def replace_returns(blocks, target, return_label):
    """
    Return return statement by assigning directly to target, and a jump.
    """
    for block in blocks.values():
        # some blocks may be empty during transformations
        if not block.body:
            continue
        stmt = block.terminator
        if isinstance(stmt, ir.Return):
            block.body.pop()  # remove return
            cast_stmt = block.body.pop()
            assert (isinstance(cast_stmt, ir.Assign)
                and isinstance(cast_stmt.value, ir.Expr)
                and cast_stmt.value.op == 'cast'), "invalid return cast"
            block.body.append(ir.Assign(cast_stmt.value.value, target, stmt.loc))
            block.body.append(ir.Jump(return_label, stmt.loc))

    Return return statement by assigning directly to target, and a jump.
    
numba/core/ir_utils.py