Another thing to consider is that as a referendum isn't legally binding even if the vote was Out then the government wouldn't have to more forward and leave the EU.
Clearly it would be political suicide for Cameron, but think it's possible he'd be prepared to fall on the sword.