This paper characterizes the strategic allocation of shares and the offer prices that maximize the expected proceeds from an initial public offering in a setting that incorporates aftermarket trading. The optimal allocation of shares trades-off the pre-market and aftermarket adverse selection costs. We show that flipping can be beneficial to the issuer, even when some investors make profits in the aftermarket. Flipping facilitates truthful information revelation during the offering. The rents can be used, in some instances, to reward informed investors in lieu of the traditional informational rents. The main determinant of the stock allocation is not the size of the rents captured by flippers but the extent to which some investors benefit from their informational advantage in the aftermarket. Finally the results indicate that the considerable latitude granted to underwriters under bookbuilding in relation to the allocation of shares is essential to control the aftermarket trading so as to increase the issuer's revenue.