[jit] Add support for --debug=casts to one cast codepath, factor out common code. Fixes #18280.