Two sentences;
one in the past, one in the now/future
if (past) => 3rd, main clause (now/future) => 2nd
If + past perfect, could/would/might + infinitive
if (now/future) => 2nd, main clause (past) => 3rd
if + past simple, could/would/might have + past participle