President Trump and special counsel Robert Mueller have a complicated relationship.

Mueller must carry out a largely independent investigation into Trump's dealings with Russia and possibly whether he attempted to obstruct justice; Trump must weigh the political costs of how to respond to Mueller's probe and what power he can, or should, exert over him.

The legal underpinnings of the relationship are as complex as the public struggle and illuminate the fraught structural balance between a special counsel and the president.

These are the three key legal questions surrounding their relationship.

Question 1: Could Trump fire Mueller?

Trump does not have the direct authority to fire Mueller, but he does have the power to compel someone else to do it for him.

According to the regulations governing special counsels, a special counsel can be removed “only by the personal action of the Attorney General. The Attorney General may remove a Special Counsel for misconduct, dereliction of duty, incapacity, conflict of interest, or for other good cause,” and the reasoning must be provided in writing.

In this case, that means Deputy Attorney General Rod Rosenstein, since Attorney General Jeff Sessions has recused himself. So, if Trump wants Mueller fired, he has to order Rosenstein to do it. But that's where things could get messy and lead down a similar path to President Nixon's "Saturday Night Massacre," when multiple Justice Department officials resigned rather than follow his orders to fire the special prosecutor.

There are indications that Rosenstein might resign if ordered to do this: he reportedly threatened to quit over how Trump handled firing FBI Director James Comey, and during a hearing before the Senate Appropriations Committee he said of firing Mueller, “I'm not going to follow any order unless I believe those are lawful and appropriate orders... If there were not good cause, it wouldn't matter to me what anybody says."

If Rosenstein resigns rather than follow President Trump’s order (or if Trump fires him), it would begin going down the line of Justice Department officials until Trump finds someone willing to do it. Here’s the catch: legal experts say a Justice official confirmed by the Senate needs to do it, according to an interpretation of a statute. In Nixon’s case, the solicitor general ended up doing it.

But Trump doesn’t have a solicitor general confirmed yet; his Justice Department currently has just three Senate-confirmed officials in place (and three more voted out of committee). The only other Senate-confirmed positions Trump has ready are Associate Attorney General Rachel Brand and Acting Assistant Attorney General for the National Security Division Dana Boente (who is not Senate-confirmed in that position, but has been confirmed as U.S. Attorney for the Eastern District of Virginia). If Brand and Boente won't carry out Trump's wish, then this executive order would designate who comes next.

The other way Trump could potentially fire Mueller and avoid the tricky situation outlined above is if he disregards the special counsel regulations or orders them repealed, and then fires Mueller himself. There’s a constitutional argument for why he could do this, since the president is vested with the ultimate law enforcement power. Special counsel regulations do not and cannot cut into this constitutional authority: they are regulations, not laws. But Trump actually going this route is probably far-fetched.

Question 2: Under what circumstances would Rosenstein recuse himself?

Trump may be under investigation for obstruction of justice. That puts Rosenstein in a sticky situation, because Mueller reports to him, and he was an important player in Trump’s firing of FBI Director James Comey. (He wrote a memo outlining reasons to fire Comey, which Trump at various times has cited as precipitating his decision.)

This means that if Mueller's investigation looks into that action, Rosenstein would be a witness in the obstruction of justice probe. Justice Department regulations are largely mum on this exact situation: the sections governing recusal say an official should step back “if he has a personal or political relationship with... any person or organization substantially involved in the conduct that is the subject of the investigation or prosecution.” That’s not quite the case here, but Rosenstein still may want to avoid the appearance of any ethical violations. He reportedly had a private conversation with Associate Attorney General Rachel Brand saying that he’s considering recusing himself.

If Rosenstein does recuse, that means Brand is running the show. The rest of the above questions stay the same, but she would be the top Justice official Mueller reports to instead of Rosenstein.

Question 3: Can Mueller indict Trump?

This is a constitutional question about whether a sitting president can be criminally prosecuted, and there isn't a clear answer. It has never happened before, and no court has definitively ruled on the issue. (The Supreme Court heard arguments about it in 1974 about Nixon, but never resolved the question.)

Here’s what the Constitution says in Article 1 Section 3: “Judgment in cases of impeachment shall not extend further than to removal from office, and disqualification to hold and enjoy any office of honor, trust or profit under the United States: but the party convicted shall nevertheless be liable and subject to indictment, trial, judgment and punishment, according to law.”

The text of the Constitution doesn’t explicitly state whether a president can be prosecuted while in office, so arguments are based on structure and inference. The official view of the executive branch is that it can't be done. The Office of Legal Counsel wrote in a 2000 memo arguing a president can’t be indicted, “The indictment or criminal prosecution of a sitting President would impermissibly undermine the capacity of the executive branch to perform its constitutionally assigned functions," though it acknowledges, "Neither the text nor the history of the Constitution ultimately provided dispositive guidance in determining whether a president is amenable to indictment or criminal prosecution while in office. It therefore based its analysis on more general considerations of constitutional structure.”

In Mueller’s position as special counsel, he is bound by Justice Department policies, but it’s an unresolved question how much deference he must give to the Office of Legal Counsel's previous legal analyses on this issue. If Mueller decides he can make his own interpretation on this issue and Rosenstein disagrees with his decision, Rosenstein could overrule him by going to Congress and saying that Mueller’s conclusion was “so inappropriate or unwarranted under established Departmental practices that it should not be pursued.”

Still, under the interpretation that the president cannot be indicted in office, Trump would have to resign or be impeached first, and then could be criminally charged afterwards. In that case, if Mueller’s investigation finds what he believes merits an indictment, historically that means he would bring his findings to the House, which would decide if it warrants “high crimes and misdemeanors” to impeach and proceed from there. The basic idea behind this precedent is that if you’re going to undo an election, it should be by a body that is subject to the will of the people.