(a) On return of a writ of habeas corpus and production of a person and cause of his detention before a judge, the judge shall immediately inquire into the legality and propriety of the confinement or detention.
(b) If it appears to the judge that the person is detained without legal warrant or authority, he shall release or discharge the person immediately.
(c) If the judge considers the detention lawful and proper, the person shall be:
(1) Remanded to custody; or
(2) Admitted to bail.
(d) If the person is admitted to bail, the judge shall take a recognizance for his appearance in court and transmit it to a court having jurisdiction over the offense charged.