# [C (gcc)], 176 bytes

<!-- language-all: lang-c -->

    #define p printf("%d ",
    int*_,i;f(x,n)int**x;{if(n<5){for(_=x[2*n-2];_-x[2*n-1];++_)p*_);}else{n-=4;for(i=0;i<8;i+=2)if(n&&x[i]+1-x[i+1])for(_=x[i+1];_-x[i]&&n;--_,--n);p*_);}}

[Try it online!][TIO-jhj9wir9]

[C (gcc)]: https://gcc.gnu.org/
[TIO-jhj9wir9]: https://tio.run/##XZFBj5swEIXv/IpRVo1sMF1gSRTJobfeVr31hCwUERNGTUwEpkVC/HZqm2w2G5@en958M2OX4aks5/nlKCtUEq5wbVHpiqy@HWHFPKP9giGvyMAUtTd/4CNWRO03dKyalhTZkCe@ChPBi3CRseBBUNCrX1A@yXMnRxVmKbdpzCKO@x3HIEuoxazXQ44iiE0pBrGgH0h7cUAU67XiYViwMFSUL9BpfkFVnvujhH2nzcSn7/UPOyxcDqiIFYf2VDIo60MLvtF/c0Fh9MCc11f4OVxlqTvY2Fh/kcpokscMEgZvDFLBYENd2KJ8JTud7wS/OxW2xomj6MHrZNmo45Opa2yfvarpW10/mX6ZpwIyGB2a3WhsAbBbzfSZR@457UaLbKUr5J9mYs0F8@C6Jg76YG5dvWtxw5pvAILGjTgg7CHlEAT48YL2LC@r@ovtolvd/CHume3HMVjBivJ79l@NZwnEhB8J9pi1ze8HhnHQDboE/xL40uDX7/f3Z/Z0V8vWvh3AlFjwkppuKxEbYK6Pm3Qj6I3TSt23yuzqTd48xzEkuzlOIN7O6Txv/wM "C (gcc) – Try It Online"

Takes the array as a list of 4 start/end pointer pairs, then n.