Your code has undefined behavior:
From ISO/IEC 9899:201x N1570 §3.4.3
1. undefined behavior
Behavior, upon use of a non portable or erroneous program construct or of erroneous data, for which this International Standard imposes no requirements.
2. NOTE
Possible undefined behavior ranges from ignoring the situation completely with unpredictable results, to behaving during translation or program execution in a documented manner characteristic of the environment (with or without the issuance of a diagnostic message), to terminating a translation or execution (with the issuance of a diagnostic message).
From https://devdocs.io/c/language/behavior
There are no restrictions on the behavior of the program ... Compilers are not required to diagnose undefined behavior (although many simple situations are diagnosed), and the compiled program is not required to do anything meaningful.
...
Because correct C programs are free of undefined behavior, compilers may produce unexpected results when a program that actually has UB is compiled with optimization enabled.
I ran this code in my compiler (gcc version 8.1.0 (x86_64-posix-seh-rev0, Built by MinGW-W64 project)) and it segfaulted.