// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package fuzz

import (
	
)

func isMinimizable( reflect.Type) bool {
	return  == reflect.TypeOf("") ||  == reflect.TypeOf([]byte(nil))
}

func minimizeBytes( []byte,  func([]byte) bool,  func() bool) {
	 := make([]byte, len())
	// If minimization was successful at any point during minimizeBytes,
	// then the vals slice in (*workerServer).minimizeInput will point to
	// tmp. Since tmp is altered while making new candidates, we need to
	// make sure that it is equal to the correct value, v, before exiting
	// this function.
	defer copy(, )

	// First, try to cut the tail.
	for  := 1024;  != 0;  /= 2 {
		for len() >  {
			if () {
				return
			}
			 := [:len()-]
			if !() {
				break
			}
			// Set v to the new value to continue iterating.
			 = 
		}
	}

	// Then, try to remove each individual byte.
	for  := 0;  < len()-1; ++ {
		if () {
			return
		}
		 := [:len()-1]
		copy([:], [:])
		copy([:], [+1:])
		if !() {
			continue
		}
		// Update v to delete the value at index i.
		copy([:], [+1:])
		 = [:len()]
		// v[i] is now different, so decrement i to redo this iteration
		// of the loop with the new value.
		--
	}

	// Then, try to remove each possible subset of bytes.
	for  := 0;  < len()-1; ++ {
		copy(, [:])
		for  := len();  > +1; -- {
			if () {
				return
			}
			 := [:len()-+]
			copy([:], [:])
			if !() {
				continue
			}
			// Update v and reset the loop with the new length.
			copy([:], [:])
			 = [:len()]
			 = len()
		}
	}

	// Then, try to make it more simplified and human-readable by trying to replace each
	// byte with a printable character.
	 := []byte("012789ABCXYZabcxyz !\"#$%&'()*+,.")
	for ,  := range  {
		if () {
			return
		}

		for ,  := range  {
			[] = 
			if () {
				// Successful. Move on to the next byte in v.
				break
			}
			// Unsuccessful. Revert v[i] back to original value.
			[] = 
		}
	}
}