It worked as expected when simulated with WOKWI [timer2_test].(timer2_test - Wokwi ESP32, STM32, Arduino Simulator)
The question is:
Why INT0 interrupt is not triggered and INTF0 is not set when function main() is commented out?
Placing sei(); or interrupts(); at the end of setup function did not solved this issue.
Well, I wondered and chatGPT says something I can believe
If you do not define an ISR for INT0 (or any other interrupt), the default behavior is that the interrupt will occur, but no action will be taken.
There is a vector in the slot that points to a default handler that does nothing.
I am not sure what you are asking. If you wonder in what init() consists, read the code, same same for any other functions. You can google it up, but remember that all the source code that ever gets into your sketch object code is on your machine somewhere. It's good to know where that is.
After some research, I concluded that the Arduino framework somehow prevents polling the External Interrupt flag (INTF0). The same hardware and code worked flawlessly when the main function was explicitly defined. I'll leave the "why" to the Arduino experts.
The main difference in the disassembly looks like the Arduino main()/init() will enable interrupts significantly earlier, so the program will restart before any of the pin manipulation is done, whereas with the custom main(), the code in setupPins() will run before interrupts are enabled.
I believe it's possible to poll the external interrupt pins without actually enabling the interrupt, in which case you wouldn't need an ISR for it.
I'm a bit confused as to what "working" vs "not working" means - how is the interrupt being triggered, and what is expected to happen (and/or doesn't happen.)
Before jumping to conclusions, I recommend trying this code simulation: Arduino Layer vs INTF0 Behaviour - Wokwi ESP32, STM32, Arduino Simulator.
It allows you to simulate the same hardware and code, both with and without the Arduino layer. The switch in the simulation does not have any bouncing.
It worked as you WANTED in Wokwi.
I'll stand by my statement that the sketch can't possibly work like that, with no ISR defined. Wokwi must have some bug(s) in their interrupt processing (or they use a different "arduino layer" code, that does something different than the hardware wrt un-handled interrupts.)
I don't see how to get wowki to show anything below the source code level, so it's tough to check.
No need or interest to do so, because your code can't possibly work on the hardware. If the code does work on the simulation, the simulation is definitely buggy.