add some IPTR casting in order to avoid sign extensions by bit shifting.