PALO ALTO — As Google Inc. swooped in to purchase Palo Alto’s Nest Labs for $3.2 billion in cash, the companies and investors sought advice from Orrick, Wilson Sonsini and Goodwin Procter.

Nest Labs, which produces smart thermostats and smoke detectors, was founded in 2010 by a team of Apple engineers and launched its Nest Learning Thermostat the following year. Richard Lutton Jr., Apple’s former chief patent counsel, joined Nest as general counsel in 2012.