code: def checked_add_with_arr(
      arr: npt.NDArray[np.int64],
      b: int | npt.NDArray[np.int64],
      arr_mask: npt.NDArray[np.bool_] | None = None,
      b_mask: npt.NDArray[np.bool_] | None = None,
  ) -> npt.NDArray[np.int64]:
      """
      Perform array addition that checks for underflow and overflow.
  
      Performs the addition of an int64 array and an int64 integer (or array)
      but checks that they do not result in overflow first. For elements that
      are indicated to be NaN, whether or not there is overflow for that element
      is automatically ignored.
  
      Parameters
      ----------
      arr : np.ndarray[int64] addend.
      b : array or scalar addend.
      arr_mask : np.ndarray[bool] or None, default None
          array indicating which elements to exclude from checking
      b_mask : np.ndarray[bool] or None, default None
          array or scalar indicating which element(s) to exclude from checking
  
      Returns
      -------
      sum : An array for elements x + b for each element x in arr if b is
            a scalar or an array for elements x + y for each element pair
            (x, y) in (arr, b).
  
      Raises
      ------
      OverflowError if any x + y exceeds the maximum or minimum int64 value.
      """
      # For performance reasons, we broadcast 'b' to the new array 'b2'
      # so that it has the same size as 'arr'.
      b2 = np.broadcast_to(b, arr.shape)
      if b_mask is not None:
          # We do the same broadcasting for b_mask as well.
          b2_mask = np.broadcast_to(b_mask, arr.shape)
      else:
          b2_mask = None
  
      # For elements that are NaN, regardless of their value, we should
      # ignore whether they overflow or not when doing the checked add.
      if arr_mask is not None and b2_mask is not None:
          not_nan = np.logical_not(arr_mask | b2_mask)
      elif arr_mask is not None:
          not_nan = np.logical_not(arr_mask)
      elif b_mask is not None:
          # error: Argument 1 to "__call__" of "_UFunc_Nin1_Nout1" has
          # incompatible type "Optional[ndarray[Any, dtype[bool_]]]";
          # expected "Union[_SupportsArray[dtype[Any]], _NestedSequence
          # [_SupportsArray[dtype[Any]]], bool, int, float, complex, str
          # , bytes, _NestedSequence[Union[bool, int, float, complex, str
          # , bytes]]]"
          not_nan = np.logical_not(b2_mask)  # type: ignore[arg-type]
      else:
          not_nan = np.empty(arr.shape, dtype=bool)
          not_nan.fill(True)
  
      # gh-14324: For each element in 'arr' and its corresponding element
      # in 'b2', we check the sign of the element in 'b2'. If it is positive,
      # we then check whether its sum with the element in 'arr' exceeds
      # np.iinfo(np.int64).max. If so, we have an overflow error. If it
      # it is negative, we then check whether its sum with the element in
      # 'arr' exceeds np.iinfo(np.int64).min. If so, we have an overflow
      # error as well.
      i8max = lib.i8max
      i8min = iNaT
  
      mask1 = b2 > 0
      mask2 = b2 < 0
  
      if not mask1.any():
          to_raise = ((i8min - b2 > arr) & not_nan).any()
      elif not mask2.any():
          to_raise = ((i8max - b2 < arr) & not_nan).any()
      else:
          to_raise = (
              (i8max - b2[mask1] < arr[mask1]) & not_nan[mask1]
          ).any() or (
              (i8min - b2[mask2] > arr[mask2]) & not_nan[mask2]
          ).any()
  
      if to_raise:
          raise OverflowError("Overflow in int64 addition")
  
      result = arr + b
      if arr_mask is not None or b2_mask is not None:
          np.putmask(result, ~not_nan, iNaT)
  
      return result
  
imports: from __future__ import annotations
  import operator
  from textwrap import dedent
  from typing import TYPE_CHECKING, Literal, cast
  import warnings
  import numpy
  from pandas._libs import algos, hashtable, iNaT, lib
  from pandas._typing import AnyArrayLike, ArrayLike, AxisInt, DtypeObj, TakeIndexer, npt
  from pandas.util._decorators import doc
  from pandas.util._exceptions import find_stack_level
  from pandas.core.dtypes.cast import construct_1d_object_array_from_listlike, infer_dtype_from_array, np_find_common_type
  from pandas.core.dtypes.common import ensure_float64, ensure_object, ensure_platform_int, is_array_like, is_bool_dtype, is_categorical_dtype, is_complex_dtype, is_extension_array_dtype, is_float_dtype, is_integer, is_integer_dtype, is_list_like, is_numeric_dtype, is_object_dtype, is_scalar, is_signed_integer_dtype, needs_i8_conversion
  from pandas.core.dtypes.concat import concat_compat
  from pandas.core.dtypes.dtypes import BaseMaskedDtype, ExtensionDtype, PandasDtype
  from pandas.core.dtypes.generic import ABCDatetimeArray, ABCExtensionArray, ABCIndex, ABCMultiIndex, ABCSeries, ABCTimedeltaArray
  from pandas.core.dtypes.missing import isna, na_value_for_dtype
  from pandas.core.array_algos.take import take_nd
  from pandas.core.construction import array, ensure_wrapped_if_datetimelike, extract_array
  from pandas.core.indexers import validate_indices
label_desc: Use image node_id 17 for calling a global function with example usage: checked_add_with_arr(arr, b, arr_mask, b_mask) and returns: result