Blocking wait for pin change on a LPC1114 microcontroller
I assume that you have changed the IOCON of the PWM output pin to change its function from GPIO pin to Counter/Timer output pin. Your while statements are then trying to use the same pin as a GPIO input, and my guess is that you just can't do that.

You haven't told us the duty cycle of your PWM signal but at 1MHz you only have 48 clock cycles for the entire period. If the duty cycle gets down below 10% or above 90% it will be very difficult to catch both the low time and the high time. This might be a good place for hand-optimized assembly code.

In any event, it will be difficult to detect an edge on a 1MHz signal and toggle another output bit very quickly. I'm not sure you could still say that the output was "synchronized" to the PWM edge.