Test that optimized variables are correctly written back.

When an optimized variable is assigned in a conditional, special
care must be taken to produce the correct result (e.g. when
the variable is assigned in only one branch of an if(), at the
end of the if() the optimized value needs to be writen back to the
scalar and marked as invalid).
WIP
WIP