Source: 3.4.50 swap_state