Structure _If-Else_ Statement
- You have a conditional jump to two sets of consecutive statements.
Make each set of statements a clause of the conditional statement.
if(cond) goto skip1; /* cond is false */ ... goto skip2; skip1: /* cond is true */ ... skip2:
⇓
if(!cond) { /* cond is false */ ... } else { /* cond is true */ ... }
Motivation
If-then-else statements are translated by the compiler as a conditional jump to two sets of consecutive statements. This refactoring recovers the original control structure.
Mechanics
Negative the if statement condition.
Make the first set of skipped statements the then clause.
Make the second set of skipped statements the else clause.
- Remove any unused label.