OK, here’s how to do it (only works for posts, and not tested yet).
function get_s2_restricted_posts_by_access_level( $level ) {
$ids = array();
$s2_options = get_option( 'ws_plugin__s2member_options' );
for( $i = 0; $i <= $level; $i++ ) {
if( $s2_options["level_$i_posts"] ) {
$ids = array_merge( $ids, explode( ',', $s2_options["level_$i_posts"] ) );
}
}
return $ids;
}
then
$posts_visible_for_level_2 = get_s2_restricted_posts_by_access_level(2);
get_posts( [ 'post__in' => $posts_visible_for_level_2 ] );