code: def merge_ranges(
      range_list1, range_list2, is_sorted=False
  ):  # noqa:C901
      merged_ranges = []
      if not is_sorted:
          range_list1 = merge_self_ranges(range_list1)
          range_list2 = merge_self_ranges(range_list2)
      len1 = len(range_list1)
      len2 = len(range_list2)
      if len1 == 0 and len2 == 0:
          return merged_ranges
      elif len1 == 0:
          return range_list2
      elif len2 == 0:
          return range_list1
      else:
          indx1 = 0
          indx2 = 0
          range1 = range_list1[indx1]
          range2 = range_list2[indx2]
          if range1[0] < range2[0]:
              merged_ranges.append(range1)
              indx1 += 1
          else:
              merged_ranges.append(range2)
              indx2 += 1
          while indx1 < len1 and indx2 < len2:
              range1 = range_list1[indx1]
              range2 = range_list2[indx2]
              if range1[0] < range2[0]:
                  if range1[1] > merged_ranges[-1][1]:
                      if range1[0] <= merged_ranges[-1][1]:
                          merged_ranges[-1] = (
                              merged_ranges[-1][0],
                              range1[1],
                          )
                      else:
                          merged_ranges.append((range1[0], range1[1]))
                      indx1 += 1
                  else:
                      indx1 += 1
              else:
                  if range2[1] > merged_ranges[-1][1]:
                      if range2[0] <= merged_ranges[-1][1]:
                          merged_ranges[-1] = (
                              merged_ranges[-1][0],
                              range2[1],
                          )
                      else:
                          merged_ranges.append((range2[0], range2[1]))
                      indx2 += 1
                  else:
                      indx2 += 1
  
          while indx1 < len1:
              range1 = range_list1[indx1]
              if range1[1] > merged_ranges[-1][1]:
                  if range1[0] <= merged_ranges[-1][1]:
                      merged_ranges[-1] = (
                          merged_ranges[-1][0],
                          range1[1],
                      )
                  else:
                      merged_ranges.append((range1[0], range1[1]))
                  indx1 += 1
              else:
                  indx1 += 1
          while indx2 < len2:
              range2 = range_list2[indx2]
              if range2[1] > merged_ranges[-1][1]:
                  if range2[0] <= merged_ranges[-1][1]:
                      merged_ranges[-1] = (
                          merged_ranges[-1][0],
                          range2[1],
                      )
                  else:
                      merged_ranges.append((range2[0], range2[1]))
                  indx2 += 1
              else:
                  indx2 += 1
      return merged_ranges
  
imports: import collections
  import os
  import sys
label_desc: Use image node_id 3 for calling a global function with example usage: merge_ranges(range_list1, range_list2, is_sorted) and returns: merged_ranges, merged_ranges, range_list2, range_list1