Maybe it'd be clearer to handle the noncontiguous matrix case by checking if this iteration is a scalar whose parent is a noncontiguous matrix dereference?
Since the loop goes from the component to the variable, rather than the other way around, that would require paying attention to the next iteration, rather than the previous one, and advance `ptr` two steps in that case. I don't think it improves simplicity.
I don't think it's simpler, but it is a bit clearer. I don't think it matters a lot though, so I won't argue too much for it.