proposition: Lemma AlignedEncoder_inv {S} {cache : Cache} (enc' : EncodeM S ByteString) (enc : forall sz, AlignedEncodeM sz) (enc_OK : EncodeMEquivAlignedEncodeM enc' enc) (enc'_aligned : forall s ce t ce', enc' s ce = Some (t, ce') -> padding t = 0) n : forall (t : Vector.t Core.char n) n1 s ce v idx ce', enc _ t n1 s ce = Some (v, idx, ce') -> exists n2 n3 (t1 : Vector.t Core.char n1) (t2 : Vector.t Core.char n2) (t3 : Vector.t Core.char n3) v2 (pf : n1 + (n2 + n3) = n), enc _ t2 0 s ce = Some (v2, n2, ce') /\ idx = n1 + n2 /\ t = eq_rect _ _ (t1 ++ t2 ++ t3) _ pf /\ v = eq_rect _ _ (t1 ++ v2 ++ t3) _ pf /\ enc' s ce = Some (build_aligned_ByteString v2, ce').
proof: Proof. intros. edestruct @AlignedEncoder_some_inv' as [b [? Heqo]]; eauto. pose proof Heqo as Hsz. eapply AlignedEncoder_sz_destruct' in Hsz; eauto. revert dependent t. revert dependent v. rewrite Hsz. intros. destruct (Vector_append_destruct3 t) as [t1 [t2 [t3 ?]]]. subst. edestruct @AlignedEncoder_inv'; eauto. destruct_conjs. subst. repeat eexists; eauto; try (rewrite <- Eqdep_dec.eq_rect_eq_dec; eauto; apply Nat.eq_dec). congruence. Unshelve. omega. Qed.
imports: Fiat.Common.Coq__8_4__8_5__Compat Bedrock.Word Coq.ZArith.ZArith Coq.NArith.NArith Coq.Arith.Arith Coq.Numbers.Natural.Peano.NPeano Coq.Logic.Eqdep_dec Fiat.Common.BoundedLookup Fiat.Narcissus.Common.Specs Fiat.Narcissus.Common.ComposeOpt Fiat.Narcissus.Common.ComposeIf Fiat.Narcissus.BaseFormats Fiat.Narcissus.BinLib.Core Fiat.Narcissus.BinLib.AlignedByteString