Auto-detect the redirect url from the original url

You can simply write your own function this way:

function get_old_link($url) {
        global $wpdb;

        // get only url path 
        $parse = parse_url($url);
        $path = trim($parse['path'], "https://wordpress.stackexchange.com/");

        // get last part as slug
        $arr = explode("https://wordpress.stackexchange.com/", $path);
        $slug = end($arr);

        // find post id by meta_key and meta_value
        $row = $wpdb->get_row("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_old_slug' AND meta_value="{$slug}"");

        if(!empty($row->post_id))
            return get_permalink($row->post_id);
}

Note: it is possible to make this function better. I only want to show you the direction.