What appears to be happening is
xx = x(n1st:n1nd)
xx = x(1:7)
Which with realloc left hand side enabled resized (reallocates) xx to size of 7.
Try adding -assume:norealloc_lhs to your compiler options.
xx(n1st:n1nd) = x(n1st:n1nd) ! *** with knowledge that xx(8) has not changed.