/*
func ShortTest(n int) {
	var u = make([]uint32, 1, 1)

	for i := 0; i < n; i++ {
		u[0] = uint32(i)
		h := jenkins3.HashWords32(u, 0)
		fmt.Printf("i=%d, 0x%08x, h=0x%08x\n", i, i, h)
	}
}
*/
493698
func main() {
	flag.Parse()
	if *p != "" {
		f, err := os.Create(*p)
		if err != nil {
			log.Fatal(err)
		}
		pprof.StartCPUProfile(f)
		defer pprof.StopCPUProfile()
	}

	//ShortTest(*n)
	//return
	benchmark32(*n)
	benchmark64(int64(*n))

	q := "This is the time for all good men to come to the aid of their country..."
	//qq := []byte{"xThis is the time for all good men to come to the aid of their country..."}
	//qqq := []byte{"xxThis is the time for all good men to come to the aid of their country..."}
	//qqqq[] := []byte{"xxxThis is the time for all good men to come to the aid of their country..."}

	u := stu(q)
	h1 := jenkins.HashWordsLen(u, (len(q)-1)/4, 13)
	h2 := jenkins.HashWordsLen(u, (len(q)-5)/4, 13)
	h3 := jenkins.HashWordsLen(u, (len(q)-9)/4, 13)
	fmt.Printf("%08x, %08x, %08x\n", h1, h2, h3)

	b, c := uint32(0), uint32(0)
	c, b = jenkins.HashString("", c, b)
	fmt.Printf("%08x, %08x\n", c, b) // deadbeef deadbeef

	b, c = 0xdeadbeef, 0
	c, b = jenkins.HashString("", c, b)
	fmt.Printf("%08x, %08x\n", c, b) // bd5b7dde deadbeef

	b, c = 0xdeadbeef, 0xdeadbeef
	c, b = jenkins.HashString("", c, b)
	fmt.Printf("%08x, %08x\n", c, b) // 9c093ccd bd5b7dde

	b, c = 0, 0
	c, b = jenkins.HashString("Four score and seven years ago", c, b)
	fmt.Printf("%08x, %08x\n", c, b) // 17770551 ce7226e6

	b, c = 1, 0
	c, b = jenkins.HashString("Four score and seven years ago", c, b)
	fmt.Printf("%08x, %08x\n", c, b) // e3607cae bd371de4

	b, c = 0, 1
	c, b = jenkins.HashString("Four score and seven years ago", c, b)
	fmt.Printf("%08x, %08x\n", c, b) // cd628161 6cbea4b3

	driver2()
}
937228
func reverseUint32(v uint32) (x uint32) {
	x |= uint32(reverseLUT[byte(v>>0)]) << 24
	x |= uint32(reverseLUT[byte(v>>8)]) << 16
	x |= uint32(reverseLUT[byte(v>>16)]) << 8
	x |= uint32(reverseLUT[byte(v>>24)]) << 0
	return x
}
1365720
func (ar *AnsiReader) shortFunction(ident string, shift, ctrl, alt bool) string {
	code := "O"

	if shift {
		code += "1;2"
	} else if ctrl {
		code += "1;5"
	} else if alt {
		code += "1;3"
	}

	return code + ident
}
1324137
func hash(thread *Thread, _ *Builtin, args Tuple, kwargs []Tuple) (Value, error) {
	var x Value
	if err := UnpackPositionalArgs("hash", args, kwargs, 1, &x); err != nil {
		return nil, err
	}
	h, err := x.Hash()
	return MakeUint(uint(h)), err
}
270550
func (f *FlagClause) Short(name rune) *FlagClause {
	f.shorthand = name
	return f
}
440297
func Min3Uint64(a, b, c uint64) uint64 {
	min := a
	if b < min {
		min = b
	}
	if c < min {
		min = c
	}
	return min
}
487121
func Hash(key uint64, numBuckets int) int32 {

	var b int64 = -1
	var j int64

	for j < int64(numBuckets) {
		b = j
		key = key*2862933555777941757 + 1
		j = int64(float64(b+1) * (float64(int64(1)<<31) / float64((key>>33)+1)))
	}

	return int32(b)
}
519587
func fastHash(input []byte) string {
	h := fnv.New32a()
	h.Write([]byte(input))
	return fmt.Sprintf("%x", h.Sum32())
}
693799
func Sum32WithSeed(data []byte, seed uint32) uint32 {

	h1 := seed

	nblocks := len(data) / 4
	var p uintptr
	if len(data) > 0 {
		p = uintptr(unsafe.Pointer(&data[0]))
	}
	p1 := p + uintptr(4*nblocks)
	for ; p < p1; p += 4 {
		k1 := *(*uint32)(unsafe.Pointer(p))

		k1 *= c1_32
		k1 = bits.RotateLeft32(k1, 15)
		k1 *= c2_32

		h1 ^= k1
		h1 = bits.RotateLeft32(h1, 13)
		h1 = h1*4 + h1 + 0xe6546b64
	}

	tail := data[nblocks*4:]

	var k1 uint32
	switch len(tail) & 3 {
	case 3:
		k1 ^= uint32(tail[2]) << 16
		fallthrough
	case 2:
		k1 ^= uint32(tail[1]) << 8
		fallthrough
	case 1:
		k1 ^= uint32(tail[0])
		k1 *= c1_32
		k1 = bits.RotateLeft32(k1, 15)
		k1 *= c2_32
		h1 ^= k1
	}

	h1 ^= uint32(len(data))

	h1 ^= h1 >> 16
	h1 *= 0x85ebca6b
	h1 ^= h1 >> 13
	h1 *= 0xc2b2ae35
	h1 ^= h1 >> 16

	return h1
}
1052242
func XHashWords(k []uint32, length int, seed uint32) uint32 {
	var a, b, c uint32
	var rot = func(x, k uint32) uint32 {
		return x<<k | x>>(32-k)
	}
	var mix = func() {
		a -= c
		a ^= rot(c, 4)
		c += b
		b -= a
		b ^= rot(a, 6)
		a += c
		c -= b
		c ^= rot(b, 8)
		b += a
		a -= c
		a ^= rot(c, 16)
		c += b
		b -= a
		b ^= rot(a, 19)
		a += c
		c -= b
		c ^= rot(b, 4)
		b += a
	}
	var final = func() {
		c ^= b
		c -= rot(b, 14)
		a ^= c
		a -= rot(c, 11)
		b ^= a
		b -= rot(a, 25)
		c ^= b
		c -= rot(b, 16)
		a ^= c
		a -= rot(c, 4)
		b ^= a
		b -= rot(a, 14)
		c ^= b
		c -= rot(b, 24)
	}
	ul := uint32(len(k))
	a = 0xdeadbeef + ul<<2 + seed
	b, c = a, a

	i := 0
	//length := 0
	for length = len(k); length > 3; length -= 3 {
		a += k[i+0]
		b += k[i+1]
		c += k[i+2]
		mix()
		i += 3
	}

	switch length {
	case 3:
		c += k[i+2]
		fallthrough
	case 2:
		b += k[i+1]
		fallthrough
	case 1:
		a += k[i+0]
		final()
	case 0:
		break
	}
	return c
}
1057464
func (s Uint32Slice) Less(i, j int) bool {
	return s[i] < s[j]
}
1083803
func decodeHash(x uint32, p uint8) (uint32, uint8) {
	var r uint8
	if x&0x1 == 1 {
		r = uint8(sliceUint32(x, 6, 1))
	} else {
		r = uint8(bits.LeadingZeros32(sliceUint32(x, 31-p, 1) << (1 + p)))
	}
	return getIndex(x, p), r + 1

}
99770
func Zero(t TestingT, i interface{}, msgAndArgs ...interface{}) bool {
	if h, ok := t.(tHelper); ok {
		h.Helper()
	}
	if i != nil && !reflect.DeepEqual(i, reflect.Zero(reflect.TypeOf(i)).Interface()) {
		return Fail(t, fmt.Sprintf("Should be zero, but was %v", i), msgAndArgs...)
	}
	return true
}
290047
func PutUint32(b []byte, v uint32) {
	if l := len(b); l != 4 {
		panic(fmt.Sprintf("PutUint32: unexpected byte slice length: %d", l))
	}

	*(*uint32)(unsafe.Pointer(&b[0])) = v
}
460378
func (pTypeDef *Test) Init() *Test {
	if pTypeDef.My_int_array == nil {
		pTypeDef.My_int_array = make([]int32, 0)
	}
	if pTypeDef.My_str_array == nil {
		pTypeDef.My_str_array = make([]string, 0)
	}
	if pTypeDef.Symtest == nil {
		pTypeDef.Symtest = NewSymTest()
	}
	return pTypeDef
}
367938
func (g *Group) Uint32() *Statement {
	// notest
	s := Uint32()
	g.items = append(g.items, s)
	return s
}
61390
func Hashf(k []byte, seed uint64) uint64 {
	/*
		_, ok := HashFunctions[Hf2]
		if !ok {
			fmt.Printf("%q not found\n", Hf2)
			panic("hashf")
		}
	*/
	switch Hf2 {
	case "nullhash":
		nh.Reset()
		nh.Write(k)
		h := nh.Sum64()
		return h
	case "nullhashF64ns":
		h := nhf64.Hash64S(k, 0)
		return h
	case "gomap64":
		h := gomap.Hash64(k, uint64(seed))
		return h
	case "gomap32":
		h := gomap.Hash32(k, uint32(seed))
		return uint64(h)
	case "aeshash64":
		h := aeshash.Hash(k, seed)
		return h
	case "adler32":
		a32.Reset()
		a32.Write(k)
		h := a32.Sum32()
		//fmt.Printf("a32 hash=0x%08x\n", h)
		return uint64(h)
	case "sbox":
		h := sbox.Sbox(k, uint32(seed))
		return uint64(h)
	case "CrapWow":
		h := crapwow.CrapWow(k, uint32(seed))
		//fmt.Printf("key=%q, hash=0x%08x\n", string(k), hash)
		return uint64(h)
	case "MaHash8v64":
		h64 := mahash.MaHash8v64(k)
		return h64
	case "j364":
		c, b := jenkins.Jenkins364(k, len(k), uint32(seed), uint32(seed))
		return uint64(b)<<32 | uint64(c)
	case "j332c":
		c, _ := jenkins.Jenkins364(k, len(k), uint32(seed), uint32(seed))
		return uint64(c)
	case "j332b":
		_, b := jenkins.Jenkins364(k, len(k), uint32(seed), uint32(seed))
		return uint64(b)
	case "j232":
		h := jenkins.Hash232(k, uint32(seed))
		return uint64(h)
	case "j264":
		h := jenkins.Hash264(k, seed)
		return h
	case "j264l":
		h := jenkins.Hash264(k, seed)
		return uint64(h & 0xFFFFFFFF)
	case "j264h":
		h := jenkins.Hash264(k, seed)
		return uint64((h >> 32) & 0xFFFFFFFF)
	case "j264xor":
		h := jenkins.Hash264(k, seed)
		return uint64(uint32(h&0xFFFFFFFF) ^ uint32((h>>32)&0xFFFFFFFF))
	case "spooky32":
		return uint64(spooky.Hash32(k, uint32(seed)))
	case "spooky64":
		return spooky.Hash64(k, seed)
	case "spooky128h":
		h, _ := spooky.Hash128(k, seed)
		return h
	case "spooky128l":
		_, l := spooky.Hash128(k, seed)
		return l
	case "spooky128xor":
		h, l := spooky.Hash128(k, seed)
		return h ^ l
	case "murmur332":
		m332.Reset()
		m332.Write(k)
		h := m332.Sum32()
		return uint64(h)
	case "murmur364":
		m364.Reset()
		m364.Write(k)
		h := m364.Sum64()
		return h
	case "siphash64":
		h := siphash.Hash(0, 0, k)
		return h
	case "siphash64pg":
		sipSeedSet(seed)
		a, _ := siphashpg.Siphash(k, seeds, siphashpg.Crounds, siphashpg.Drounds, false)
		return a

	case "FarmHash32":
		h := farm.Fingerprint32(k)
		return uint64(h & 0xFFFFFFFF)
	case "FarmHash64":
		h := farm.Fingerprint64(k)
		return h
	case "FarmHash128-high":
		h, _ := farm.Fingerprint128(k)
		return h
	case "FarmHash128-low":
		_, l := farm.Fingerprint128(k)
		return l
	case "FarmHash128-xor":
		h, l := farm.Fingerprint128(k)
		return h ^ l

	case "MetroHash64-1":
		h := metro.Hash64_1(k, uint32(seed))
		return h
	case "MetroHash64-2":
		h := metro.Hash64_2(k, uint32(seed))
		return h

	case "MetroHash128-1h":
		h, _ := metro.Hash128_1(k, uint32(seed))
		return h
	case "MetroHash128-1l":
		_, l := metro.Hash128_1(k, uint32(seed))
		return l
	case "MetroHash128-1xor":
		h, l := metro.Hash128_1(k, uint32(seed))
		return h ^ l

	case "MetroHash128-2h":
		h, _ := metro.Hash128_2(k, uint32(seed))
		return h
	case "MetroHash128-2l":
		_, l := metro.Hash128_2(k, uint32(seed))
		return l
	case "MetroHash128-2xor":
		h, l := metro.Hash128_2(k, uint32(seed))
		return h ^ l

		/*
			case "siphash64":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, false)
				return a
			case "siphash128a":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return a
			case "siphash128b":
				sipSeedSet(seed)
				_, b := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return b
			case "siphash64al":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, false)
				return uint64(a&0xFFFFFFFF)
			case "siphash64ah":
				sipSeedSet(seed)
				a, _ := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, false)
				return uint64((a>>32)&0xFFFFFFFF)
			case "siphash64bl":
				sipSeedSet(seed)
				_, b := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return uint64(b&0xFFFFFFFF)
			case "siphash64bh":
				sipSeedSet(seed)
				_, b := siphash.Siphash(k, seeds, siphash.Crounds, siphash.Drounds, true)
				return uint64((b>>32)&0xFFFFFFFF)
		*/
	case "keccak224":
		fp28 = fp28[0:0]
		k224.Reset()
		//fmt.Printf("len(k)=%d\n", k)
		k224.Write(k)
		fp28 = k224.Sum(fp28) // crashes 		fp8 = k224.Sum(fp28)
		//fmt.Printf("len(k)=%d, k=%#X, fp=%#x\n", len(k), k, fp28)
		//fmt.Printf("len(fp28)=%d\n", fp28)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp28[0])<<56 | uint64(fp28[1])<<48 | uint64(fp28[2])<<40 | uint64(fp28[3])<<32 | uint64(fp28[4])<<24 | uint64(fp28[5])<<16 | uint64(fp28[6])<<8 | uint64(fp28[7])<<0
	case "keccakpg643":
		fp8 = fp8[0:0]
		k643.Reset()
		k643.Write(k)
		fp8 = k643.Sum(fp8)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp8[0])<<56 | uint64(fp8[1])<<48 | uint64(fp8[2])<<40 | uint64(fp8[3])<<32 | uint64(fp8[4])<<24 | uint64(fp8[5])<<16 | uint64(fp8[6])<<8 | uint64(fp8[7])<<0
	case "keccakpg644":
		fp := make([]byte, 8, 8)
		fp = fp[0:0]
		k644.Reset()
		k644.Write(k)
		fp = k644.Sum(fp)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
	case "keccakpg648":
		fp := make([]byte, 8, 8)
		fp = fp[0:0]
		k648.Reset()
		k648.Write(k)
		fp = k648.Sum(fp)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
	case "keccakpg160":
		fp := make([]byte, 32)
		fp = fp[0:0]
		k160.Reset()
		k160.Write(k)
		fp = k160.Sum(fp)
		//fmt.Printf("keccak160xor: fp=%v\n", fp)
		if false {
			low := fp[0] ^ fp[4] ^ fp[8] ^ fp[12] ^ fp[16]
			med := fp[1] ^ fp[5] ^ fp[9] ^ fp[13] ^ fp[17]
			hii := fp[2] ^ fp[6] ^ fp[10] ^ fp[14] ^ fp[18]
			top := fp[3] ^ fp[7] ^ fp[11] ^ fp[15] ^ fp[19]
			return uint64(uint32(top)<<24 | uint32(hii)<<16 | uint32(med)<<8 | uint32(low))
		} else {
			return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
		}
	case "skein256xor":
		fp := make([]byte, 32)
		fp = fp[0:0]
		skein256.Reset()
		skein256.Write(k)
		fp = skein256.Sum(fp)
		//fmt.Printf("skein256: fp=%v\n", fp)
		if true {
			low := fp[0] ^ fp[4] ^ fp[8] ^ fp[12] ^ fp[16]
			med := fp[1] ^ fp[5] ^ fp[9] ^ fp[13] ^ fp[17]
			hii := fp[2] ^ fp[6] ^ fp[10] ^ fp[14] ^ fp[18]
			top := fp[3] ^ fp[7] ^ fp[11] ^ fp[15] ^ fp[19]
			return uint64(uint32(top)<<24 | uint32(hii)<<16 | uint32(med)<<8 | uint32(low))
		} else {
			return uint64(uint32(fp[0])<<24 | uint32(fp[1])<<16 | uint32(fp[2])<<8 | uint32(fp[3]))
		}
	case "skein256":
		fp := make([]byte, 32)
		fp = fp[0:0]
		skein256.Reset()
		skein256.Write(k)
		fp = skein256.Sum(fp)
		//fmt.Printf("skein256: fp=%v\n", fp)
		return uint64(fp[0])<<56 | uint64(fp[1])<<48 | uint64(fp[2])<<40 | uint64(fp[3])<<32 | uint64(fp[4])<<24 | uint64(fp[5])<<16 | uint64(fp[6])<<8 | uint64(fp[7])<<0
	case "skein256hi":
		fp := make([]byte, 32)
		fp = fp[0:0]
		skein256.Reset()
		skein256.Write(k)
		fp = skein256.Sum(fp)
		//fmt.Printf("skein256: fp=%v\n", fp)
		return uint64(uint32(fp[28])<<24 | uint32(fp[29])<<16 | uint32(fp[30])<<8 | uint32(fp[31]))
	case "sha1":
		//fp := make([]byte, 20)
		//fp = fp[0:0]
		sha1160.Reset()
		sha1160.Write(k)
		fp20 = fp20[0:0]
		fp20 = sha1160.Sum(fp20)
		if false {
			low := fp20[0] ^ fp20[4] ^ fp20[8] ^ fp20[12] ^ fp20[16]
			med := fp20[1] ^ fp20[5] ^ fp20[9] ^ fp20[13] ^ fp20[17]
			hii := fp20[2] ^ fp20[6] ^ fp20[10] ^ fp20[14] ^ fp20[18]
			top := fp20[3] ^ fp20[7] ^ fp20[11] ^ fp20[15] ^ fp20[19]
			return uint64(uint32(top)<<24 | uint32(hii)<<16 | uint32(med)<<8 | uint32(low))
		} else {
			return uint64(fp20[0])<<56 | uint64(fp20[1])<<48 | uint64(fp20[2])<<40 | uint64(fp20[3])<<32 | uint64(fp20[4])<<24 | uint64(fp20[5])<<16 | uint64(fp20[6])<<8 | uint64(fp20[7])<<0
		}
	default:
		fmt.Printf("hf=%q\n", Hf2)
		panic("hashf")
	}
	return 0
}