Regarding compiler deleting memset, there are multiple memory-zeroing functions that are guaranteed not to be optimized away:
https://cppreference.com/c/string/byte/memset (memset_s)
https://cppreference.com/cpp/string/byte/memset (memset_explicit)
Also see notes section for various other functions that people were using before memset_s became standard.