I'm in my senior year of undergrad. I messed up a little bit academically this semester - not seriously, but enough to be confident I wouldn't get into a top 20 math PhD program. So I wanted to work on improving my CV for a year or two and then apply to the top 20 PhD programs (kind of like this person). I was thinking of this year applying to 2nd-tier schools for either a Master's or PhD program, then if I'm excelling really well in my first semester, applying to 1st-tier math PhD programs at the end of that semester. The main question I have is whether I should apply to the Master's or the PhD programs at 2nd-tier schools.
At first it seemed like a no-brainer to apply to the PhD programs at the 2nd-tier schools in order to receive free tuition and a stipend (which usually don't come with Master's programs). But then I was worrying if it would be looked down upon by both the university I am at and the one I am applying to if I am "quitting" one funded PhD program in order to join another. I especially felt concerned after looking at this answer, which describes a PhD as a "long-term relationship... an expensive and rare opportunity." Should I avoid applying to one PhD program with the intent of leaving for another (more prestigious) one? If so, should I just apply to Master's programs at the 2nd-tier schools this year?