Things start to get a little messy here. When we invoke method m2 from a pointer to X, we don’t really know which one to call at compile time. This is because m2 is virtual.
The mini-block starting on line 64 handles the dynamic resolution of method m1 when we are only given a pointer to an X object. First, we use the temporary variable vtab to make life a little simpler.
vtab is a pointer to a struct X_vtable. However, the pointer is computed based on the pointer pX and its derived_offset. Recall that the derived_offset is the offset (in number of bytes) to get back to the subclass that inherits X. In this case, it is -4 because we initialized myY.superX.derived_offset = -4, and pX = &(myY.superX).
In other words, vtab is really pointing to _YX_vtable, not _X_vtable!
The following line invokes the function pointed to by member m1. This essentally calls X_m1 because that is how YX_vtable.m1 is initialized.
The this pointer is computed as well. It is based on pX, but with the offset specified by _YX_vtable.offset_m1 and pX->dervied_offset. In this particular case, the offset is 0, as we initialized _YX_vtable.offset_m1 == 8, but pX->derived_offset == -8. This is because pX is a pointer to an X object, and X_m1 expects exactly that. There is no need to adjust anything.
The set up of pX->m2() is similar, but it has some significant differences. This is the mini-block of code starting on line 68. The computation of vtab is the same as that of the previous one. However, this time, the computation of the this pointer is different. This is because _YX_vtable.m2 is a pointer to Y_m2, which expects the this pointer to be a pointer to a Y object. pX is a pointer to an X object. So, to compute the proper this pointer, we need to add to the pointer the offset of -8, which is the sum of _YX_vtable.offset_m2 == 0 and pX->derived_offset == -8. In other words, we are morphing a (X *) to a (Y *) at run time.
Of course, if this code is actually going to be compiled by a C compiler, lines 66 and 70 have type matching problems. There is no way to fix this problem because there is no way that we know how to cast the this pointer at compile. Otherwise, we would have used a static call determined at compile-time instead!