\begin{lemma}[Exact second carry-loop semantics]
Let $a$ be a 768-cell byte array, let $b$ be a Boolean, let $q$ be a
\texttt{usize} write cursor, and let $c$ be a \texttt{u64} carry satisfying
$c<10^q$.  Suppose that, whenever $j<q$, $j<768$, and
$c<10^{q-j-1}$, cell $a[j]$ is zero.  If the extracted
\texttt{left\_shift\_loop1} call on $(b,a,q,c)$ returns $(b',a')$, then
there is a length-$q$ list $u$ of decimal digits such that
\[
                 c=\operatorname{fold}_{10}(u).
\]
For every $j<q$ with $j<768$, cell $a'[j]$ equals $u_j$; every physical
cell at or beyond $q$ is unchanged; and
\[
 b'=\mathrm{true}\quad\Longleftrightarrow\quad
 b=\mathrm{true}\ \text{or}\
 \bigl(\exists j<q,\ 768\le j\ \text{and}\ u_j\ne0\bigr).
\]
Thus the conclusion includes the leading-zero-padding consequence: a
carry having fewer than $q$ decimal digits is represented by zeroes in the
untouched positions before the loop's final cursor.
\end{lemma}
\begin{proof}
Use \noderef{ResultLoopPartial} for the exact extracted body in
\noderef{num_imp_dec2flt_decimal_seq_DecimalSeq_left_shift}.  At an
intermediate state $(b_s,a_s,w,c_s)$, let $v$ be the list of remainders
already produced, in most-significant-to-least-significant order.  Maintain
\[
 w\le q,\qquad c_s<10^w,\qquad |v|=q-w,
 \qquad c=c_s10^{|v|}+\operatorname{fold}_{10}(v).       \tag{1}
\]
Every member of $v$ is below ten.  Maintain also that $a_s[w+j]=v_j$
whenever that destination is physical, that cells outside $[w,q)$ are
unchanged, and that $b_s$ is $b$ OR the nonzeroness of exactly those
members $v_j$ whose destination $w+j$ is at least 768.  These clauses hold
initially with $w=q$, $c_s=c$, and $v$ empty.

Consider a continuation step.  It has $c_s>0$.  From $c_s<10^w$ it follows
that $w>0$, so the extracted \texttt{usize} subtraction $w-1$ is legal.
Put
\[
 t=\lfloor c_s/10\rfloor,
 \qquad r=c_s-10t=c_s\bmod10.
\]
The extracted \texttt{u64} division is legal because its divisor is ten.
The standard division bound $10t\le c_s<2^{64}$ discharges the checked
\texttt{u64} multiplication, and it also discharges the following checked
subtraction.  Euclidean division gives $c_s=10t+r$ and $r<10$; hence the
\texttt{u8} cast of $r$ is exact.  Moreover, if $w_1=w-1$, then
$t<10^{w_1}$, directly from $c_s<10^w$ and
$10^w=10\cdot10^{w_1}$.  Prepending $r$ to $v$ therefore preserves every
arithmetic clause of (1), including the exact fold equation.

If $w_1<768$, the extracted cap test takes its write branch.  The fixed
array has length 768, so the update is in bounds; its update equation puts
$r$ at the new first destination and preserves every other cell.  The
array and Boolean invariants follow.  If $w_1\ge768$, the body performs no
array access.  Its two remainder branches set the Boolean precisely when
$r$ is nonzero, which is exactly the newly omitted-digit disjunct.  Thus
both cap branches preserve the invariant.  Division also strictly reduces
a positive carry, so the partial-loop principle reaches the body's done
branch; equivalently, the supplied normal loop result receives the stated
postcondition.

At done, $c_s=0$.  Equation (1) says
$c=\operatorname{fold}_{10}(v)$ and $|v|=q-w$.  Prefix $v$ by $w$ zeroes
to obtain $u$.  Decimal-digit induction gives
$\operatorname{fold}_{10}(v)<10^{|v|}$.  Hence for each $j<w$,
\[
 c<10^{|v|}\le10^{q-j-1}.
\]
The hypothesis says that the original physical cell $a[j]$ is zero, and
the unchanged-cell invariant says that $a_s[j]$ is the same zero.  These
are exactly the padded leading entries of $u$.  The suffix entries follow
from the written-cell invariant.  Prefixing zeroes creates no omitted
nonzero digit, so reindexing the maintained Boolean equivalence yields the
displayed equivalence for $u$.  The unchanged suffix clause is already an
invariant clause, completing the proof.
\end{proof}
