The core problem probably comes down to this (from ISO 9899:2011 6.5.7 Bit-wise shift operators):
The integer promotions are performed on each of the operands. The type of the result is that of
the promoted left operand. If the value of the right operand is negative or is greater than or
equal to the width of the promoted left operand, the behavior is undefined.