
     Jj                       d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZmZmZ  ee      j)                         j*                  d   Zed	z  Zd
ZdZdZdZdZdZddgZdZdddddddZ dg dddg dddg d dd!g d"dd#g d$dd%g d&dgZ!d:d;d'Z"d<d(Z#d=d)Z$d>d*Z%d?d+Z&d@d,Z'd?d-Z(dAd.Z)dBd/Z*ddd0dCd1Z+dDd2Z,dEd3Z-	 d:	 	 	 	 	 	 	 	 	 	 	 	 	 dFd4Z.dGd5Z/dGd6Z0edfdHd7Z1dId8Z2e3d9k(  r e2        yy)Jz?Tie predecessor fill-site rows to opcode 0x10 handler evidence.    )annotationsN)Path)Any)offset_to_varead_sectionsva_to_offset)handler_byteshandler_for_opcodestream_effect_text   out   i@ iA i+T iT idG iDH iDH iDH zBroot-entry execution path from 0x00478364 to 0x004844d0/0x004844d8zTdescriptor-boundary bridge from predecessor root stop through fill to current readerz\runtime proof that predecessor fill stream executes through the save-selector dispatch slicezIruntime branch-state observation matching the predecessor fill hypothesiszEpredecessor-to-current route order proof before the 0x00542b0c readerzVclosed selector-merge proof connecting predecessor 1:0 and source 0:0 into current 2:0)zroot-entry-to-fillzdescriptor-boundary-bridgezdispatch-slice-runtime-proofzruntime-fill-observedzroute-orderzselector-merge-closedHwanse2.exe)z0x0040b49e opcode 0x10 handlerz0x00410c90 helper callz0x004844d0/0x004844d8 fill rowsz0x00542b0c current reader)pathfieldszout/script_handler_table.json)0x10handlerVaHexstreamEffectreferenceCountz;out/save_selector_predecessor_fill_execution_order_gap.json)	fillSitesrootTailIsolationScandirectFillSiteRefCounts
proofFoundz=out/save_selector_predecessor_branch_state_execution_gap.json)runtimeBranchStateSplitruntimePredecessorFillObservedbranchStateExecutionProofFoundz>out/save_selector_predecessor_fill_site_execution_context.json)requiredProofGatesrequiredProofGateFailIdsbranchStatePollFillMatchCountfillSiteExecutionContextProvenz,out/save_selector_secondary_reset_scope.json)helperclosedStaticResetScopepromotionStatusc                x    | j                         s|i S |S t        j                  | j                  d            S )Nutf-8encoding)existsjsonloads	read_text)r   fallbacks     V/home/exedev/hwanse/tools/summarize_save_selector_predecessor_fill_opcode10_context.py	load_jsonr.   \   s5    ;;=%r383::dnngn677    c                    d| dS )N0x08x values    r-   hex32r6   b   s    c{r/   c                @    | sy 	 t        | d      S # t        $ r Y y w xY w)Nr   )int
ValueErrorr4   s    r-   
hex_to_intr:   f   s+    5"~ s    	c                V    | D ]$  }|d   }||d   z   }||cxk  r|k  sn |d   c S  y )Nvaraw_sizenamer3   )sectionsr<   sectionstartends        r-   section_name_for_varC   o   sE     #gj))B6?"	#
 r/   c                    g }t        j                  d|      }d}	 | j                  ||      }|dk  r	 |S t        ||      }|1|j	                  t        |      t        ||      t        |      d       |dz   }_)N<Ir   )	siteVaHexr@   targetVaHexr   )structpackfindr   appendr6   rC   )exer?   targetrefsneedleoffsethitr<   s           r-   direct_dword_refsrR   x   s    D[[v&FF
hhvv&7 K (C(>KK"2Y.x<$V} 
 q r/   c                    i }| D ]/  }|j                  d      xs d}|j                  |d      dz   ||<   1 t        t        |j                                     S )Nr@   unknownr   r   )getdictsorteditems)rN   countsrefr@   s       r-   refs_by_sectionr[      sZ    F 5'')$1	 **Wa014w5 v||~&''r/   c           
        g }|D ]  }|j                  d      dk7  r|d   }||d   z   }| || }t        dt        dt        |      dz
              D ]n  }||   dk7  rt	        |||z         }	|	t        j                  d||d	z         d   }
|	d
z   |
z   }||k(  sI|j                  t        |	      t        |      d       p  |S )Nr>   .textrawr=   r         z<ir      )	callVaHexrG   )	rU   rangemaxlenr   rH   unpack_fromrK   r6   )rL   r?   rM   rowsr@   rA   rB   dataindexr<   reldests               r-   	call_refsrl      s    D ;;v')gj))5~1c!SY]34 	EE{d"h6Bz$$T4;A>C6C<Dv~!&r#(; 	& Kr/   c           	     Z   |D ci c]  }|g  }}|j                         D ci c]  \  }}|t        j                  d|       }}}|j                         D ]E  \  }}d}	 |j                  ||      }	|	dk  r!||   j	                  t        | |	z                |	dz   }> |S c c}w c c}}w )NrE   r   r   )rX   rH   rI   rJ   rK   r6   )
base_varh   targetsr>   hitsr5   needlesrO   rP   rQ   s
             r-   dword_hits_in_bytesrr      s    7>!?t$(!?D!?AHQ+$tV[[u--QGQ f))FF+CQwJeGcM231WF  K "@Qs
   
B"!B'c                    g }t        t              }t        dz   }| j                  d      xs g D ]?  }t	        |j                  d            }| ||cxk  r|k  s,n /|j                  |       A |S )Nr_   
nearbyRowsvaHex)min
FILL_SITESFILL_FRAGMENT_STOPrU   r:   rK   )	root_tailrg   
fill_startfill_endrowr<   s         r-   fill_fragment_rowsr}      sn    DZJ!A%H}}\*0b ()>jB99KK Kr/   opcodehandlerc               ~    d}| D ]5  }||j                  d      |k7  r||j                  d      |k7  r1|dz  }7 |S )Nr   	opcodeHexr   r   rU   )rg   r   r   countr|   s        r-   	row_countr      sX    E #''+"6&"@377>#:g#E
 Lr/   c                   t        | j                  d            }|i S |dz  }|dz	  dz  }|dz	  dz  }|dz	  dz  }|rdnd}|rdnd	}d
}d }	g }
|dv r+d}ddddd|   }	t        d      D cg c]  }||	k  rdnd }
}| j                  d      | j                  d      d|dd|dd|dd|d|t        |      ||	|
|dk(  dS c c}w )NvalueHex      r      secondaryBranchStateprimaryBranchStatei`Y ipY zunknown-helper-case>   r   r         zconstant-prefix-fillr   r_   ra      )r   r   r   r      r   r   ru   r1   02x)ru   r   opcodeByteHextableSelectorByteHexhelperCaseByteHexspareByteHextargetTabletargetBaseHex
helperKindhelperFillCountexpectedStatePrefixfillsSecondaryBranchState)r:   rU   rc   r6   )r|   r5   r   table_selectorhelper_casesparetarget_tabletarget_basehelper_kindhelper_fill_countexpected_prefixri   s               r-   decode_opcode10_rowr      s3   swwz*+E}	T\FqjD(NB;$&Kb[D E-;)AUL .*JK'K!#Ol", !aA!4[ANSTViXU(9 91q@XX!GGJ'fS\*"$^C$8 9!+c!23U3K(#{+!,.%15K%K  Ys   +Cc                    | r|S |S Nr3   )r5   true_statusfalse_statuss      r-   bool_statusr      s    ;1\1r/   c                l   t        |       }t        | |t              }t        | |t              }|j                  d      xs i }	t        | |t              }
t        }t        t        |      z   }|
D ]5  }t        |j                  d            }|d uxr ||cxk  xr |k  nc |d<   7 t        t        t        d   t        d   t        t        t        t        d}|j                         D ci c]  \  }}|t!        | ||       }}}|j                         D ci c]?  \  }}|t#        ||         t        |      t%        d |D              t'        |      |d d d	A }}}t)        t        |t        d   t        d   t        t        t        d
      }t%        d |j+                         D              }|j                  d      xs i }t-        |      }|D cg c]  }|j                  d       }}g d}|D cg c]%  }|j                  d      dk(  rt/        |      }|r|' }}}t1        |      xr t3        d |D              }|D cg c]$  }|j                  d      |j                  d      & }}|r|d   j                  d      ng }|D cg c]  }d|d
 } }|j                  d      xs i }!|j                  d      xs i }"|d   d   |d   d   z   }#|j                  d      }$|j                  d      }%|j                  d      }&|j                  d      du xr/ |j                  d      du xr |#dk(  xr |$dk(  xr |%dk(  xr |&dk(  }'|"j                  d       d!u xr> |"j                  d"      d!u xr) |"j                  d#      du xr |j                  d$      dk(  }(|j                  d%      d!u xs( |j                  d&      d!u xs |"j                  d'      d!u })|j                  d(      xs g }*|*D +cg c]  }+t4        j                  |+|+       },}+d)t7        |j                  d*      t        k(  xr t        |      dkD  d+d,      d-|j                  d.       d/t9        |	       d0t        |       d1d2t7        t        |
      dk(  xr t3        d3 |
D              d4d5      d6t#        t               d7t        |
       d8|!j                  d9       d1d:t7        ||k(  d;d<      d=d>j;                  d? |D               d@d>j;                  |       d1dAt7        |xr |dBdBgk(  dCdD      d=dEj;                  dF |D              xs dG dHd>j;                  |       xs dG d1dIt7        |#dk(  dJdK      dL|# dM|j                  dN       d1dOt7        |'dPdQ      dR|$ dS|% dT|& d1dUt7        |(dVdW      dX|"j                  d        dY|"j                  d#       dZ|"j                  d"       d[|j                  d$       d1d\t7        |j                  d]      dk(  d^d_      d`|j                  d]       da|j                  db       dc|j                  dd       ded>j;                  |j                  d(      xs g       xs dG d1g}-|)sdfndg}.|.dfk(  rdhndi}/i djdkdldmdn|j                  dn      xs dodp|j                  dp      xs t#        t              dq|j                  dq      xs drds|j                  ds      xs t#        t              dt|j                  dt      xs t#        t              dddu|j                  d.      dvt#        t              dw|j                  d*      t        k(  dxt        |      dy|	dzt9        |	      d{t=        d| |xs i j                  d}      xs g D        d       d~t#        t              dt        |
      i d|
dt        |
      dk(  xr t3        d |
D              d|!j                  d9      dt        D cg c]  }t#        |       c}dt#        t?        t                     dt#        t        dz          d|d|d|d||k(  d|dtA        |D ch c]  }|j                  d       c}      d|d|d| d|dtC        |dt#        t                    dtC        |d      i dtC        |dd      d|j                  d      d|j                  d      d|j                  d      d|$d|%d|&d|d|#d|d   d   d|d|d |"j                  d       d|"j                  d"      d|"j                  d#      d|"j                  d      xs g d|j                  d      i d|j                  d      d|j                  d      d|j                  d      d|j                  d      d$|j                  d$      d|j                  d      xs g d|j                  d      d]|j                  d]      db|j                  db      d(|*dd|j                  dd      d'|j                  d%      d&|j                  d&      d%|)d|*d|,dtD        t        tD              |-|.|/dS c c}}w c c}}w c c}w c c}}w c c}w c c}w c c}+w c c}w c c}w )Nr   rb   insideOpcode10Handlerr   r   )opcode10Handlerr!   predecessorFillSite0predecessorFillSite1predecessorFillStoppredecessorRootcurrentRootcurrentReaderc              3  J   K   | ]  }|j                  d       dk(  sd  yw)r@   r]   r   Nr   .0r|   s     r-   	<genexpr>z build_summary.<locals>.<genexpr>  s      P3#'')2D2OQPs   ##   )rG   r   	textCountr?   rN   )r   r   r   r   r   c              3  2   K   | ]  }t        |        y wr   )re   )r   valuess     r-   r   z build_summary.<locals>.<genexpr>-  s     '^F'^   r   r   )r   0x00r   0xc0r   c              3  >   K   | ]  }|j                  d         yw)r   Nr   r   s     r-   r   z build_summary.<locals>.<genexpr>;  s     V34V   r   r   r1   r   r!   r   r   r   r   branchToFillFragmentCountbranchToCurrentReaderCountfixedFallthroughToFillCount"localFillTraceReachesCurrentReaderF)rootEntryFixedTraversalFillSitesReachablepublicPredecessorReachedTobservedAllZeroobservedMatchesFillr   r   r    fillExecutionOrderProofFoundr   zopcode10-handler	handlerVazhandler-resolvedzhandler-unresolvedzopcode=0x10 handler=r   z effect=z bytes=)kindstatusdetailzhelper-call-scopec              3  >   K   | ]  }|j                  d         ywr   Nr   r   s     r-   r   z build_summary.<locals>.<genexpr>x  s     .hTWsww7N/O.hr   z helper-only-called-from-opcode10zhelper-scope-openzhelper=z calls=z secondaryResetScopeOnly=#onlyDirectCallInsideOpcode10Handlerzfill-fragment-shapez&opcode10-fill-then-descriptor-boundaryzunexpected-fragment-shapezrows=,c              3  F   K   | ]  }|j                  d       xs d  yw)ru   -Nr   r   s     r-   r   z build_summary.<locals>.<genexpr>  s!      RS!1!8S!8 Rs   !z	 opcodes=zopcode10-decoded-fillr   z"secondary-branch-state-prefix-fillzdecoded-fill-open;c           
   3     K   | ]M  }|j                  d        d|j                  d       d|j                  d       d|j                  d        O yw)ru   :r   z:case=r   z:count=r   Nr   r   s     r-   r   z build_summary.<locals>.<genexpr>  sr       t  WZswww/0#''-2H1IPSPWPWXkPlOmmtuxu|u|  ~O  vP  uQ  R  ts   AAr   z expectedPrefix=zdirect-fill-entry-refszno-fill-site-text-refszhas-fill-site-text-refszfillTextRefs=z directFillCounts=r   zroot-tail-controlz no-branch-or-fallthrough-to-fillzpossible-fill-entry-proofzbranchToFill= branchToReader= fixedToFill=zruntime-branch-statez-public-predecessor-all-zero-fill-not-observedzruntime-fill-observed-or-openzpublicPredecessor= matchesFill=	 allZero= fillMatches=zrequired-proof-gatesrequiredProofGatePassCountzno-proof-gates-passedzsome-proof-gate-passedzpass=z fail=requiredProofGateFailCount allBlocked=requiredProofGateAllBlockedz failedIds=blockedzready-for-reviewa  Opcode 0x10 and helper 0x00410c90 explain the two predecessor fill rows, but this does not prove the predecessor fill fragment executes before reader 0x00542b0c. There are no direct .text refs to the fill sites, the predecessor root tail has no branch/fallthrough to the fragment, and bounded runtime polls reach public predecessor selector 1:0 with secondaryBranchState still all zero.zCThe predecessor fill opcode context has enough evidence for review.sourcemap1_01arM   map2_02dpredecessorSelectorz1:0predecessorRootHexcurrentSelectorz2:0currentRootHexcurrentReaderHexopcodeHandlerHexopcodeHandlerExpectedHexopcodeHandlerMatchesExpectedopcodeHandlerCodeSizeopcodeHandlerStreamEffectopcodeHandlerStreamEffectText scriptHandlerTableReferenceCountc              3  f   K   | ])  }|j                  d       dk(  r|j                  d       + yw)r   r   r   Nr   r   s     r-   r   z build_summary.<locals>.<genexpr>  s3      77;'61 ()s   /1entrieshelperVaHexhelperDirectCallCounthelperDirectCalls)helperOnlyDirectCallInsideOpcode10Handlerc              3  >   K   | ]  }|j                  d         ywr   r   r   s     r-   r   z build_summary.<locals>.<genexpr>  s     *dPS3773J+K*dr   <secondaryResetScopeHelperOnlyDirectCallInsideOpcode10Handlerr   fillFragmentRangeHexz..r_   fillFragmentRowsfillFragmentOpcodesfillFragmentExpectedOpcodesfillFragmentHasOnlyExpectedRowsdecodedOpcode10RowsdecodedOpcode10FillTargetTablesr   decodedOpcode10HelperFillCounts"decodedOpcode10ExpectedStatePrefix decodedOpcode10ExpectedFillHexes&decodedOpcode10AllSecondaryBranchStatefillOpcode10RowCountr~   fillDefaultAdvanceRowCount
0x0040239f)r   fillDescriptorStopRowCountr   
0x00440c5crootTailDescriptorIsolated!rootTailBranchToFillFragmentCount"rootTailBranchToCurrentReaderCount#rootTailFixedFallthroughToFillCount
directRefsdirectFillSiteTextRefCountdirectCurrentReaderTextRefCountr   "opcode10HandlerRouteImmediateCountopcode10HandlerImmediateHitsruntimeObservedAllZeroruntimeMatchesExpectedFillruntimeExpectedFillHexesexpectedFillHexesbranchStatePollSampleCount(branchStatePollPublicPredecessorHitCount"branchStatePollCurrentRootHitCount$branchStatePollRouteSelectorHitCountbranchStatePollAllZeroCountr   requiredProofGateCount$failedPredecessorFillOpcode10GateIdsmissingEvidenceevidenceRefs)evidenceRefCountevidencer#   
conclusion)#r   r
   OPCODE10r	   OPCODE10_HANDLERrU   rl   	HELPER_VAre   r:   rw   rx   PREDECESSOR_ROOTCURRENT_ROOTCURRENT_READERrX   rR   r6   sumr[   rr   r   r}   r   boolall)OPCODE10_CONTEXT_MISSING_EVIDENCE_BY_GATEr   r   joinnextrv   rW   r   OPCODE10_CONTEXT_EVIDENCE_REFS)0rL   fill_order_gapbranch_state_gapfill_site_contextsecondary_reset_scopescript_handler_tabler?   r   handler_codehandler_effecthelper_callshandler_starthandler_endr|   call_vadirect_targetsr>   r5   direct_ref_rowsrg   direct_refshandler_immediateshandler_route_immediate_country   fragment_rowsfragment_opcodesexpected_fragment_opcodesdecodeddecoded_opcode10_rowsdecoded_fill_targets_secondarydecoded_fill_countsdecoded_expected_prefixdecoded_expected_fill_hexeshelper_scoperuntime_splitfill_site_text_ref_countroot_tail_branch_to_fillroot_tail_branch_to_readerroot_tail_fixed_to_fillno_fill_entry_proofruntime_still_unprovenproof_foundrequired_proof_gate_fail_idsgate_idmissing_evidencer  promotion_statusr  s0                                                   r-   build_summaryrS     s     S!H h9G h0@AL[[06BNS(I6L$M"S%66K 
SWW[124JMW$J{$J 	#$
 , *1 *11+#'	N *//1D% 	Xu55O  *//1	 D$ 	 !56YP$PP'-"I
 	
	K 	 -$.qM$.qM#5'+	

 %('^BTB[B[B]'^$^!""#:;ArI&y1M8EF,FF @ !77;6)+C0G	 	  	"# 	WV@UVV # )77$%1 	!" 
 Vk3A6::;PQpr&=#""U3K# # ),,X6<"L$(()BCIrM 	*+K8
,
-k
:	;   )}}-HI!*/K!L'mm,IJ?@EI 	)JKuT	)$)	) %)	) '!+		)
 $q(  	45= 	H/0D8	H34=	H !!"ABaG	  	<(D0 	E  !ABdJ	E;<D 
 $5#8#89S#T#ZXZ  4 	255gwG  '!K(,<<V\ARUVAV"$ 'w{{>'B&C D,^<=WSEVDWY	
 (!L!Q&h3.h[g.h+h2# %	*+73|3D2E F++7+;+;<a+b*ce	
 *! $==8+  RM RRS T88$4568	
 ,!.P3F1a&3P4# 88  t  ^s  t  t  {  x{  | |""%((+F"G"N3!OQ	
 -!":a"?AY[tu 89 :$$2$6$67P$Q#RT		
 (!#2+   89 :""<!= >679	
 +!&?/ %]%6%67Q%R$S T,001FGH I(,,->?@ A0445TUVX	
 +!!%%&BCqH'( )--.JKL M)--.JKL M/334QRS T88-112LMSQST[X[\	^	
kdHJ )4y9K y(		h
 S \*\*\ 	~112GHQE\ 	n001EFa%P`Ja	\
 	>--.?@IE\ 	.,,-=>U%BU\ 	N../AB[eNF[\ 	V\ 	GKK7\ 	#E*:$;\ 	'K(@DT(T\ 	 \!2\ 	$^\ 	();N)K\ 	+D06B;;IFL"
 -
\. 	uY'/\0 	 \!21\2 	\3\4 	4"ds*dWc*d'd7\: 	GHXHX1I
;\@ 	
;ueEl;A\B 	5Z#9":"UCUXYCY=Z<[ \C\D 	ME\F 	/G\H 	&'@I\J 	*+;?X+XK\L 	4M\N 	*6Uj2kc377=3I2k+lO\P 	*+>Q\R 	-.ES\T 	+,GU\V 	12PW\X 		-PUVfPg hY\Z 	%i|&T[\\ 	%ifVb&c]\^ 	-n.@.@Ae.f_\` 	4^5G5G76
a\f 	%n&8&89U&Vg\h 	,-Ei\j 	-.Hk\l 	./Fm\n 	ko\p 	%&>q\r 	*;+G+Ts\t 	-.Ku\v 	'(:w\x 	#M$5$56P$Qy\z 	!-"3"34E"F{\| 	%m&7&78M&N}\~ 	#M$5$56I$J$Pb\@ 	%&7&;&;<X&YA\B 	34E4I4I65
C\H 	-.?.C.C0/
I\N 	/0A0E0E21
O\T 	&'8'<'<=Z'[U\V 	():)>)>?^)_W\X 	/334HIORY\Z 	!"3"7"78P"Q[\\ 	%&7&;&;<X&Y]\^ 	%&7&;&;<X&Y_\` 	#$@a\b 	&'8'<'<=Z'[c\d 	'(:(:<(He\f 	)*;*?*?@`*ag\h 	ki\j 	/0Lk\l 	+m\n 	6o\p   >?+ w\ \G	2 G#Bd < 3ls7   *jAjj7*j)jj"8j'j,
'j1c                   dd| d   dd| d    d| d    dd	| d
    d| d    d| d    d| d    d	d| d    dd| d    d| d    d| d    dd| d    d| d    d| d    d| d    d d!j                  | d"          d#d!j                  | d$         xs d% d&d!j                  d' | d(   D              xs d% d)d!j                  | d*         xs d% d+| d,    d-| d.    d/| d0    d1| d2    d3| d4    d5| d6    d7| d8    d9| d:    d;| d<    d=| d>    d?| d@    dA| dB    dC| dD    dE| dF    dG| dH    
dI| dJ    dK| dL    dM| dN    dOd!j                  | dP         xs d% dQ| dR    dS| dT    dU| dV    dWd!j                  | j                  dX      xs g       xs d% ddYt        | j                  dZ      xs g        d[| j                  d\       d]| d^    dd_dd`dag}| db   D ]&  }|j                  dc|dd    de|df    de|dg    dh       ( |j	                  g di       | dj   D ]  }|j                  dk|j                  dl       dm|j                  dn       dm|j                  d       dm|j                  do       dpd!j                  dq |j                  dr      xs g D              xs d% dh        |j	                  g ds       | dt   D ]  }|j                  dk|j                  dl       dm|j                  du       dm|j                  dv       dp|j                  dw       de|j                  dx       ded!j                  dy |j                  dz      xs g D              xs d% dh        |j	                  g d{       | d|   j                         D ]  \  }}d!j                  d} |j                  d~      xs i j                         D              xs d%}|j                  dc| d|j                  d       dp|j                  d       de|j                  d       de| dh        |j                  d       dj                  |      S )Nz1# Save Selector Predecessor Fill Opcode10 Context r  z
- route: `r   z -> rM   `z- predecessor/current: `r   z` `r   z` -> `r   r   z- current reader: `r   z- opcode handler: `r   r   z` (r   )z- helper: `r   z` calls=r    onlyOpcode10=r   z- fill fragment: `r   z
` opcodes=r   r   z - decoded opcode10 fill: tables=r   r   z counts=c              3  2   K   | ]  }t        |        y wr   strr   r5   s     r-   r   zmarkdown.<locals>.<genexpr>A  s,       y}  INy|  ~C  zD  y}r   r   z
 expected=r   z- fill rows: opcode10=r  z	 default=r  z descriptorStop=r  z- direct refs: fillText=r  z currentReaderText=r  z handlerRouteImmediate=r  z- root tail: isolated=r  z branchToFill=r  r   r	  r   r
  z- runtime: publicPred=r   r   r  r   r  z polls=r  r   r   z- proof gates: gates=r   /r   r   r   z failed=r   z- proof: order=r   z	 context=r    z proofFound=r   z"- failed opcode10 context gates: `r  z- missing evidence count: r  z- evidence refs: r  z- promotion status: r#   z## Evidencez| kind | status | detail |z| --- | --- | --- |r  z| r   z | r   r   z |)rU  z## Fill FragmentrU  z2| va | value | opcode | handler | fixed advances |z| --- | --- | --- | --- | --- |r   z| `ru   z` | `r   r   z` | c              3  2   K   | ]  }t        |        y wr   rZ  r\  s     r-   r   zmarkdown.<locals>.<genexpr>X  s     5mUc%j5mr   fixedAdvances)rU  z## Decoded Opcode10 Fill RowsrU  zO| va | table byte | helper case | target table | fill count | expected prefix |z&| --- | --- | --- | --- | ---: | --- |r   r   r   r   r   c              3  (   K   | ]
  }d |d  ywr1   r   Nr3   r\  s     r-   r   zmarkdown.<locals>.<genexpr>e  s     6zEE#;7G6z   r   )rU  z## Direct RefsrU  z(| target | refs | text refs | sections |z| --- | ---: | ---: | --- |r  c              3  0   K   | ]  \  }}| d |   ywr   Nr3   r   keyr5   s      r-   r   zmarkdown.<locals>.<genexpr>i  s     cese1UG,c   r?   z `rG   r   r   
)r*  rU   re   rK   extendrX   )summarylinesr|   r>   r?   s        r-   markdownrl  5  s   ;


WX&'tGH,=+>a@
"7+@#A"B#gNbFcEddjkr  tE  lF  kG  GJ  KR  Sc  Kd  Je  ef  	g
g&89:!<
gk236'BT:U9VVYZa  cB  [C  ZD  DE  	F
gm,-Xg>U6V5WWefm  oZ  g[  f\  	]
W%;<=ZQXYnQoHpGqr
*388G<]4^+_+fcf*ggopspxpx  y}  RY  Z{  R|  y}  q}  qD  AD  pE  EO  PS  PX  PX  Y`  aC  YD  PE  PL  IL  OM  	N
 )?!@ A7SoKpJq  rB  CJ  Kg  Ch  Bi  	j
"7+G#H"II\]d  fG  ^H  ]I  I`  ah  iM  aN  `O  	P
 )E!F G~V]  _B  WC  VD  DT  U\  ]A  UB  TC  CP  QX  Y~  Q  P@  	A
 )C!D EYwWoOpNqq~  @G  Hd  @e  f  fm  nu  vR  nS  mT  Ta  bi  jI  bJ  aK  	L
(D EFaPlHmGnnz  |C  Da  |b  {c  ck  lo  lt  lt  u|  }W  uX  lY  l`  ]`  ka  	b
'"@AB)GTtLuKv  wC  DK  LX  DY  CZ  	[
,SXXgkkBh6i6omo-p-wtw,xxyz
$S5F)G)M2%N$OP
GKK(:;<=
w'89:;

$5E8 z" Or#f+c#h-CM?"MNO	LL  G  H)* 
#'''"#5)<(=U377;CWBX Y'(SXX5mcggVeNfNljl5m-m-tqt,uuwy	


 
LL   ,- 
#'''"#51G)H(I J+,-T#''-2H1Iww()*#chh6zUXU\U\]rUsUywy6z.z  /B  B  .C  CEF	

 
LLvw\*002 
	c88c
@S@YWY?`?`?bccjgjb/0SWWW5E4Fc#''R]J^I__bckbllno	


 
LL99Ur/   c           )     v   dj                  d | d   D              }dj                  d | d   D              }dj                  d | d   D              }dj                  d | d	   j                         D              }dj                  d
dddt        j                  | d          ddt        j                  | d          dt        j                  | d          dt        j                  | d          dt        j                  | d          dt        j                  | d          dt        j                  | d          dt        j                  | d          ddt        j                  | d          d t        j                  | d!   xs d"       d#t        j                  | d$          d%t        j                  | d&          d'| d(    d)| d*    d+d,t        j                  | d-          d.t        j                  d/j                  | d0                d1| d2    d3| d4    d5| d6    d7| d8    d9| d:    d;| d<    d+d=t        j                  d/j                  | d>         xs d"       d?t        j                  d/j                  d@ | dA   D              xs d"       dBt        j                  d/j                  | dC         xs d"       d+dD| dE    dF| dG    dH| dI    dJ| dK    dL| dM    dN| dO    dP| dQ    dR| dS    dTt        j                  d/j                  | dU         xs d"       dV| dW    dXt        j                  d/j                  | j	                  dY      xs g       xs d"       dZt        | j	                  d[      xs g        d\| j	                  d]       d^t        j                  | d_          d+d`|dadb|dadc|dadd|dag      S )eNrh  c           
   3     K   | ]R  }d t        j                  |d          dt        j                  |d          dt        j                  |d          d T yw)<tr><td>r   	</td><td>r   r   
</td></tr>N)htmlescaper   s     r-   r   zhtml_page.<locals>.<genexpr>r  sg       	{{3v;'( ){{3x=)* +{{3x=)* +	s   AAr  c              3    K   | ]  }d t        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  dj                  d	 |j                  d
      xs g D              xs d       d  yw)<tr><td><code>ru   r   </code></td><td><code>r   r   r   </code></td><td>r   c              3  2   K   | ]  }t        |        y wr   rZ  r\  s     r-   r   z&html_page.<locals>.<genexpr>.<genexpr>  s     #[5CJ#[r   r_  rq  N)rr  rs  rU   r*  r   s     r-   r   zhtml_page.<locals>.<genexpr>z  s      	 	[[!1!8S9: ;[[!4!;<= >[[!5!<=> ?[[!8!?C@A B{{388#[CGGO<T<ZXZ#[[b_bcd e		s   C4C6r   c              3  P  K   | ]  }d t        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  |j                  d      xs d       dt        j                  t        |j                  d	                   dt        j                  d
j	                  d |j                  d      xs g D              xs d       d   yw)ru  ru   r   rv  r   r   rw  r   rp  r   r   c              3  (   K   | ]
  }d |d  ywra  r3   r\  s     r-   r   z&html_page.<locals>.<genexpr>.<genexpr>  s     #gbs$4#grb  r   rq  N)rr  rs  rU   r[  r*  r   s     r-   r   zhtml_page.<locals>.<genexpr>  s     
 	[[!1!8S9: ;[[)?!@!GCHI J[[)<!=!DEF G{{377=18S9: ;{{3sww'89:;< ={{388#g#''J_B`Bfdf#ggnknop q	
s   D$D&r   c              3    K   | ]  \  }}d t        j                  |       dt        j                  |j                  d      xs d       d|j                  d       d|j                  d       dt        j                  dj                  d	 |j                  d
      xs i j	                         D              xs d       d  yw)ro  z <code>rG   r   rw  r   rp  r   r   c              3  0   K   | ]  \  }}| d |   ywrd  r3   re  s      r-   r   z&html_page.<locals>.<genexpr>.<genexpr>  s     #kese1UG$4#krg  r?   rq  N)rr  rs  rU   r*  rX   )r   r>   r|   s      r-   r   zhtml_page.<locals>.<genexpr>  s       D#	{{4 !SWW]5K5Rs)S(T Uwww  !ww{#$ %{{388#kPZH[Ha_aGhGhGj#kkrorst u		s   CCr  zc<!doctype html><meta charset="utf-8"><title>Save Selector Predecessor Fill Opcode10 Context</title>z<style>body{font-family:system-ui,sans-serif;background:#111;color:#eee;max-width:1100px;margin:24px auto}table{border-collapse:collapse;width:100%;margin:18px 0}td,th{border:1px solid #444;padding:6px 8px;vertical-align:top}code{color:#9bd4ff}</style>z8<h1>Save Selector Predecessor Fill Opcode10 Context</h1>z<p>r  z</p>z<p>route <code>r   z -&gt; rM   z</code>; predecessor <code>r   z</code> <code>r   z</code>; current <code>r   r   z</code>; reader <code>r   z</code>.</p>z<p>opcode <code>r   z</code> handler <code>r   r   z	</code> (r   z); helper <code>r   z</code> calls r   rX  r   z.</p>z<p>fill fragment <code>r   z</code>; opcodes r   r   z; opcode10=r  z
; default=r  z; descriptorStop=r  z; fillText=r  z; currentReaderText=r  z; handlerRouteImmediate=r  z <p>decoded opcode10 fill tables=r   z	; counts=c              3  2   K   | ]  }t        |        y wr   rZ  r\  s     r-   r   zhtml_page.<locals>.<genexpr>  s0       SW  ch  TW  X]  T^  SWr   r   z; expected=r   z<p>runtime publicPred=r   z
; allZero=r  z; matchesFill=r  z; polls=r  z; fillMatches=r   z; proof gates r   r]  r   z; allBlocked=r   z	; failed=r   z; proofFound=r   z ; failed opcode10 context gates=r  z; missing evidence count=r  z; evidence refs=r  z; promotion status r#   zb<h2>Evidence</h2><table><thead><tr><th>kind</th><th>status</th><th>detail</th></tr></thead><tbody>z</tbody></table>z<h2>Fill Fragment</h2><table><thead><tr><th>va</th><th>value</th><th>opcode</th><th>handler</th><th>fixed advances</th></tr></thead><tbody>z<h2>Decoded Opcode10 Fill Rows</h2><table><thead><tr><th>va</th><th>table byte</th><th>helper case</th><th>target table</th><th>fill count</th><th>expected prefix</th></tr></thead><tbody>zy<h2>Direct Refs</h2><table><thead><tr><th>target</th><th>refs</th><th>text refs</th><th>sections</th></tr></thead><tbody>)r*  rX   rr  rs  rU   re   )rj  evidence_rowsr=  decoded_rowsref_rowss        r-   	html_pager  q  s   II  :& M II 	 -.	 	M 99 
 01
 
L yy  !.446 H 99o 	GB
dkk',/016
$++gh&789WU]M^A_@``{  }A  }H  }H  IP  Qf  Ig  }h  |i  iw  x|  xC  xC  DK  L`  Da  xb  wc  cz  {  {F  {F  GN  O`  Ga  {b  zc  cq  rv  r}  r}  ~E  FV  ~W  rX  qY  Yo  pt  p{  p{  |C  DV  |W  pX  oY  Ye  	f
4;;w{';<==STXT_T_`ghz`{  aC  @C  UD  TE  EN  OS  OZ  OZ  [b  cB  [C  OD  NE  EU  VZ  Va  Va  bi  jw  bx  Vy  Uz  zH  IP  Qh  Ii  Hj  jx  y@  Al  ym  xn  ns  	t
!$++g6L.M"N!OO`aealalmpmumuv}  T  wU  nV  bW  aX  Xc  dk  lB  dC  cD  DN  OV  Ws  Ot  Nu  uF  GN  Ok  Gl  Fm  mx  y@  A]  y^  x_  _s  t{  |]  t^  s_  _w  x  @d  xe  wf  fk  	l
*4;;sxxHi@j7k7ror+s*tt}  C  J  J  KN  KS  KS  SW  ls  tU  lV  SW  KW  K^  [^  _  ~`  `k  lp  lw  lw  x{  x@  x@  AH  Ik  Al  xm  xt  qt  lu  kv  v{  	|
 )C!D EZPWXpPqOr  sA  BI  Jf  Bg  Ah  hp  qx  yU  qV  pW  We  fm  nM  fN  eO  O]  ^e  fB  ^C  ]D  DE  FM  Nj  Fk  El  ly  zA  B_  z`  ya  aj  ko  kv  kv  wz  w  w  @G  Hb  @c  wd  wk  hk  kl  jm  mz  {B  CO  {P  zQ  Qq  rv  r}  r}  ~A	  ~F	  ~F	  G	N	  G	R	  G	R	  S	y	  G	z	  G	@
  ~	@
  ~A
  ~H
  E
H
  rI
  qJ
  J
c
  d
g
  h
o
  h
s
  h
s
  t
E  h
F  h
L  JL  d
M  c
N  N^  _f  _j  _j  k}  _~  ^  R  SW  S^  S^  _f  gx  _y  Sz  R{  {@  	Al 	V 	F 	D+  r/   c                   |j                  dd       |dz  }|j                  t        j                  | dd      dz   d	       |9|j                  j                  dd       |j                  t        |       d	       |S )
NT)parentsexist_okz4save_selector_predecessor_fill_opcode10_context.jsonFr   )ensure_asciiindentrh  r%   r&   )mkdir
write_textr)   dumpsparentr  )rj  out_dirhtml_outjson_outs       r-   write_outputsr    s    MM$M.OOH

7q9D@   dT:Ig.AOr/   c                    t        j                  t              } | j                  dt        t
        dz         | j                  dt        t               | j                  dt               | j                         }t        |j                  j                         t        |j                  dz  i       t        |j                  d	z  i       t        |j                  d
z  i       t        |j                  dz  i       t        |j                  dz  i             }t        ||j                  |j                        }t        d|        y )N)descriptionz--exer   )typedefaultz	--out-dirz
--html-out)r  z7save_selector_predecessor_fill_execution_order_gap.jsonz9save_selector_predecessor_branch_state_execution_gap.jsonz:save_selector_predecessor_fill_site_execution_context.jsonz(save_selector_secondary_reset_scope.jsonzscript_handler_table.jsonz+wrote predecessor fill opcode10 context -> )argparseArgumentParser__doc__add_argumentr   ROOTOUT
parse_argsrS  rL   
read_bytesr.   r  r  r  print)parserargsrj  r  s       r-   mainr    s   $$9F
dD=4HI
$<
40D$,,!ZZ\^_$,,!\\^`a$,,!]]_ab$,,!KKRP$,,!<<bAG WdllDMMBH	5*	r/   __main__r   )r   r   r,   z
Any | Nonereturnr   )r5   r8   r  r[  )r5   
str | Noner  z
int | None)r?   
list[dict]r<   r8   r  r  )rL   bytesr?   r  rM   r8   r  r  )rN   r  r  dict[str, int])rn   r8   rh   r  ro   r  r  zdict[str, list[str]])ry   rV   r  r  )rg   r  r   r  r   r  r  r8   )r|   rV   r  rV   )r5   r'  r   r[  r   r[  r  r[  )rL   r  r-  rV   r.  rV   r/  rV   r0  rV   r1  zdict | Noner  rV   )rj  rV   r  r[  )rj  rV   r  r   r  zPath | Noner  r   )r  None)4r  
__future__r   r  rr  r)   rH   pathlibr   typingr   probe_exe_scene_tablesr   r   r   summarize_script_handler_tabler	   r
   r   __file__resolver  r  r  r   r!  r"  r%  r$  r#  rw   rx   r)  r,  r.   r6   r:   rC   rR   r[   rl   rr   r}   r   r   r   rS  rl  r  r  r  __name__r3   r/   r-   <module>r     s   E "       L L ` ` H~''*
Ul 	 *%
  	M 	_ 	g 	TZ`- )( 
 0L
 N
 P
 Q
 ?IQ," ^8&(0 9=TX B2 )-~	~~ ~ 	~
  ~ &~ 
~B
9x=@ 25d 
* zF r/   