code: def optimize_pdf(
      input_pdf: Path,
      output_pdf: Path,
      context: PdfContext,
      executor: Executor,
      linearize: bool,
  ) -> tuple[Path, Sequence[str]]:
      save_settings = dict(
          linearize=linearize,
          **get_pdf_save_settings(context.options.output_type),
      )
      result_path = optimize(
          input_pdf, output_pdf, context, save_settings, executor
      )
      messages = []
      if context.options.optimize == 0:
          messages.append("Optimization was disabled.")
      else:
          image_optimizers = {
              "jbig2": jbig2enc.available(),
              "pngquant": pngquant.available(),
          }
          for name, available in image_optimizers.items():
              if not available:
                  messages.append(
                      f"The optional dependency '{name}' was not found, so some image "
                      f"optimizations could not be attempted."
                  )
      return result_path, messages
  
file_path: OCRmyPDF/src/ocrmypdf/builtin_plugins/optimize.py
imports: from __future__ import annotations
  import argparse
  import logging
  from collections.abc import Sequence
  from pathlib import Path
  from ocrmypdf import Executor, PdfContext, hookimpl
  from ocrmypdf._exec import jbig2enc, pngquant
  from ocrmypdf._pipeline import get_pdf_save_settings
  from ocrmypdf.cli import numeric
  from ocrmypdf.optimize import optimize
  from ocrmypdf.subprocess import check_external_program
label_desc: Use image node_id 3 for calling a global function with example usage: optimize_pdf(input_pdf, output_pdf, context, executor, linearize) and returns: result_path,  messages