As an example:
if (digitalRead(legsw == HIGH))
should be:
if (digitalRead(legsw) == HIGH)
Subtle but important.