How to reset all interrupt registers to Factory Settings in Arduino Mega 2560

Thank you Paul

The thing is that I have already removed the EEPROM part of the code and have the values directly in the code to test the problem so there is no issue of garbage value from memory.

In fact I had the same instinct as yours when the issue popped up and I have alreadt cleared the EEPROM bit by bit using the EEPROM_clear code in examples and when it didnt worked out I removed the EEPROM part completely

Moreover the main issue is that why using cli() is solving all the problem and the same code works fine on a new Mega.

I think there is some issue with the Fuse settings getting corrupted and therefore if you can guide me how to reset all the fuses to the factory setting as I have never done this before.