# We import necessary libraries from Qiskit
from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_histogram

# We create a quantum circuit with two qubits and two classical bits
qc = QuantumCircuit(2, 2)

# We apply the CX gate with the first qubit as control and the second qubit as target
control_qubit = 0
target_qubit = 1
qc.cx(control_qubit, target_qubit)

qc.measure([0, 1], [0, 1])

# We visualize the quantum circuit
qc.draw('mpl')

# We simulate the quantum circuit
simulator = Aer.get_backend('qasm_simulator')
result = execute(qc, simulator).result()

# We get the measurement results
counts = result.get_counts(qc)

# We visualize the measurement results
plot_histogram(counts)

qc1 = QuantumCircuit(2, 2)
qc1.x(1)
qc1.cx(0, 1)
qc1.measure([0, 1], [0, 1])

qc1.draw('mpl')

# We simulate the quantum circuit
simulator = Aer.get_backend('qasm_simulator')
result = execute(qc1, simulator).result()

# We get the measurement results
counts = result.get_counts(qc1)

# We visualize the measurement results
plot_histogram(counts)

qc2 = QuantumCircuit(2, 2)
qc2.x(0)
qc2.cx(0, 1)
qc2.measure([0, 1], [0, 1])

qc2.draw('mpl')

# We simulate the quantum circuit
simulator = Aer.get_backend('qasm_simulator')
result = execute(qc2, simulator).result()

# We get the measurement results
counts = result.get_counts(qc2)

# We visualize the measurement results
plot_histogram(counts)

magical_circuit = QuantumCircuit(2, 2)
magical_circuit.x(1)
magical_circuit.barrier()

magical_circuit.h(0)
magical_circuit.h(1)

magical_circuit.cx(0, 1)

magical_circuit.h(0)
magical_circuit.h(1)
magical_circuit.barrier()

magical_circuit.measure([0, 1], [0, 1])

magical_circuit.draw('mpl')

simulator = Aer.get_backend('qasm_simulator')
result = execute(magical_circuit, simulator).result()
counts = result.get_counts(magical_circuit)

plot_histogram(counts)