\begin{lemma}[Normal right shift on the loop-zero domain]
Let $d$ have at most 768 retained cells, all retained cells be decimal digits,
and let its retained word have length equal to the count and begin with a
digit in $[1,9]$.  Suppose its point satisfies $0\leq p<310$, and let
$0\leq k\leq60$.  Then the extracted prefix-search loop returns normally
with the original record, false all-zero flag, an index $r$, and accumulator
$c$ satisfying
\[
 1\leq r\leq n+k,\qquad 2^k\leq c<10\,2^k.                \tag{1}
\]
Put $p^*=p-r+1$.  Then
\[
                 -2047\leq p^*\leq309.                   \tag{2}
\]
Consequently the complete extracted right shift returns normally, does not
take its reset-to-zero branch, returns a nonempty record $d'$, and has the
exact point update $d'.p=p^*$.  The Lean conclusion exposes $r,c$, the exact
prefix-loop equation, the complete-call equation, (1), (2), nonemptiness, and
the point equation.
\end{lemma}
\begin{proof}
Write $n$ for the retained count, $I$ for the base-ten fold of the retained
word, and $B=2^k$.  The positive leading digit and decimal-cell hypotheses
give $n\geq1$ and $I>0$.  We first construct the normal prefix-search return
by unfolding the first two loops in
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_right_shift}.

While the read cursor $s<n$, maintain that the U64 accumulator is the
base-ten fold of the first $s$ retained digits and is below $10B$.  If its
quotient by $B$ is nonzero, the loop finishes.  Otherwise the accumulator is
below $B$; reading the next decimal digit $a<10$ replaces it by $10c+a<10B$.
The read is in bounds because $s<n\leq768$, the cursor increment is below
769, and the U64 multiply-add is safe because
$10B\leq10\,2^{60}<2^{64}$.  Thus all checked operations in this phase
succeed.

If all $n$ digits are read while the accumulator is still below $B$, it is
the positive integer $I$.  The nested loop appends zeroes, replacing $c$ by
$10c$ each time.  It takes at most $k$ iterations: after $k$ iterations its
value is $I10^k\geq10^k\geq2^k=B$, so the quotient test must have succeeded
no later.  Before that test $c<B$, hence every multiplication has result
$10c<10B<2^{64}$, and the cursor is at most $n+k$.  At the first successful
test, $B\leq c<10B$.  This constructs the stated normal prefix-loop equation.
Applying the already checked conditional characterization
\noderef{DecimalRightShiftPrefixLoopSemantics} gives exactly (1) and confirms
that the returned record and flag are $d$ and false.

The extracted definition next casts $r$ to I32 and computes $p-(r-1)$.
Since $r\leq n+k\leq768+60=828$ and $0\leq p<310$, all operands and
intermediate results are in I32 range and
\[
 p^*=p-r+1\geq0-828+1=-827>-2047,
 \qquad p^*\leq p\leq309.
\]
This proves (2).  The negation of the extracted decimal-point-range constant
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_DECIMAL_POINT_RANGE} is
$-2047$.  Therefore the strict comparison $p^*<-2047$ is false, which is the
promised sufficient nonreset criterion.

The shift $1\mathbin{\mathtt{<<}}k$ succeeds because $k\leq60<64$, and the
subtraction of one gives the mask $B-1$.  We now construct both remaining
loop returns.  In the main output loop maintain $B\leq c<10B$ initially and,
after emitting a quotient digit, $0\leq c<10B$.  Euclidean division by $B$
therefore gives a digit below ten.  If a further input digit $a<10$ is read,
the next accumulator is $10(c\bmod B)+a<10B$; hence it is below
$10\,2^{60}<2^{64}$.  Each iteration advances a read cursor bounded by $n$
and a write cursor bounded by $n\leq768$, so every read, write, cast, and
increment succeeds, and the loop terminates after at most $n$ iterations.
This is the execution invariant underlying
\noderef{DecimalRightShiftMainLoopSemantics}.

The final loop repeatedly emits $c/B$ and replaces $c$ by
$10(c\bmod B)$.  The quotient is again a decimal digit and the replacement
is below $10B<2^{64}$.  Writes below 768 succeed; at the cap the extracted
body performs no array write and only updates the sticky flag.  Termination
is finite: after the first remainder $e<B$, after at most $k$ appended
decimal zeroes the residual is zero because $B=2^k$ divides $10^k$.
Thus this loop also returns normally, with precisely the behavior stated by
\noderef{DecimalRightShiftFinalLoopSemantics}.

At the prefix-search finish, $1\leq c/B<10$.  If unread input remains, the
main loop writes this positive quotient at output cell zero; otherwise the
final loop does so.  Thus the pre-trim output count is positive and its first
cell is nonzero.  Its count is capped at 768.  The trim loop therefore
returns normally after at most that many terminal-zero inspections; by
\noderef{DecimalSeqTrimSemantics}, it preserves the point and the nonzero
first cell.  Combining these constructed subcalls in the unfolded complete
right-shift definition gives the asserted successful call, nonempty output,
and exact point $p^*$.
\end{proof}
