The court or judge before whom the party is brought on a writ of habeas corpus shall, immediately after the return thereof, examine into the facts contained in such return, and into the cause of the confinement or restraint of such party, whether the same has been upon commitment for any criminal or supposed criminal matter or not; and if issue be taken upon the material facts in the return, or other facts are alleged to show that the imprisonment or detention is illegal, or that the party imprisoned is entitled to his discharge, the court or judge shall proceed, in a summary way, to hear the allegations and proofs on both sides, and to do what to justice appertains in delivering, bailing or remanding such party.
N.C. Gen. Stat. § 17-32