def _generate_range_overflow_safe(endpoint, periods, stride, side='<STR_LIT:start>'):
<EOL>assert side in ['<STR_LIT:start>', '<STR_LIT:end>']<EOL>i64max = np.uint64(np.iinfo(np.int64).max)<EOL>msg = ('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>.format(side=side, endpoint=endpoint, periods=periods))<EOL>with np.errstate(over="<STR_LIT>"):<EOL><INDENT>try:<EOL><INDENT>addend = np.uint64(periods) * np.uint64(np.abs(stride))<EOL><DEDENT>except FloatingPointError:<EOL><INDENT>raise OutOfBoundsDatetime(msg)<EOL><DEDENT><DEDENT>if np.abs(addend) <= i64max:<EOL><INDENT>return _generate_range_overflow_safe_signed(<EOL>endpoint, periods, stride, side)<EOL><DEDENT>elif ((endpoint > <NUM_LIT:0> and side == '<STR_LIT:start>' and stride > <NUM_LIT:0>) or<EOL>(endpoint < <NUM_LIT:0> and side == '<STR_LIT:end>' and stride > <NUM_LIT:0>)):<EOL><INDENT>raise OutOfBoundsDatetime(msg)<EOL><DEDENT>elif (side == '<STR_LIT:end>' and endpoint > i64max and endpoint - stride <= i64max):<EOL><INDENT>return _generate_range_overflow_safe(endpoint - stride,<EOL>periods - <NUM_LIT:1>, stride, side)<EOL><DEDENT>mid_periods = periods // <NUM_LIT:2><EOL>remaining = periods - mid_periods<EOL>assert <NUM_LIT:0> < remaining < periods, (remaining, periods, endpoint, stride)<EOL>midpoint = _generate_range_overflow_safe(endpoint, mid_periods,<EOL>stride, side)<EOL>return _generate_range_overflow_safe(midpoint, remaining, stride, side)<EOL>
Calculate the second endpoint for passing to np.arange, checking
to avoid an integer overflow.  Catch OverflowError and re-raise
as OutOfBoundsDatetime.

Parameters
----------
endpoint : int
    nanosecond timestamp of the known endpoint of the desired range
periods : int
    number of periods in the desired range
stride : int
    nanoseconds between periods in the desired range
side : {'start', 'end'}
    which end of the range `endpoint` refers to

Returns
-------
other_end : int

Raises
------
OutOfBoundsDatetime