// BUG(codahale): Totally untested on big-endian CPUs. Would very much
// appreciate someone with an ARM device giving this a swing.
// advances the keystream
979460
func (s *stream) advance() {
	core(&s.state, (*[stateSize]uint32)(unsafe.Pointer(&s.block)), s.rounds, false)

	if bigEndian {
		j := blockSize - 1
		for i := 0; i < blockSize/2; i++ {
			s.block[j], s.block[i] = s.block[i], s.block[j]
			j--
		}
	}

	s.offset = 0
	i := s.state[12] + 1
	s.state[12] = i
	if i == 0 {
		s.state[13]++
	}
}
848171
func bytesToKey(b []byte, pasteActive bool) (rune, []byte) {
	if len(b) == 0 {
		return utf8.RuneError, nil
	}

	if !pasteActive {
		switch b[0] {
		case 1: // ^A
			return keyHome, b[1:]
		case 5: // ^E
			return keyEnd, b[1:]
		case 8: // ^H
			return keyBackspace, b[1:]
		case 11: // ^K
			return keyDeleteLine, b[1:]
		case 12: // ^L
			return keyClearScreen, b[1:]
		case 23: // ^W
			return keyDeleteWord, b[1:]
		}
	}

	if b[0] != keyEscape {
		if !utf8.FullRune(b) {
			return utf8.RuneError, b
		}
		r, l := utf8.DecodeRune(b)
		return r, b[l:]
	}

	if !pasteActive && len(b) >= 3 && b[0] == keyEscape && b[1] == '[' {
		switch b[2] {
		case 'A':
			return keyUp, b[3:]
		case 'B':
			return keyDown, b[3:]
		case 'C':
			return keyRight, b[3:]
		case 'D':
			return keyLeft, b[3:]
		case 'H':
			return keyHome, b[3:]
		case 'F':
			return keyEnd, b[3:]
		}
	}

	if !pasteActive && len(b) >= 6 && b[0] == keyEscape && b[1] == '[' && b[2] == '1' && b[3] == ';' && b[4] == '3' {
		switch b[5] {
		case 'C':
			return keyAltRight, b[6:]
		case 'D':
			return keyAltLeft, b[6:]
		}
	}

	if !pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteStart) {
		return keyPasteStart, b[6:]
	}

	if pasteActive && len(b) >= 6 && bytes.Equal(b[:6], pasteEnd) {
		return keyPasteEnd, b[6:]
	}

	// If we get here then we have a key that we don't recognise, or a
	// partial sequence. It's not clear how one should find the end of a
	// sequence without knowing them all, but it seems that [a-zA-Z~] only
	// appears at the end of a sequence.
	for i, c := range b[0:] {
		if c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '~' {
			return keyUnknown, b[i+1:]
		}
	}

	return utf8.RuneError, b
}
355502
func Core(dst *[64]byte, state *[64]byte, rounds int) {
	v00 := uint32(state[0]) | (uint32(state[1]) << 8) | (uint32(state[2]) << 16) | (uint32(state[3]) << 24)
	v01 := uint32(state[4]) | (uint32(state[5]) << 8) | (uint32(state[6]) << 16) | (uint32(state[7]) << 24)
	v02 := uint32(state[8]) | (uint32(state[9]) << 8) | (uint32(state[10]) << 16) | (uint32(state[11]) << 24)
	v03 := uint32(state[12]) | (uint32(state[13]) << 8) | (uint32(state[14]) << 16) | (uint32(state[15]) << 24)
	v04 := uint32(state[16]) | (uint32(state[17]) << 8) | (uint32(state[18]) << 16) | (uint32(state[19]) << 24)
	v05 := uint32(state[20]) | (uint32(state[21]) << 8) | (uint32(state[22]) << 16) | (uint32(state[23]) << 24)
	v06 := uint32(state[24]) | (uint32(state[25]) << 8) | (uint32(state[26]) << 16) | (uint32(state[27]) << 24)
	v07 := uint32(state[28]) | (uint32(state[29]) << 8) | (uint32(state[30]) << 16) | (uint32(state[31]) << 24)
	v08 := uint32(state[32]) | (uint32(state[33]) << 8) | (uint32(state[34]) << 16) | (uint32(state[35]) << 24)
	v09 := uint32(state[36]) | (uint32(state[37]) << 8) | (uint32(state[38]) << 16) | (uint32(state[39]) << 24)
	v10 := uint32(state[40]) | (uint32(state[41]) << 8) | (uint32(state[42]) << 16) | (uint32(state[43]) << 24)
	v11 := uint32(state[44]) | (uint32(state[45]) << 8) | (uint32(state[46]) << 16) | (uint32(state[47]) << 24)
	v12 := uint32(state[48]) | (uint32(state[49]) << 8) | (uint32(state[50]) << 16) | (uint32(state[51]) << 24)
	v13 := uint32(state[52]) | (uint32(state[53]) << 8) | (uint32(state[54]) << 16) | (uint32(state[55]) << 24)
	v14 := uint32(state[56]) | (uint32(state[57]) << 8) | (uint32(state[58]) << 16) | (uint32(state[59]) << 24)
	v15 := uint32(state[60]) | (uint32(state[61]) << 8) | (uint32(state[62]) << 16) | (uint32(state[63]) << 24)

	s00, s01, s02, s03, s04, s05, s06, s07 := v00, v01, v02, v03, v04, v05, v06, v07
	s08, s09, s10, s11, s12, s13, s14, s15 := v08, v09, v10, v11, v12, v13, v14, v15

	for i := 0; i < rounds; i += 2 {
		v00 += v04
		v12 ^= v00
		v12 = (v12 << 16) | (v12 >> (16))
		v08 += v12
		v04 ^= v08
		v04 = (v04 << 12) | (v04 >> (20))
		v00 += v04
		v12 ^= v00
		v12 = (v12 << 8) | (v12 >> (24))
		v08 += v12
		v04 ^= v08
		v04 = (v04 << 7) | (v04 >> (25))
		v01 += v05
		v13 ^= v01
		v13 = (v13 << 16) | (v13 >> 16)
		v09 += v13
		v05 ^= v09
		v05 = (v05 << 12) | (v05 >> 20)
		v01 += v05
		v13 ^= v01
		v13 = (v13 << 8) | (v13 >> 24)
		v09 += v13
		v05 ^= v09
		v05 = (v05 << 7) | (v05 >> 25)
		v02 += v06
		v14 ^= v02
		v14 = (v14 << 16) | (v14 >> 16)
		v10 += v14
		v06 ^= v10
		v06 = (v06 << 12) | (v06 >> 20)
		v02 += v06
		v14 ^= v02
		v14 = (v14 << 8) | (v14 >> 24)
		v10 += v14
		v06 ^= v10
		v06 = (v06 << 7) | (v06 >> 25)
		v03 += v07
		v15 ^= v03
		v15 = (v15 << 16) | (v15 >> 16)
		v11 += v15
		v07 ^= v11
		v07 = (v07 << 12) | (v07 >> 20)
		v03 += v07
		v15 ^= v03
		v15 = (v15 << 8) | (v15 >> 24)
		v11 += v15
		v07 ^= v11
		v07 = (v07 << 7) | (v07 >> 25)
		v00 += v05
		v15 ^= v00
		v15 = (v15 << 16) | (v15 >> 16)
		v10 += v15
		v05 ^= v10
		v05 = (v05 << 12) | (v05 >> 20)
		v00 += v05
		v15 ^= v00
		v15 = (v15 << 8) | (v15 >> 24)
		v10 += v15
		v05 ^= v10
		v05 = (v05 << 7) | (v05 >> 25)
		v01 += v06
		v12 ^= v01
		v12 = (v12 << 16) | (v12 >> 16)
		v11 += v12
		v06 ^= v11
		v06 = (v06 << 12) | (v06 >> 20)
		v01 += v06
		v12 ^= v01
		v12 = (v12 << 8) | (v12 >> 24)
		v11 += v12
		v06 ^= v11
		v06 = (v06 << 7) | (v06 >> 25)
		v02 += v07
		v13 ^= v02
		v13 = (v13 << 16) | (v13 >> 16)
		v08 += v13
		v07 ^= v08
		v07 = (v07 << 12) | (v07 >> 20)
		v02 += v07
		v13 ^= v02
		v13 = (v13 << 8) | (v13 >> 24)
		v08 += v13
		v07 ^= v08
		v07 = (v07 << 7) | (v07 >> 25)
		v03 += v04
		v14 ^= v03
		v14 = (v14 << 16) | (v14 >> 16)
		v09 += v14
		v04 ^= v09
		v04 = (v04 << 12) | (v04 >> 20)
		v03 += v04
		v14 ^= v03
		v14 = (v14 << 8) | (v14 >> 24)
		v09 += v14
		v04 ^= v09
		v04 = (v04 << 7) | (v04 >> 25)
	}

	v00 += s00
	v01 += s01
	v02 += s02
	v03 += s03
	v04 += s04
	v05 += s05
	v06 += s06
	v07 += s07
	v08 += s08
	v09 += s09
	v10 += s10
	v11 += s11
	v12 += s12
	v13 += s13
	v14 += s14
	v15 += s15

	s12 += 1
	state[48] = byte(s12)
	state[49] = byte(s12 >> 8)
	state[50] = byte(s12 >> 16)
	state[51] = byte(s12 >> 24)

	dst[0] = byte(v00)
	dst[1] = byte(v00 >> 8)
	dst[2] = byte(v00 >> 16)
	dst[3] = byte(v00 >> 24)

	dst[4] = byte(v01)
	dst[5] = byte(v01 >> 8)
	dst[6] = byte(v01 >> 16)
	dst[7] = byte(v01 >> 24)

	dst[8] = byte(v02)
	dst[9] = byte(v02 >> 8)
	dst[10] = byte(v02 >> 16)
	dst[11] = byte(v02 >> 24)

	dst[12] = byte(v03)
	dst[13] = byte(v03 >> 8)
	dst[14] = byte(v03 >> 16)
	dst[15] = byte(v03 >> 24)

	dst[16] = byte(v04)
	dst[17] = byte(v04 >> 8)
	dst[18] = byte(v04 >> 16)
	dst[19] = byte(v04 >> 24)

	dst[20] = byte(v05)
	dst[21] = byte(v05 >> 8)
	dst[22] = byte(v05 >> 16)
	dst[23] = byte(v05 >> 24)

	dst[24] = byte(v06)
	dst[25] = byte(v06 >> 8)
	dst[26] = byte(v06 >> 16)
	dst[27] = byte(v06 >> 24)

	dst[28] = byte(v07)
	dst[29] = byte(v07 >> 8)
	dst[30] = byte(v07 >> 16)
	dst[31] = byte(v07 >> 24)

	dst[32] = byte(v08)
	dst[33] = byte(v08 >> 8)
	dst[34] = byte(v08 >> 16)
	dst[35] = byte(v08 >> 24)

	dst[36] = byte(v09)
	dst[37] = byte(v09 >> 8)
	dst[38] = byte(v09 >> 16)
	dst[39] = byte(v09 >> 24)

	dst[40] = byte(v10)
	dst[41] = byte(v10 >> 8)
	dst[42] = byte(v10 >> 16)
	dst[43] = byte(v10 >> 24)

	dst[44] = byte(v11)
	dst[45] = byte(v11 >> 8)
	dst[46] = byte(v11 >> 16)
	dst[47] = byte(v11 >> 24)

	dst[48] = byte(v12)
	dst[49] = byte(v12 >> 8)
	dst[50] = byte(v12 >> 16)
	dst[51] = byte(v12 >> 24)

	dst[52] = byte(v13)
	dst[53] = byte(v13 >> 8)
	dst[54] = byte(v13 >> 16)
	dst[55] = byte(v13 >> 24)

	dst[56] = byte(v14)
	dst[57] = byte(v14 >> 8)
	dst[58] = byte(v14 >> 16)
	dst[59] = byte(v14 >> 24)

	dst[60] = byte(v15)
	dst[61] = byte(v15 >> 8)
	dst[62] = byte(v15 >> 16)
	dst[63] = byte(v15 >> 24)
}
1234530
func WriteByteOffs(fp sophie.FsPath, buffer []byte, keyOffs, keyEnds, valOffs, valEnds []int) error {
	if len(keyOffs) != len(keyEnds) || len(keyOffs) != len(valOffs) || len(keyOffs) != len(valEnds) {
		return errorsp.NewWithStacks("length of keyOffs(%d), keyEnds(%d), valOffs(%d) and valEnds(%d) must be the same",
			len(keyOffs), len(keyEnds), len(valOffs), len(valEnds))
	}
	writer, err := fp.Create()
	if err != nil {
		return errorsp.WithStacks(err)
	}
	defer writer.Close()

	for i, keyOff := range keyOffs {
		keyEnd, valOff, valEnd := keyEnds[i], valOffs[i], valEnds[i]
		if err := sophie.VInt(keyEnd - keyOff).WriteTo(writer); err != nil {
			return errorsp.WithStacks(err)
		}
		if _, err := writer.Write(buffer[keyOff:keyEnd]); err != nil {
			return errorsp.WithStacks(err)
		}
		if err := sophie.VInt(valEnd - valOff).WriteTo(writer); err != nil {
			return errorsp.WithStacks(err)
		}
		if _, err := writer.Write(buffer[valOff:valEnd]); err != nil {
			return errorsp.WithStacks(err)
		}
	}
	return nil
}
76497
func main() {
	// os.Setenv("IS_ENABLED", "asdf")
	c := &Config{}
	if err := env.Process(c); err != nil {
		fmt.Println("error:", err)
		return
		// panic(err)
	}
	fmt.Printf("name: %s, port: %d, adapter: %s, enabled: %v\n", c.Name, c.Port, c.Adapter, c.Enabled)
}
793741
func NewTSMBatchKeyIterator(size int, fast bool, interrupt chan struct{}, readers ...*TSMReader) (KeyIterator, error) {
	var iter []*BlockIterator
	for _, r := range readers {
		iter = append(iter, r.BlockIterator())
	}

	return &tsmBatchKeyIterator{
		readers:              readers,
		values:               map[string][]Value{},
		pos:                  make([]int, len(readers)),
		size:                 size,
		iterators:            iter,
		fast:                 fast,
		buf:                  make([]blocks, len(iter)),
		mergedFloatValues:    &tsdb.FloatArray{},
		mergedIntegerValues:  &tsdb.IntegerArray{},
		mergedUnsignedValues: &tsdb.UnsignedArray{},
		mergedBooleanValues:  &tsdb.BooleanArray{},
		mergedStringValues:   &tsdb.StringArray{},
		interrupt:            interrupt,
	}, nil
}
827896
func initAcceptFromNonce(dst, nonce []byte) {
	if len(dst) != acceptSize {
		panic("accept buffer is invalid")
	}
	if len(nonce) != nonceSize {
		panic("nonce is invalid")
	}

	sha := acquireSha1()
	defer releaseSha1(sha)

	sha.Write(nonce)
	sha.Write(webSocketMagic)

	var sb [sha1.Size]byte
	sh := uintptr(unsafe.Pointer(&sb))
	sum := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
		Data: sh,
		Len:  0,
		Cap:  sha1.Size,
	}))
	sum = sha.Sum(sum)

	base64.StdEncoding.Encode(dst, sum)
}
418824
func appendExecute(buf []byte, portal string, maxRows uint32) []byte {
	buf = append(buf, 'E')
	sp := len(buf)
	buf = pgio.AppendInt32(buf, -1)

	buf = append(buf, portal...)
	buf = append(buf, 0)
	buf = pgio.AppendUint32(buf, maxRows)

	pgio.SetInt32(buf[sp:], int32(len(buf[sp:])))

	return buf
}
991415
func bigUint64(v *big.Int) (uint64, bool) {
	return v.Uint64(), !v.IsUint64()
}
224415
func NewCacheKeyIterator(cache *Cache, size int, interrupt chan struct{}) KeyIterator {
	keys := cache.Keys()

	chans := make([]chan struct{}, len(keys))
	for i := 0; i < len(keys); i++ {
		chans[i] = make(chan struct{}, 1)
	}

	cki := &cacheKeyIterator{
		i:         -1,
		size:      size,
		cache:     cache,
		order:     keys,
		ready:     chans,
		blocks:    make([][]cacheBlock, len(keys)),
		interrupt: interrupt,
	}
	go cki.encode()
	return cki
}
113613
func runtimeArchitecture() (string, error) {
	cmd := exec.Command("/usr/bin/uname", "-m")
	machine, err := cmd.Output()
	if err != nil {
		return "", err
	}
	return strings.TrimSpace(string(machine)), nil
}
15979
func newThreefish256_64(key, tweak []uint64) (*threefish256, error) {
    c := new(threefish256)

    // Initialize tweak 
    setTweak(tweak, c.expanedTweak[:])

    c.expanedKey[EXPANDED_KEY_SIZE_256-1] = KEY_SCHEDULE_CONST

    setKey(key, c.expanedKey[:])
    return c, nil
}
1160512
func NewChainProcessor(processors ...Processor) ProcessorFunc {
	return func(in string) (string, bool) {
		out := in
		ok := true
		for _, processor := range processors {
			out, ok = processor.Process(out)
			if !ok {
				return "", false
			}
		}
		return out, ok
	}
}
1037763
func main() {
	f := firmata.NewAdaptor("/dev/ttyACM0")
	f.Connect()

	led := gpio.NewLedDriver(f, "13")
	led.Start()

	for {
		led.Toggle()
		time.Sleep(1000 * time.Millisecond)
	}
}
837473
func main() {
	mathrand.SeedRandomly()

	// Setup process global Context.
	c := context.Background()
	c = gologger.StdConfig.Use(c) // Log to STDERR.

	// TODO(dnj): We currently instantiate global instances of several services,
	// with the current service configuration paramers (e.g., name of BigTable
	// table, etc.).
	//
	// We should monitor config and kill a Flex instance if it's been observed to
	// change. It would respawn, reload the new config, and then be good to go
	// until the next change.
	//
	// As things stand, this configuration basically never changes, so this is
	// not terribly important. However, it's worth noting that we should do this,
	// and that here is probably the right place to kick off such a goroutine.

	// Standard HTTP endpoints using flex LogDog services singleton.
	r := router.NewWithRootContext(c)
	mw := flexMW.ReadOnlyFlex
	mw.InstallHandlers(r)

	// Setup the global services, such as auth, luci-config.
	gsvc, err := flex.NewGlobalServices(flexMW.WithGlobal(c))
	if err != nil {
		logging.WithError(err).Errorf(c, "Failed to setup Flex services.")
		panic(err)
	}
	defer gsvc.Close()
	baseMW := mw.Base().Extend(gsvc.Base)

	// Set up PRPC server.
	svr := &prpc.Server{
		AccessControl: accessControl,
	}
	logsServer := logs.New()
	logsPb.RegisterLogsServer(svr, logsServer)
	discovery.Enable(svr)
	svr.InstallHandlers(r, baseMW)

	// Setup HTTP endpoints.
	// We support OpenID (cookie) auth for browsers and OAuth2 for everything else.
	httpMW := baseMW.Extend(
		auth.Authenticate(
			server.CookieAuth,
			&auth.GoogleOAuth2Method{Scopes: []string{commonAuth.OAuthScopeEmail}}))
	r.GET("/logs/*path", httpMW, logs.GetHandler)

	// Run forever.
	logging.Infof(c, "Listening on port 8080...")
	if err := http.ListenAndServe(":8080", r); err != nil {
		logging.WithError(err).Errorf(c, "Failed HTTP listen.")
		panic(err)
	}
}
1286521
func main() {
	flag.Parse()

	key := os.Getenv("BFX_API_KEY")
	secret := os.Getenv("BFX_API_SECRET")
	c := rest.NewClientWithURL(*api).Credentials(key, secret)

	available, err := c.Platform.Status()
	if err != nil {
		log.Fatalf("getting status: %s", err)
	}

	if !available {
		log.Fatalf("API not available")
	}

	if *orderid != "" {
		ordid, err := strconv.ParseInt(*orderid, 10, 64)
		if err != nil {
			log.Fatal(err)
		}
		os, err := c.Orders.OrderTrades(bitfinex.TradingPrefix+bitfinex.BTCUSD, ordid)
		if err != nil {
			log.Fatalf("getting order trades: %s", err)
		}

		log.Printf("order trades: %#v\n", os)
	} else {
		os, err := c.Orders.History(bitfinex.TradingPrefix + bitfinex.BTCUSD)
		if err != nil {
			log.Fatalf("getting orders: %s", err)
		}

		log.Printf("orders: %#v\n", os)
	}
}
972814
func (s *systemInfo) CPUMHz() (int, error) {
	err := s.collectPlatformInfo()
	if err != nil {
		return 0, err
	}
	return s.cpuMHz, nil
}