code: func Parse(r io.Reader) (*Profile, error) {
  	orig, err := ioutil.ReadAll(r)
  	if err != nil {
  		return nil, err
  	}
  
  	var p *Profile
  	if len(orig) >= 2 && orig[0] == 0x1f && orig[1] == 0x8b {
  		gz, err := gzip.NewReader(bytes.NewBuffer(orig))
  		if err != nil {
  			return nil, fmt.Errorf("decompressing profile: %v", err)
  		}
  		data, err := ioutil.ReadAll(gz)
  		if err != nil {
  			return nil, fmt.Errorf("decompressing profile: %v", err)
  		}
  		orig = data
  	}
  	if p, err = parseUncompressed(orig); err != nil {
  		if p, err = parseLegacy(orig); err != nil {
  			return nil, fmt.Errorf("parsing profile: %v", err)
  		}
  	}
  
  	if err := p.CheckValid(); err != nil {
  		return nil, fmt.Errorf("malformed profile: %v", err)
  	}
  	return p, nil
  }
docs: // Parse parses a profile and checks for its validity.  The input
  // may be a gzip-compressed encoded protobuf or one of many legacy
  // profile formats which may be unsupported in the future.