1st you need to find the mole ratio between KClO3 and O2. To find that you need to take the coefficents of each of the compounds. That gives a ratio of 2:3.
Now we find out how many each unit is:
2x = 12
x = 6
Now we multiply it by 3 to find the number of moles of O2
3(6) = 18 mol O2.