OPENQASM 3.1; // Teleportation as a subroutine with bits of its own, fed forward, and a // subroutine whose returned measurement lands in the caller's bit. qubit[3] q; bit[1] r; def teleport(qubit src, qubit mid, qubit dst) { bit a; bit b; h mid; cx mid, dst; cx src, mid; h src; a = measure src; b = measure mid; if (b) x dst; if (a) z dst; } def read_out(qubit s) -> bit { return measure s; } x q[0]; teleport(q[0], q[1], q[2]); r[0] = read_out(q[2]);