Impossible past, the condition is something that cannot happen because the event is over, the speaker express regret about a past event or the wish that had worked out differentely. Rule If + past perfect tense, would have (past participle) So the second tense is incorrect
its the 3rd type of conditional
if i'd (=i had) had any sense, I would have left years ago.
had had --> would have left [ 3 parts]
this is exactly what we called as mix type 2. if simple past - would have p.participle