With Brexit talks appearing to be at an impasse as the withdrawal deadline looms, here is a look at what could happen next in the UK's roller-coaster relationship with the EU.

When do things have to be sorted out by?

Britain is scheduled to quit the bloc on 31 October, but the EU heads of government summit in Brussels on October 17-18 will be crucial.

What is the problem?

Again, the issue of the backstop looms large in the difficulties.

British Prime Minister Boris Johnson wants to replace it by keeping Northern Ireland in step with single market rules on goods, but taking it out, along with the rest of the UK, of the customs union.

The draft idea would mean some form of checks on goods to ensure the correct tariff was being paid.

The EU is keen to stick to the border deal agreed by former UK Prime Minister Theresa May.

Could there be a compromise arrangement?

The EU has been standing firmly with Dublin on the border issue, but if there is room for manoeuvre ahead of the Halloween deadline, any tweaked agreement is not guaranteed to pass a UK House of Commons vote, where a number of competing factions of MPs have taken particular stances on what they will, or will not, accept on the Brexit front.

How would the UK Prime Minister pass such an agreement?

Without opposition support, Mr Johnson would have to try to weave a coalition of his backers, the DUP, some former Tories from whom he removed the whip, and Labour rebels.

Not an easy alliance to assemble.

What happens if there is no agreement?

Under the terms of the Benn Act, which the House of Commons passed against the PM's will, the UK government is compelled to ask Brussels for a three-month Brexit extension if there is no deal by 19 October.

What happens then?

The British government insists it will obey the law, but also insists that Britain will leave the EU on 31 October with or without a deal.

A legal challenge to the Benn Act could be in the offing. The UK has to formally ask for an extension before the EU could agree to it.

All 27 remaining EU nations would have to sign up for the extension and they could insist on a shorter or longer duration than the one specified in the Benn Act.

Will there be a general election in UK?

The opposition has insisted it wants to ensure a Brexit extension before agreeing to Mr Johnson's demand for an early poll.

Shadow Brexit secretary Sir Keir Starmer has said that a snap election would be "inevitable" if EU withdrawal is delayed.

There is also the possibility Mr Johnson could resign rather than be the PM to ask for an extension, setting himself up for what he could frame as a "people vs Parliament" election.

What about a new referendum?

Such a move is possible, as some pro-Europeans, such as Labour deputy leader Tom Watson, want to separate Brexit from other issues.

However, a general election is more likely before any attempt at another Brexit poll.