How to reinstall antitheft on locked phone after device deleted from Avast a/c

Oh crap! I will name my first born child after you if you can help please Tomas! I’ve really screwed my phone up and I have no idea what to do now! I installed Avast on my HTC One M8 a couple of years ago and now don’t remember the settings/PINs or have access to the ‘friend’ phone number. I had the screen replaced on the device and then of course Avast locked it after the repairer turned it back on. I did eventually manage to turn the siren off and get the phone back to ‘normal’ again but I don’t recall how I did it exactly. I have been into my Avast account and tried to change the PIN and I thought I was successful. Because it freaked me out so much, I tried to uninstall all the Avast stuff from my phone, but had obviously forgotten that there was a Stealth mode and therefore I haven’t really cleared it all out. The phone has been working fine for about a month, so I didn’t really bother about investigating further, but yesterday I caught a flight and had to turn the phone off. When I turned it back on, bingo! siren and message and much embarrassment in the middle of the airport! Unfortunately, I have also deleted the device from my Avast account, but now I can’t access anything about it anywhere and have no idea how I can reinstall the program so I can reconfigure it before it goes into lockdown mode. I’m the Captain of a Volunteer Fire & Rescue Brigade and my phone is literally like a lifeline! If anybody has any idea what I might be able to do, I would be eternally grateful!

Factory reset the phone.