Hoist up some typechecks to avoid emitting them repeatedly.

Also simplify some bitwise ops.
Add FIXME about some probably obsolete code.