code: def replace_all(
      buffer: Sequence[int],
      replacements: Iterable[Tuple[int, int, Sequence[int]]],
  ) -> bytes:
      """Substitute multiple replacement values into a buffer.
  
      Replacements is a list of (start, end, value) triples.
      """
  
      result = bytearray()
      prev = 0
      offset = 0
      for u, v, r in replacements:
          result.extend(buffer[prev:u])
          result.extend(r)
          prev = v
          offset += len(r) - (v - u)
      result.extend(buffer[prev:])
      assert len(result) == len(buffer) + offset
      return bytes(result)
  
imports: import array
  import sys
  import warnings
  from random import Random
  from typing import Callable, Dict, Generic, Iterable, Iterator, List, Optional, Sequence, Tuple, TypeVar, Union, overload
  from hypothesis.errors import HypothesisWarning
label_desc: Use image node_id 2 for calling a global function with example usage: replace_all(buffer, replacements) and returns: bytes