package binary

import (
	
	
	
	

	
	
)

func decodeCode( *bytes.Reader,  uint64,  *wasm.Code) ( error) {
	, ,  := leb128.DecodeUint32()
	if  != nil {
		return fmt.Errorf("get the size of code: %w", )
	}
	 := int64()

	// Parse #locals.
	, ,  := leb128.DecodeUint32()
	 -= int64()
	if  != nil {
		return fmt.Errorf("get the size locals: %v", )
	} else if  < 0 {
		return io.EOF
	}

	// Validate the locals.
	 = 0
	var  uint64
	for  := uint32(0);  < ; ++ {
		, ,  := leb128.DecodeUint32()
		if  != nil {
			return fmt.Errorf("read n of locals: %v", )
		} else if  < 0 {
			return io.EOF
		}

		 += uint64()

		,  := .ReadByte()
		if  != nil {
			return fmt.Errorf("read type of local: %v", )
		}

		 +=  + 1
		switch  := ;  {
		case wasm.ValueTypeI32, wasm.ValueTypeF32, wasm.ValueTypeI64, wasm.ValueTypeF64,
			wasm.ValueTypeFuncref, wasm.ValueTypeExternref, wasm.ValueTypeV128:
		default:
			return fmt.Errorf("invalid local type: 0x%x", )
		}
	}

	if  > math.MaxUint32 {
		return fmt.Errorf("too many locals: %d", )
	}

	// Rewind the buffer.
	_,  = .Seek(-int64(), io.SeekCurrent)
	if  != nil {
		return 
	}

	 := make([]wasm.ValueType, 0, )
	for  := uint32(0);  < ; ++ {
		, ,  := leb128.DecodeUint32()
		 -= int64() + 1 // +1 for the subsequent ReadByte
		if  != nil {
			return fmt.Errorf("read n of locals: %v", )
		} else if  < 0 {
			return io.EOF
		}

		,  := .ReadByte()
		if  != nil {
			return fmt.Errorf("read type of local: %v", )
		}

		for  := uint32(0);  < ; ++ {
			 = append(, )
		}
	}

	 :=  - uint64(.Len())
	 := make([]byte, )
	if _,  = io.ReadFull(, );  != nil {
		return fmt.Errorf("read body: %w", )
	}

	if  := len() - 1;  < 0 || [] != wasm.OpcodeEnd {
		return fmt.Errorf("expr not end with OpcodeEnd")
	}

	.BodyOffsetInCodeSection = 
	.LocalTypes = 
	.Body = 
	return nil
}