Can I transfer H1 (not stamped) to H4 and then back to H1 without going through H1 lottery again?

I got picked up in the lottery in 2018. I worked for my employer A from Oct to May and then had to come to India for 3 months. I haven’t stamped my H1 yet. If I quit my current job and go back to the US on a H4 visa, can I transfer my H1 to a new employer B without going through the lottery? What if my employer A revokes or withdraws the first h1b petition? Can employer B still file for a cap exempt H1 transfer?

Yes, you can. Even, if they revoke, it does not matter. You were counted towards H1B cap once and you can use it anytime as cap exempt.