How legal it is to get a change of status from B1/B2 to H1B transfer from comp A to B. (not working for A anymore)

My question is whether it is an issue if I apply a change of status from B1/B2 to H1B with the scenario provided:

a) Having an approved I140 from Comp A.

b)Having a valid I797 from Comp A until Sep 2016, but no longer working for Company A since March 2014. Have been working for another company Deloitte in India from June 2014.

c)Having a valid H1B stamp on passport until Sep 2016.

So, I am planning to get a B1/B2 visa and come to US on that and apply for jobs. If I get a job, can I get my H1B transferred from Comp A to another Comp B(where I get my job/employer).

How successful or how legal is this procedure?

Thanks.

Immiseeker.