// 32-bit mixing function.
187534
func mmix(h uint32, k uint32) (uint32, uint32) {
	k *= M
	k ^= k >> R
	k *= M
	h *= M
	h ^= k
	return h, k
}
267742
func Uint32s(b0, b1 []uint32) int {
	d := 0
	for i, x := range b0 {
		d += Uint32(x, b1[i])
	}
	return d
}
1096459
func (enc *Encoder) WriteInt32(val int32) error {
	return enc.WriteInt(int(val))
}
557622
func Uint32Bytes(v uint32) []byte {
	b := make([]byte, 4)
	PutUint32(b, v)
	return b
}
310598
func (e *Encoder) EncodeInt32(n int32) error {
	return e.write4(codes.Int32, uint32(n))
}
932643
func MixHash(hash uint32, key uint32) uint32 {
	hash ^= key
	hash = rotateLeft(hash, r2)
	hash = hash*m + n
	return hash

}
466137
func MixKey(key uint32) uint32 {
	key *= c1
	key = rotateLeft(key, r1)
	key *= c2
	return key
}
562589
func SumInt32(s []int32) (sum int32) {
	for _, v := range s {
		sum += v
	}
	return
}
258962
func ConvertUint32(str string) (uint32, error) {
	i, err := strconv.ParseUint(str, 10, 32)
	if err != nil {
		return 0, err
	}
	return uint32(i), nil
}
274859
func sliceBits32(x uint32, high, low uint8) uint32 {
	return (x << (31 - high)) >> (low + (31 - high))
}
547464
func shiftLower(bit byte, b []byte) byte {
	bit = bit << 7
	for i := len(b) - 1; i >= 0; i-- {
		newByte := b[i] >> 1
		newByte |= bit
		bit = (b[i] & 1) << 7
		b[i] = newByte
	}
	return bit >> 7
}
1198388
func as_hex(b []byte, i int) int {
	bi := b[i]
	if bi >= 'A' && bi <= 'F' {
		return int(bi) - 'A' + 10
	}
	if bi >= 'a' && bi <= 'f' {
		return int(bi) - 'a' + 10
	}
	return int(bi) - '0'
}
1347365
func MixAudioFormat(dst, src *uint8, format AudioFormat, len uint32, volume int) {
	_dst := (*C.Uint8)(unsafe.Pointer(dst))
	_src := (*C.Uint8)(unsafe.Pointer(src))
	C.SDL_MixAudioFormat(_dst, _src, format.c(), C.Uint32(len), C.int(volume))
}
1127329
func Hash264(k []byte, seed uint64) uint64 {
	var fast = true // fast is really much faster
	//fmt.Printf("k=%v\n", k)
	//fmt.Printf("length=%d, len(k)=%d\n", length, len(k))

	//The 64-bit golden ratio is 0x9e3779b97f4a7c13LL
	length := uint64(len(k))
	a := uint64(0x9e3779b97f4a7c13)
	b := a
	c := seed
	if fast {
		k64 := sliceUI64(k)
		cnt := 0
		for i := length; i >= 24; i -= 24 {
			a += k64[0+cnt]
			b += k64[1+cnt]
			c += k64[2+cnt]
			// inlining is slightly faster
			a, b, c = mix64a(a, b, c)
			a, b, c = mix64b(a, b, c)
			a, b, c = mix64c(a, b, c)
			a, b, c = mix64d(a, b, c)
			a, b, c = mix64e(a, b, c)
			a, b, c = mix64f(a, b, c)
			k = k[24:]
			cnt += 3
			length -= 24
		}
	} else {
		for i := length; i >= 24; i -= 24 {
			a += uint64(k[0]) | uint64(k[1])<<8 | uint64(k[2])<<16 | uint64(k[3])<<24 | uint64(k[4])<<32 | uint64(k[5])<<40 | uint64(k[6])<<48 | uint64(k[7])<<56
			b += uint64(k[8]) | uint64(k[9])<<8 | uint64(k[10])<<16 | uint64(k[11])<<24 | uint64(k[12])<<32 | uint64(k[13])<<40 | uint64(k[14])<<48 | uint64(k[15])<<56
			c += uint64(k[16]) | uint64(k[17])<<8 | uint64(k[18])<<16 | uint64(k[19])<<24 | uint64(k[20])<<32 | uint64(k[21])<<40 | uint64(k[22])<<48 | uint64(k[23])<<56
			a, b, c = mix64alt(a, b, c)
			k = k[24:]
			length -= 24
		}
	}
	c += length
	if len(k) > 23 {
		panic("Hash264")
	}
	switch length {
	case 23:
		c += uint64(k[22]) << 56
		fallthrough
	case 22:
		c += uint64(k[21]) << 48
		fallthrough
	case 21:
		c += uint64(k[20]) << 40
		fallthrough
	case 20:
		c += uint64(k[19]) << 32
		fallthrough
	case 19:
		c += uint64(k[18]) << 24
		fallthrough
	case 18:
		c += uint64(k[17]) << 16
		fallthrough
	case 17:
		c += uint64(k[16]) << 8
		fallthrough
	case 16:
		b += uint64(k[15]) << 56 // the first byte of c is reserved for the length
		fallthrough
	case 15:
		b += uint64(k[14]) << 48
		fallthrough
	case 14:
		b += uint64(k[13]) << 40
		fallthrough
	case 13:
		b += uint64(k[12]) << 32
		fallthrough
	case 12:
		b += uint64(k[11]) << 24
		fallthrough
	case 11:
		b += uint64(k[10]) << 16
		fallthrough
	case 10:
		b += uint64(k[9]) << 8
		fallthrough
	case 9:
		b += uint64(k[8])
		fallthrough
	case 8:
		a += uint64(k[7]) << 56
		fallthrough
	case 7:
		a += uint64(k[6]) << 48
		fallthrough
	case 6:
		a += uint64(k[5]) << 40
		fallthrough
	case 5:
		a += uint64(k[4]) << 32
		fallthrough
	case 4:
		a += uint64(k[3]) << 24
		fallthrough
	case 3:
		a += uint64(k[2]) << 16
		fallthrough
	case 2:
		a += uint64(k[1]) << 8
		fallthrough
	case 1:
		a += uint64(k[0])
	case 0:
		break
	default:
		panic("HashWords64")
	}
	a, b, c = mix64alt(a, b, c)
	return c
}
1359403
func appendFixed32(b []byte, v uint32) []byte {
	b = append(b,
		byte(v),
		byte(v>>8),
		byte(v>>16),
		byte(v>>24))
	return b
}
186466
func (e Encoder) AppendUint32(dst []byte, val uint32) []byte {
	return e.AppendUint(dst, uint(val))
}
1234665
func (Encoder) AppendInt32(dst []byte, val int32) []byte {
	return strconv.AppendInt(dst, int64(val), 10)
}