// assembleBpfInsn assembles a slice of bpf.RawInstructions to the format required by
// package syscall.
178741
func assembleBpfInsn(filter []bpf.RawInstruction) []syscall.BpfInsn {
	// Copy each bpf.RawInstruction into syscall.BpfInsn.  If needed,
	// the structures have the same memory layout and could probably be
	// unsafely cast to each other for speed.
	insns := make([]syscall.BpfInsn, 0, len(filter))
	for _, ins := range filter {
		insns = append(insns, syscall.BpfInsn{
			Code: ins.Op,
			Jt:   ins.Jt,
			Jf:   ins.Jf,
			K:    ins.K,
		})
	}

	return insns
}
632997
func IndexN(str, sep string, n int) (index int) {
	index, idx, sepLen := 0, -1, len(sep)
	for i := 0; i < n; i++ {
		if idx = strings.Index(str, sep); idx == -1 {
			break
		}
		str = str[idx+sepLen:]
		index += idx
	}

	if idx == -1 {
		index = -1
	} else {
		index += (n - 1) * sepLen
	}

	return
}
378732
func (p *parser) peekn(n int) ([]token, error) {
	if len(p.buf) > n {
		return p.buf[:n], nil
	}
	for i := len(p.buf) - 1; i < n; i++ {
		t := p.lexer.token()
		p.buf = append(p.buf, t)
		if t.typ == tokenEOF {
			return p.buf, io.EOF
		}
	}
	return p.buf, nil
}
1127279
func NodeFromNodePb(n *NodePb) Node {
	if n == nil {
		return nil
	}
	switch {
	case n.Bn != nil:
		var bn *BinaryNode
		return bn.FromPB(n)
	case n.Booln != nil:
		var bn *BooleanNode
		return bn.FromPB(n)
	case n.Un != nil:
		var un *UnaryNode
		return un.FromPB(n)
	case n.Fn != nil:
		var fn *FuncNode
		return fn.FromPB(n)
	case n.Tn != nil:
		var tn *TriNode
		return tn.FromPB(n)
	case n.An != nil:
		var an *ArrayNode
		return an.FromPB(n)
	case n.Nn != nil:
		var nn *NumberNode
		return nn.FromPB(n)
	case n.Vn != nil:
		var vn *ValueNode
		return vn.FromPB(n)
	case n.In != nil:
		var in *IdentityNode
		return in.FromPB(n)
	case n.Sn != nil:
		var sn *StringNode
		return sn.FromPB(n)
	case n.Incn != nil:
		var in *IncludeNode
		return in.FromPB(n)
	case n.Niln != nil:
		return &NullNode{}
	}
	return nil
}
1231376
func (a *ArgType) BuildIndexFuncName(ixTpl *Index) {
	// build func name
	funcName := ixTpl.Type.Name
	if !ixTpl.Index.IsUnique {
		funcName = inflector.Pluralize(ixTpl.Type.Name)
	}
	funcName = funcName + "By"

	// add param names
	paramNames := []string{}

	ixName := fmtIndexName(ixTpl.Index.IndexName, ixTpl.Type.Table.TableName)
	if a.UseIndexNames && ixName != "" {
		paramNames = append(paramNames, ixName)
	} else {
		for _, f := range ixTpl.Fields {
			paramNames = append(paramNames, f.Name)
		}
	}

	// store resulting name back
	ixTpl.FuncName = funcName + strings.Join(paramNames, "")
}
322340
func (pcg *Pcg128x64) NextN(bounds uint64) uint64 {
  threshold := (0 - bounds) % bounds
  for {
    result := pcg.Next()
    if result >= threshold {
      return result % bounds;
    }
  }
}
138352
func Compile(ctx context.Context, src string, out string) error {
	debug := option.Config.BPFCompilationDebug
	prog := progInfo{
		Source:     src,
		Output:     out,
		OutputType: outputObject,
	}
	dirs := directoryInfo{
		Library: option.Config.BpfDir,
		Runtime: option.Config.StateDir,
		Output:  option.Config.StateDir,
		State:   option.Config.StateDir,
	}
	return compile(ctx, &prog, &dirs, debug)
}
349402
func BuildB3SingleHeader(traceID, spanID, sampling, flags, parentSpanID string) string {
	if traceID == "" || spanID == "" {
		return ""
	}

	if sampling == "" && flags == "" {
		return traceID + "-" + spanID
	}

	samplingBit := "0"
	if flags == "1" {
		samplingBit = "d"
	} else if s, err := strconv.ParseBool(sampling); err == nil {
		if s {
			samplingBit = "1"
		}
	} else {
		return traceID + "-" + spanID
	}

	if parentSpanID == "" {
		return traceID + "-" + spanID + "-" + samplingBit
	}

	return traceID + "-" + spanID + "-" + samplingBit + "-" + parentSpanID
}
908422
func sb3Inv(r0, r1, r2, r3 *uint32) {
	r4 := *r2
	*r2 ^= *r1
	*r0 ^= *r2
	r4 &= *r2
	r4 ^= *r0
	*r0 &= *r1
	*r1 ^= *r3
	*r3 |= r4
	*r2 ^= *r3
	*r0 ^= *r3
	*r1 ^= r4
	*r3 &= *r2
	*r3 ^= *r1
	*r1 ^= *r0
	*r1 |= *r2
	*r0 ^= *r3
	*r1 ^= r4
	*r0 ^= *r1
	//return *r2, *r1, *r3, *r0
	r4 = *r0
	*r0 = *r2
	*r2 = *r3
	*r3 = r4
}
1221835
func (b *Block) MakePartSet(partSize int) *PartSet {
	if b == nil {
		return nil
	}
	b.mtx.Lock()
	defer b.mtx.Unlock()

	// We prefix the byte length, so that unmarshaling
	// can easily happen via a reader.
	bz, err := cdc.MarshalBinaryLengthPrefixed(b)
	if err != nil {
		panic(err)
	}
	return NewPartSetFromData(bz, partSize)
}
150142
func NewBuiltin(name string, fn func(thread *Thread, fn *Builtin, args Tuple, kwargs []Tuple) (Value, error)) *Builtin {
	return &Builtin{name: name, fn: fn}
}
730715
func (s *stack) NipN(idx int32) error {
	_, err := s.nipN(idx)
	return err
}
1159716
func Assemble(opts Options) error {
	var err error

	debug("createDirectories")
	err = createDirectories(opts)
	if err != nil {
		return err
	}

	debug("writeMeshbluConfig")
	err = writeMeshbluConfig(opts)
	if err != nil {
		return err
	}

	debug("writeServiceConfig")
	err = writeServiceConfig(opts)
	if err != nil {
		return err
	}

	debug("installIgnition")
	err = installIgnition(opts)
	if err != nil {
		return err
	}

	debug("foreverize")
	err = foreverize(opts)
	if err != nil {
		return err
	}

	return nil
}
398252
func instPrefix(b byte, mode int) (Inst, error) {
	// When tracing it is useful to see what called instPrefix to report an error.
	if trace {
		_, file, line, _ := runtime.Caller(1)
		fmt.Printf("%s:%d\n", file, line)
	}
	p := Prefix(b)
	switch p {
	case PrefixDataSize:
		if mode == 16 {
			p = PrefixData32
		} else {
			p = PrefixData16
		}
	case PrefixAddrSize:
		if mode == 32 {
			p = PrefixAddr16
		} else {
			p = PrefixAddr32
		}
	}
	// Note: using composite literal with Prefix key confuses 'bundle' tool.
	inst := Inst{Len: 1}
	inst.Prefix = Prefixes{p}
	return inst, nil
}
173992
func BuildZipkinThrift(s *Span) *z.Span {
	span := &zipkinSpan{Span: s}
	span.handleSpecialTags()
	parentID := int64(span.context.parentID)
	var ptrParentID *int64
	if parentID != 0 {
		ptrParentID = &parentID
	}
	traceIDHigh := int64(span.context.traceID.High)
	var ptrTraceIDHigh *int64
	if traceIDHigh != 0 {
		ptrTraceIDHigh = &traceIDHigh
	}
	timestamp := utils.TimeToMicrosecondsSinceEpochInt64(span.startTime)
	duration := span.duration.Nanoseconds() / int64(time.Microsecond)
	endpoint := &z.Endpoint{
		ServiceName: span.tracer.serviceName,
		Ipv4:        int32(span.tracer.hostIPv4)}
	thriftSpan := &z.Span{
		TraceID:           int64(span.context.traceID.Low),
		TraceIDHigh:       ptrTraceIDHigh,
		ID:                int64(span.context.spanID),
		ParentID:          ptrParentID,
		Name:              span.operationName,
		Timestamp:         &timestamp,
		Duration:          &duration,
		Debug:             span.context.IsDebug(),
		Annotations:       buildAnnotations(span, endpoint),
		BinaryAnnotations: buildBinaryAnnotations(span, endpoint)}
	return thriftSpan
}
717466
func bpfCompileProg(src string, dst string) error {
	ctx, cancel := context.WithTimeout(context.Background(), contextTimeout)
	defer cancel()

	srcpath := filepath.Join("sockops", src)
	outpath := filepath.Join(dst)

	err := loader.Compile(ctx, srcpath, outpath)
	if err != nil {
		return fmt.Errorf("failed compile %s: %s", srcpath, err)
	}
	return nil
}
1064285
func setBPFDirection(fd int, direction int) error {
	var dirfilt uint

	switch direction {
	case bpfDIn:
		// filter outbound
		dirfilt = syscall.BPF_DIRECTION_OUT
	default:
		// no filter
	}

	_, _, err := syscall.Syscall(
		syscall.SYS_IOCTL,
		uintptr(fd),
		syscall.BIOCSDIRFILT,
		uintptr(unsafe.Pointer(&dirfilt)),
	)
	if err != 0 {
		return syscall.Errno(err)
	}

	return nil
}