It does not follow that an atmosphere containing 40% hydrogen cannot have changed into one containing 78% nitrogen. The gas giants today are the hydrogen-containing planets simply because they are big enough to prevent the hydrogen from escaping. Hydrogen molecules, since they are much lighter, have a much higher average velocity at a given temperature than do nitrogen and oxygen (and CO2 and any other gas) molecules. At terrestrial temperatures, this velocity typically exceeds the earth's escape velocity, so the hydrogen escapes. On gas giants, the escape velocity is higher than the molecular velocity, so the hydrogen is retained.
As far as going from 40% hydrogen to 78% nitrogen goes, for simplicity consider a small atmosphere containing 166 molecules, 66 of which are hydrogen, 78 are nitrogen, 21 are oxygen and one is argon. This atmosphere then contains 66/166 = ~40% hydrogen, 78/166 = ~47% nitrogen, 21/166 = ~12.5% oxygen and 1/166 = ~0.5% argon. Now allow all of the hydrogen molecules to escape and you are left with an atmosphere containing 78 nitrogen, 21 oxygen and 1 argon molecule. This atmosphere then has a composition that should be familiar, ie. 78% nitrogen, 21% oxygen, and 1% argon.
I did not say cannot. I asked where it came from. If that is your scientific theory, it still needs to explain where carbon dioxide fits in.