code: def sort_labeled_intervals(intervals, labels=None):
      '''Sort intervals, and optionally, their corresponding labels
      according to start time.
      Parameters
      ----------
      intervals : np.ndarray, shape=(n, 2)
          The input intervals
      labels : list, optional
          Labels for each interval
      Returns
      -------
      intervals_sorted or (intervals_sorted, labels_sorted)
          Labels are only returned if provided as input
      '''
      idx = np.argsort(intervals[:, 0])
      intervals_sorted = intervals[idx]
      if labels is None:
          return intervals_sorted
      else:
          return intervals_sorted, [labels[_] for _ in idx]