\begin{lemma}[Exact leading-zero and dot adjustment]
Let an Aeneas byte slice $s$ have contents $ZT$, where every byte of $Z$
is either ASCII zero (48) or a dot (46), and $T$ is empty or starts with a
byte different from both.  Suppose $|s|\leq C=9223372036854775807$.
For a signed pointer-sized word $n$, assume
$0\leq n\leq |s|$ and $\mathit{isize}_{\min}\leq n-c_0(Z)$, where
$c_0(Z)$ is the number of zero bytes in $Z$.
The extracted operation
\noderef{num_imp_dec2flt_parse_adjust_many_digit_count} on $(s,n)$ returns
normally with integer value $n-c_0(Z)$.
\end{lemma}
\begin{proof}
Use the 64-bit target equation of \noderef{Assumptions}.  Unfold
\noderef{num_imp_dec2flt_parse_adjust_many_digit_count}, including its loop
body.  Write the scanning state as $(a,j,f)$, consisting of the count,
unsigned index, and scanning flag.  While $f$ is true, maintain a partition
$Z=PQ$, $j=|P|$, and $a=n-c_0(P)$.  Once $f$ is false, maintain instead
$a=n-c_0(Z)$.  Initially $P$ is empty, $j=0$, $a=n$, and $f$ is true.

If $Q=bQ'$, then $j<|s|$ and the indexed byte is exactly $b$, by the
partition and the slice equation.  If $b=48$, the checked byte subtraction
$48-1$ gives 47, saturating subtraction $48-47$ gives 1, and the
heterogeneous cast of 1 to \texttt{isize} is exact.  The new count is
$a-1=n-c_0(Pb)$.  Its lower bound follows from
$c_0(Pb)\leq c_0(Z)$ and the assumed lower bound for $n-c_0(Z)$.
Its upper bound follows from $a-1\leq n\leq |s|\leq C$.
Consequently this checked signed subtraction succeeds.
If $b=46$, the same checked byte subtraction gives 47, but saturating
subtraction $46-47$ gives 0.  Its cast is exact, and the checked subtraction
by 0 leaves the count unchanged and within its scalar bounds.
These are all possibilities by the prefix hypothesis.

In both cases the checked index increment succeeds, since
$j+1\leq |Z|\leq |s|\leq C<2^{64}$, and the invariant advances from
$P$ to $Pb$.  When $Q$ is empty and $T$ is empty, the length guard fails
at $j=|s|$ and returns the desired count.  When $Q$ is empty and
$T=bR$, the index is in bounds and the indexed byte is neither zero nor
dot.  The body keeps the count and index and changes the flag to false;
the next iteration returns the count.  A state with false flag also returns
immediately if the length guard fails.  Thus every terminal branch returns
$n-c_0(Z)$.

Termination is justified by the natural measure
$2(|s|-j)+(1\text{ if }f\text{ is true, else }0)$.
An index increment in a scanning state reduces it by 2; switching the
flag to false reduces it by 1.  No other continuation is possible.
The well-founded loop specification therefore gives a normal result with
the asserted integer value, including the all-prefix and empty-input cases.
\end{proof}
