Picture the scene: it's 08:00 on Friday 24 June*, and a weary David Cameron marches to the microphones outside Downing Street to react to the referendum vote to leave the EU.

Ignoring shouted questions about whether he will resign, he reprises his reaction to his shock Commons defeat over Syria in 2013. "The will of the British people is clear," he says, "I get it and I will negotiate accordingly to implement their clear decision."

Suppose that, or something like that, happens. What next, for the government and for Parliament? How would MPs deliver the decision the British people had just voted for?

The first point to make is that the process cannot easily be separated from the political mayhem that would then unfold.

At the very least, David Cameron and his top lieutenants, Chancellor George Osborne and Foreign Secretary Phillip Hammond, would be fighting for their political lives - with every action and statement viewed through that prism.

Recently I put the prime minister's comment that he would not resign, in the event of a leave vote, to a pro-Brexit Tory backbencher. "He's right," came the response, "of course he won't resign; we'll sack him."

There's already speculation that, in the event of a leave vote, the PM would, John Major-like, seek an immediate vote of confidence from his troops and dare a rival to break cover.

His pitch would be the need for continuity to get the UK through a difficult patch, a message which would be much more powerful if there was some external crisis under way, at the time.

Parliament recalled?

On the other side of the Commons chamber, the interval between referendum day and the Commons summer break represents a window of opportunity for a coup attempt against Labour leader Jeremy Corbyn, before the rules on leadership challenges might be changed at the party conference, so it is possible both the main parties would embark on the withdrawal process in headless chicken mode.

Even so, events might well move very fast. Parliament, due to be in recess until the following Monday, might be recalled for its first Saturday sitting since the Falklands War - that would be at the prime minister's discretion.

The key questions MPs will pose, whenever they get to debate the result, would mostly, but not exclusively, revolve around the timetable and mechanism for withdrawal.

The question of whether emergency measures will be needed to restrict access at the UK's borders, to stop a wave of migrants trying to get in before withdrawal, might also be raised.

Then the process questions would start: when would the government trigger the process by invoking Article 50 of the Treaty of the European Union, which starts a two-year process for leaving?

The argument for doing so immediately is that it dispels any hint of prevarication; the argument against is that two years is quite a short time for a long and complex negotiation, so it might be better to open discussion, while the government's finger hovers over the start button, and eke out a year or more before formally starting the process.

Image copyright AP

"There's everything to be said for delaying triggering Article 50, until preliminary talks have made some progress," says Andrew Tyrie, the Conservative chairman of the Commons Treasury Select Committee.

"It is absurd to suggest there would be any breach of trust, when everyone knows we would be committed to leaving.

"The overwhelming majority of the electorate will accept that, by negotiating for a while before the two-year period, we increase the scope for securing a smooth transition, and minimising the short term economic shock that some commentators warn of," he said.

Next comes the question of what the future relationship between the UK and the EU would look like - suddenly all that talk about Swiss, Canadian and Norwegian models would be very important.

The debates in Commons and Lords would see a series of speakers putting down markers for the negotiations. But how would they monitor what might be two years of withdrawal talks?

Sir Jon Cunliffe, former British permanent representative to the EU, suggested to the Treasury Committee there might be three sets of negotiations:

First on withdrawal terms

Then on the UK's future relationship with the EU

And then on a series of international trade deals, to replace those negotiated under the EU umbrella.

Each of these could have huge implications for interests and individuals.

Image copyright HoC Image caption Sir Jon Cunliffe told MPs there could be three sets of negotiations with the EU in the event of a vote to leave

The normal procedure for trade treaties is that they would be laid before Parliament, along with a government explanatory memorandum, for 21 sitting days before being ratified.

Were MPs to vote against ratification, the government would have 21 days to change minds and try again - but so wide-ranging are implications of an EU exit, that they would certainly want a much more exhaustive process, complete with real-time monitoring and debate, so that they could breathe down the necks of the negotiators.

So expect regular debates on the floor of the Commons, endless select committee inquiries, and possibly the creation of a special committee to ringmaster their efforts - not least because Brexiteers (the name given to those supporting an EU exit) would be very keen to ensure there was no backsliding.

Leadership battles

Equally critical, who would lead the process?

Of course the prime minister would be in ultimate charge of the negotiations, but there would have to be a cabinet-level lead minister, in day-to-day charge of what might be two years of very detailed talks - just as Harold Macmillan dispatched Edward Heath to negotiate UK accession to the EU in the early 1960s.

That person (Justice Secretary Michael Gove would be a good bet) would probably have to be an ideologically-pure Brexiteer; there is simply no way the victorious leave side would tolerate a negotiator who was equivocal about UK withdrawal, and even the hard-line Eurosceptics who backed the PM's renegotiation - Business Secretary Sajid Javid, for example - would probably be ruled out.

Image copyright AFP/Getty Images Image caption The government's official position is in favour of staying in the EU - but some of the cabinet are backing exit

During the negotiating period the chosen person would be the second most important figure in the government, and if the pro-remain David Cameron remained in Downing Street, they might eclipse the prime minister.

It could easily become very destabilising for the government. The only parallel I could come up with was Lloyd George trying to take over the running of the First World War from Herbert Henry Asquith - which Asquith resisted on the grounds that the prime minister should be in charge, and he ended up being elbowed out of office.

The negotiator, in turn, would need a team behind them - and plenty of Brexiteers would relish the chance (energy minister Andrea Leadsom might be a good bet, having founded the Fresh Start think-tank, which has taken a close look at some of the issues involved).

And there might well be a push to have parliamentary observers, as during the abortive attempt to create an EU constitution.

While leadership battles and career calculations were under way, MPs and peers would embark on enormous legislative task.

'Sifting mechanism'

Leaving the EU is not as simple as repealing the 1972 European Communities Act.

Parliament would have to amend or repeal a series of other Acts, as well as 44 years' worth of EU-derived secondary legislation, especially statutory instruments passed under Section 2(2) of the 1972 Act, which would have no legal effect after it had been repealed.

Now, none of this is an argument against Brexit - my point is simply that it cannot be accomplished with a snap of the fingers.

Legislating our way out of the EU would be a prolonged task, especially since there does not appear to have been much preparatory work.

Take this exchange at a hearing of the powerful Public Accounts Committee in February. Jonathan Black, director, Europe at the Treasury was questioned by the Conservative MP Stephen Phillips:

Q: "Mr Black, you can say it: there is no strategic planning going on in the event of a vote by the British people to leave the European Union. That's right, isn't it?

A: "The government's position is to remain a member of a reformed European Union.

Q: "There is no planning going on within the civil service as to what happens if Britain votes to leave the European Union, is there?

A: "The work that we are doing is focused on ensuring that the EU budget, which we are part of as a member of the European Union, is structured and spent as wisely as it can be."

It may well be that Parliament has to set up a special sifting mechanism to work through the layers of euro-legislation and decide what should, and should not, be kept.

'Bold gamble'

One delicate issue would be the extent to which the consent of the Scottish Parliament, Welsh Assembly and Northern Ireland Assembly might be needed.

International relations are supposed to be a matter reserved to Westminster, but EU law does touch on the competences of devolved administrations, so, arguably, leaving the EU would affect their rights and powers.

This could prove important if some parts of the UK had voted to remain, even if the majority had voted to leave - and there is, at the very least a strong possibility that a vote for Brexit could trigger a second Scottish independence referendum.

And as the process nears its conclusion, might the pro-EU forces strike back, and seek to hold a second referendum on the actual terms of withdrawal - if the deal didn't look too attractive?

That would be a bold gamble indeed - and possibly political suicide for those inside an overwhelmingly pro-Leave Conservative Party.

*If the EU referendum follows the pattern of the Scottish referendum, the result should start to become clear by 02:00 BST on Friday 24 June, with a BBC projection probably available by 06:00 BST.