code: def main(infile, outfile, level, jobs=1):
      """Entry point for direct optimization of a file."""
      from shutil import copy  # pylint: disable=import-outside-toplevel
      from tempfile import (
          TemporaryDirectory,
      )  # pylint: disable=import-outside-toplevel
  
      class OptimizeOptions:
          """Emulate ocrmypdf's options."""
  
          def __init__(
              self,
              input_file,
              jobs,
              optimize_,
              jpeg_quality,
              png_quality,
              jb2lossy,
          ):
              self.input_file = input_file
              self.jobs = jobs
              self.optimize = optimize_
              self.jpeg_quality = jpeg_quality
              self.png_quality = png_quality
              self.jbig2_page_group_size = 0
              self.jbig2_lossy = jb2lossy
              self.jbig2_threshold = 0.85
              self.quiet = True
              self.progress_bar = False
  
      infile = Path(infile)
      options = OptimizeOptions(
          input_file=infile,
          jobs=jobs,
          optimize_=int(level),
          jpeg_quality=0,  # Use default
          png_quality=0,
          jb2lossy=False,
      )
  
      with TemporaryDirectory() as tmpdir:
          context = PdfContext(options, tmpdir, infile, None, None)
          tmpout = Path(tmpdir) / "out.pdf"
          optimize(
              infile,
              tmpout,
              context,
              dict(
                  compress_streams=True,
                  preserve_pdfa=True,
                  object_stream_mode=ObjectStreamMode.generate,
              ),
          )
          copy(fspath(tmpout), fspath(outfile))
  
imports: from __future__ import annotations
  import logging
  import sys
  import tempfile
  import threading
  from collections import defaultdict
  from collections.abc import Iterator, MutableSet, Sequence
  from os import fspath
  from pathlib import Path
  from typing import Any, Callable, NamedTuple, NewType
  from warnings import warn
  from zlib import compress
  import img2pdf
  from pikepdf import Dictionary, Name, Object, ObjectStreamMode, Pdf, PdfError, PdfImage, Stream, UnsupportedImageTypeError
  from PIL import Image
  from ocrmypdf._concurrent import Executor, SerialExecutor
  from ocrmypdf._exec import jbig2enc, pngquant
  from ocrmypdf._jobcontext import PdfContext
  from ocrmypdf._progressbar import ProgressBar
  from ocrmypdf.exceptions import OutputFileAccessError
  from ocrmypdf.helpers import IMG2PDF_KWARGS, safe_symlink
label_desc: Use image node_id 22 for calling a global function with example usage: main(infile, outfile, level, jobs) without return types