// ReadPads reads 0-7 bits from the bit buffer to achieve byte-alignment.
432022
func (br *bitReader) ReadPads() uint {
	nb := br.numBits % 8
	val := uint(br.bufBits & uint64(1<<nb-1))
	br.bufBits >>= nb
	br.numBits -= nb
	return val
}
125774
func (b *bitReader) getBits(n uint8) uint16 {
	if n == 0 || b.bitsRead >= 64 {
		return 0
	}
	return b.getBitsFast(n)
}
776744
func (pw *Writer) WritePads(v uint) {
	nb := -pw.numBits & 7
	pw.bufBits |= uint64(v) << pw.numBits
	pw.numBits += nb
}
1229908
func leftPad(input []byte, size int) (out []byte) {
	n := len(input)
	if n > size {
		n = size
	}
	out = make([]byte, size)
	copy(out[len(out)-n:], input)
	return
}
569126
func (rwops *RWops) ReadBE32() uint32 {
	if rwops == nil {
		return 0
	}
	return uint32(C.SDL_ReadBE32(rwops.cptr()))
}
267263
func (e *Encoding) pad(s string, minlen int) string {
	if len(s) >= minlen {
		return s
	}

	format := fmt.Sprint(`%0`, strconv.Itoa(minlen), "s")
	return fmt.Sprintf(format, s)
}
129124
func (rd *reservoirReader) readBits(n int) (int, error) {
	if n <= 0 {
		return 0, nil
	}

	retval, bits := 0, rd.bits
	for {
		if bits == 0 {
			if rd.head == rd.limit {
				return 0, MalformedStream("reservoir overread")
			}
			bits, rd.current = 8, rd.buffer[rd.head]
			rd.head++
		}

		if n <= bits {
			retval <<= uint(n)
			retval |= int(rd.current >> uint(8-n))
			rd.current <<= uint(n)
			bits -= n
			rd.bits = bits
			return retval, nil
		} else {
			retval <<= uint(bits)
			retval |= int(rd.current >> uint(8-bits))
			n -= bits
			bits = 0
		}
	}
}
413415
func oneTimePad(data, key []byte) {
	n := len(data)
	if n != len(key) {
		panic("Lengths of slices are not equal")
	}

	for i := 0; i < n; i++ {
		data[i] ^= key[i]
	}
}
812916
func (br *bitReader) ReadOffset(sym uint, rcs []rangeCode) uint {
	rc := rcs[sym]
	return uint(rc.base) + br.ReadBits(uint(rc.bits))
}
1007230
func readBytes(r io.Reader) ([]byte, error) {
	length, err := readInt32(r)
	if err != nil {
		return nil, err
	}
	buf := make([]byte, length)
	_, err = io.ReadFull(r, buf)
	if err != nil {
		return nil, err
	}
	return buf, nil
}
1232729
func pad(q, p []byte, k int) int {
	n := len(p)/k*k + k
	copy(q, p)
	c := byte(n - len(p))
	for i := len(p); i < n; i++ {
		q[i] = c
	}
	return n
}
87327
func (b *ByteBuf) ReadMarkedBytes() (int, []byte, error) {
	return b.ReadBytes(b.GetMarkedRemind())
}
1249558
func (r *SplicedMemory) ReadMemory(buf []byte, addr uintptr) (n int, err error) {
	started := false
	for _, entry := range r.readers {
		if entry.offset+entry.length < addr {
			if !started {
				continue
			}
			return n, fmt.Errorf("hit unmapped area at %v after %v bytes", addr, n)
		}

		// Don't go past the region.
		pb := buf
		if addr+uintptr(len(buf)) > entry.offset+entry.length {
			pb = pb[:entry.offset+entry.length-addr]
		}
		pn, err := entry.reader.ReadMemory(pb, addr)
		n += pn
		if err != nil || pn != len(pb) {
			return n, err
		}
		buf = buf[pn:]
		addr += uintptr(pn)
		if len(buf) == 0 {
			// Done, don't bother scanning the rest.
			return n, nil
		}
	}
	if n == 0 {
		return 0, fmt.Errorf("offset %v did not match any regions", addr)
	}
	return n, nil
}
879464
func (b *Buffer) Read32() uint32 {
	v, ok := b.consume(4)
	if !ok {
		return 0
	}
	return order.Uint32(v)
}
1354138
func (delimited *Delimited) ReadNS(key string) golhashmap.HashMap {
	var hmap golhashmap.HashMap
	hmap = make(golhashmap.HashMap)
	key = "key::" + key
	val := delimited.db.GetVal(key)
	if val == "" {
		return hmap
	}
	children := strings.Split(val, ",")
	for _, child := range children {

		childKey := strings.Split(child, "key::")[1]
		childVal := delimited.db.GetVal("val::" + childKey)
		if childVal != "" {
			hmap[childKey] = childVal
		}
	}
	return hmap
}
1345040
func (pr *Reader) BitsRead() int64 {
	offset := 8*pr.Offset - int64(pr.numBits)
	if pr.bufRd != nil {
		discardBits := pr.discardBits + int(pr.fedBits-pr.numBits)
		offset = 8*pr.Offset + int64(discardBits)
	}
	return offset
}
66860
func readBytes(dst []byte, r io.Reader) error {
	offset := 0
	remaining := len(dst)
	if remaining == 0 {
		// Nothing left to read
		return nil
	}
	for {
		n, err := r.Read(dst[offset:])
		offset += n
		remaining -= n
		if remaining == 0 {
			return nil
		}
		if err != nil {
			return err
		}
	}
}