#include<iostream>
#include<vector>
#include<stack>
#include<utility>
#define P(i, j) all[i-r0][j-c0]
#define C(i, j) check[i-r0][j-c0]
int r0, c0, r1, c1;
std::stack<std::pair<std::pair<int, int>, int>> s;
std::vector<int> mov = {-1, 0, 1};
int move(std::vector<std::vector<bool>> all, std::vector<std::vector<bool>> check){
    auto p = s.top();
    if(p.first.first==r1&&p.first.second==c1)
        return p.second;
    while(!s.empty()){
        for(int i=0; i<3; i++)
            for(int j=0; j<3; j++){
                auto r = p;
                r.first.first += mov[i];
                r.first.second += mov[j];
                r.second++;
                if(r.first.first>=r0&&r.first.first<=r1&&r.first.second>=c0&&r.first.second<=c1&&P(r.first.first, r.first.second)&&!C(r.first.first, r.first.second)){
                    s.push(r);
                    C(r.first.first, r.first.second) = 1;
                    return move(all, check);
                }
            }
        s.pop();
    }
}
int main(){
    std::cin>>r0>>c0>>r1>>c1;
    s.push({{r0, c0}, 0});
    int n;  std::cin>>n;
    std::vector<std::vector<bool>> all(r1-r0+1, std::vector<bool>(c1-c0+1));
    std::vector<std::vector<bool>> check(r1-r0+1, std::vector<bool>(c1-c0+1));
    C(r0, c0)=1;
    for(int i=0; i<n; i++){
        int tempx;
        std::cin>>tempx;
        int tempy1, tempy2;
        std::cin>>tempy1>>tempy2;
        for(int j=tempy1; j<=tempy2; j++)
            if(j<=c1&&j>=c0&&tempx<=r1&&tempx>=r0)
                P(tempx, j) = 1;
    }
    std::cout<<move(all, check)<<'\n';
}
In the above program, when I provide the following inputs
5 7 6 11
3
5 3 8
6 7 11
5 2 5
and then use a debugger to analyze the code, its weird that on the 6th call, when the code reaches return move(all, check), its not called and no stack for it is created. Instead its just skipped and s.pop() function is called sequentially. Is there any valid reason for this ?
Please use breakpoints at return move(all, check) and s.pop() if you are putting this on a debugger.