/*---------------------------------------------------------------------------
  Copyright 2012-2021, Microsoft Research, Daan Leijen.

  This is free software; you can redistribute it and/or modify it under the
  terms of the Apache License, Version 2.0. A copy of the License can be
  found in the LICENSE file at the root of this distribution.
---------------------------------------------------------------------------*/

/* Internal effect handler primitives.

  Internal primitives to implement evidence based algebraic
  effect handlers. These are emitted by the compiler during evidence
  translation and this module is always implicitly imported.

  The paper:

  Ningning Xie, and Daan Leijen. _Generalized Evidence Passing for Effect Handlers_,
  or _efficient compilation of effect handlers to C_. 
  Proceedings of the ACM International Conference on Functional Programming (ICFP'21), 
  August 2021, Vol 5: pp. 71, doi: 10.1145/3473576.
  <https://www.microsoft.com/en-us/research/publication/generalized-evidence-passing-for-effect-handlers-or-efficient-compilation-of-effect-handlers-to-c/>

  describes how the monadic evidence translation works on which this
  module is based. This module is compiled _without monadic translation_ and
  thus we need to do this by hand in this module which allows us to implement
  most primitives directly in Koka keeping the external C/JavaScript/etc primitives
  to a minimum.
*/
module hnd

import types

extern import 
  c  file "hnd-inline"
  js file "hnd-inline.js"

// -------------------------------------------
// Internal types
// -------------------------------------------

// Each handler in the context has a unique marker.
struct markerstd/core/hnd/marker: (E, V) -> V<ee: E::E,aa: V>( mm: int32 : int32std/core/types/int32: V)

// The tag of a handler identifies the type at runtime (e.g. `"exn/core/std"`).
abstract type htagstd/core/hnd/htag: ((E, V) -> V) -> V<hh: (E, V) -> V::(E,V)->V> 
  Htagstd/core/hnd/Htag: forall<a> (tagname : string) -> htag<a>(tagnametagname: string:stringstd/core/types/string: V)

pub fun ".new-htag"( tagtag: string : stringstd/core/types/string: V ) 
  Htagstd/core/hnd/Htag: forall<a> (tagname : string) -> htag<a>(tagtag: string)

pub fun hidden-htagstd/core/hnd/hidden-htag: forall<a> (tag : string) -> htag<a>( tagtag: string : stringstd/core/types/string: V ) 
  Htagstd/core/hnd/Htag: forall<a> (tagname : string) -> htag<a>(tagtag: string)

// control flow context:
//                 -1: none: bottom
//                   /          \
// 0: except: never resumes   1: linear: resumes exactly once
//                   \          /
//           2: affine: resumes never or once
//                        |
//     3: multi: resumes never, once, or multiple times
pub alias cfcstd/core/hnd/cfc: V = int32std/core/types/int32: V

// Effect handler evidence of a handler `:h` in the context.
abstract type evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V> 
  con Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a><ee: E,rr: V>(htaghtag: htag<24>:htagstd/core/hnd/htag: ((E, V) -> V) -> V<hh: (E, V) -> V>, markermarker: marker<25,26>:markerstd/core/hnd/marker: (E, V) -> V<ee: E,rr: V>, hndhnd: 24<25,26>:hh: (E, V) -> V<ee: E,rr: V>, cfccfc: cfc:cfcstd/core/hnd/cfc: V, hevvhevv: evv<25>:evvstd/core/hnd/evv: E -> V<ee: E>)

// Evidence vectors
type evvstd/core/hnd/evv: E -> V<ee: E::E>

pub alias ev-indexstd/core/hnd/ev-index: V = ssize_tstd/core/types/ssize_t: V

// -------------------------------------------
// Internal Markers
// -------------------------------------------

extern fresh-marker-intstd/core/hnd/fresh-marker-int: () -> int32() : int32std/core/types/int32: V 
  c  "kk_marker_unique"
  js inline "$marker_unique++"

extern fresh-marker-named-intstd/core/hnd/fresh-marker-named-int: () -> int32() : int32std/core/types/int32: V 
  c inline  "-kk_marker_unique(kk_context())"
  js inline "-($marker_unique++)"

fun fresh-markerstd/core/hnd/fresh-marker: forall<e,a> () -> marker<e,a>() : markerstd/core/hnd/marker: (E, V) -> V<ee: E,rr: V> 
  Markerstd/core/hnd/Marker: forall<e,a> (m : int32) -> marker<e,a>(fresh-marker-intstd/core/hnd/fresh-marker-int: () -> int32())

fun fresh-marker-namedstd/core/hnd/fresh-marker-named: forall<e,a> () -> marker<e,a>() : markerstd/core/hnd/marker: (E, V) -> V<ee: E,rr: V> 
  Markerstd/core/hnd/Marker: forall<e,a> (m : int32) -> marker<e,a>(fresh-marker-named-intstd/core/hnd/fresh-marker-named-int: () -> int32())

// -------------------------------------------
// Internal Evidence vectors
// -------------------------------------------

inline extern evv-totalstd/core/hnd/evv-total: () -> evv<(<>)>() : evvstd/core/hnd/evv: E -> V<<std/core/types/(<>): E>> 
  c  "kk_evv_total"
  js inline "[]"


pub inline extern ".evv-at"<e,h> ( i : ev-indexstd/core/hnd/ev-index: V ) : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>  // pretend total; don't simplify
  c  "kk_evv_at"
  js "$std_core_hnd._evv_at"

// (dynamically) find evidence insertion/deletion index in the evidence vector
pub extern ".evv-index"<ee: E::E,hh: (E, V) -> V>( htaghtag: htag<$3131> : htagstd/core/hnd/htag: ((E, V) -> V) -> V<hh: (E, V) -> V> ) : ee: E ev-indexstd/core/hnd/ev-index: V 
  c  "kk_evv_index"
  js "__evv_index"


pub extern ".evv-lookup"( htaghtag: htag<$3147> : htagstd/core/hnd/htag: ((E, V) -> V) -> V<hh: (E, V) -> V> ) : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V> 
  c  "kk_evv_lookup"
  js "__evv_lookup"

pub inline extern ".evv-select"( i : ev-indexstd/core/hnd/ev-index: V, htag : htagstd/core/hnd/htag: ((E, V) -> V) -> V<hh: (E, V) -> V> ) : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V> 
  c  inline "(#1 >= 0 ? kk_evv_at(#1,kk_context()) : kk_evv_lookup(#2,kk_context()))"
  js inline "(#1 >= 0 ? $std_core_hnd._evv_at(#1) : __evv_lookup(#2))"

extern evv-showstd/core/hnd/evv-show: forall<e> (evv : evv<e>) -> string( evvevv: evv<$4296> : evvstd/core/hnd/evv: E -> V<ee: E> ) : stringstd/core/types/string: V 
  c  "kk_evv_show"
  js "_evv_show"

extern evv-eqstd/core/hnd/evv-eq: forall<e> (evv0 : evv<e>, evv1 : evv<e>) -> bool(evv0evv0: evv<$3891> : evvstd/core/hnd/evv: E -> V<ee: E>, evv1evv1: evv<$3891> : evvstd/core/hnd/evv: E -> V<ee: E> ) : boolstd/core/types/bool: V 
  c  "kk_evv_eq"
  js inline "(#1) === (#2)"


extern evv-getstd/core/hnd/evv-get: forall<e> () -> e evv<e>() : ee: E evvstd/core/hnd/evv: E -> V<ee: E> 
  c  "kk_evv_get"
  js "$std_core_hnd._evv_get"

inline extern evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()<e1,e>( w : evvstd/core/hnd/evv: E -> V<e1e1: E> ) : ee: E (std/core/types/(): V)std/core/types/(): V 
  c  "kk_evv_set"
  js "$std_core_hnd._evv_set"

inline extern evv-swapstd/core/hnd/evv-swap: forall<e,e1,e2> (w : evv<e1>) -> e evv<e2><e1,e2>( w : evvstd/core/hnd/evv: E -> V<e1e1: E> ) : ee: E evvstd/core/hnd/evv: E -> V<e2e2: E> 
  c  "kk_evv_swap"
  js "$std_core_hnd._evv_swap"

extern evv-insertstd/core/hnd/evv-insert: forall<e,e1,a> (evv : evv<e>, ev : ev<a>) -> e evv<e1>( evvevv: evv<$3868> : evvstd/core/hnd/evv: E -> V<e1e1: E>, evev: ev<$3870> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V> ) : e1e1: E evvstd/core/hnd/evv: E -> V<e2e2: E> 
  c  "kk_evv_insert"
  js "_evv_insert"

extern evv-swap-deletestd/core/hnd/evv-swap-delete: forall<e,e1> (i : ev-index, behind : bool) -> e1 evv<e>( ii: ev-index : ev-indexstd/core/hnd/ev-index: V, behindbehind: bool : boolstd/core/types/bool: V ) : e1e1: E evvstd/core/hnd/evv: E -> V<ee: E> 
  c  "kk_evv_swap_delete"
  js "_evv_swap_delete"

inline extern evv-swap-create0std/core/hnd/evv-swap-create0: forall<e> () -> e evv<e>() : ee: E evvstd/core/hnd/evv: E -> V<ee: E>  //not quite the right effect type but avoids unbound effect types
  c  "kk_evv_swap_create0"
  js "$std_core_hnd._evv_swap_create0"

inline extern evv-swap-create1std/core/hnd/evv-swap-create1: forall<e> (i : ev-index) -> e evv<e>( i : ev-indexstd/core/hnd/ev-index: V ) : ee: E evvstd/core/hnd/evv: E -> V<ee: E>  //not quite the right effect type but avoids unbound effect types
  c  "kk_evv_swap_create1"
  js "$std_core_hnd._evv_swap_create1"

extern evv-swap-createstd/core/hnd/evv-swap-create: forall<e> (indices : vector<ev-index>) -> e evv<e>( indicesindices: vector<ev-index> : vectorstd/core/types/vector: V -> V<ev-indexstd/core/hnd/ev-index: V> ) : ee: E evvstd/core/hnd/evv: E -> V<ee: E>  //not quite the right effect type but avoids unbound effect types
  c  "kk_evv_swap_create"
  js "_evv_swap_create"

inline extern ev-nonestd/core/hnd/ev-none: forall<e,a> () -> e ev<a><e,h>() : ee: E evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V> 
  c  "kk_ev_none"
  js "ev_none"

pub extern ".evv-is-affine"() : boolstd/core/types/bool: V 
  c  inline "kk_evv_cfc(kk_context())<=2"
  js inline "$std_core_hnd._evv_cfc()<=2"


// -------------------------------------------
// Internal Yielding
// -------------------------------------------

pub inline extern yieldingstd/core/hnd/yielding: () -> bool() : boolstd/core/types/bool: V 
  c  "kk_yielding"
  js "$std_core_hnd._yielding"

pub inline extern yielding-non-finalstd/core/hnd/yielding-non-final: () -> bool() : boolstd/core/types/bool: V 
  c  "kk_yielding_non_final"
  js "$std_core_hnd._yielding_non_final"

pub noinline extern yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b(nextnext: ($3910) -> $3912 $3911 : aa: V -> ee: E bb: V ) : ee: E bb: V 
  c  "kk_yield_extend"
  js "_yield_extend"

pub inline fun yield-bindstd/core/hnd/yield-bind: forall<a,b,e> (x : a, next : (a) -> e b) -> e b( xx: $4520 : aa: V, nextnext: ($4520) -> $4522 $4521 : aa: V -> ee: E bb: V ) : ee: E bb: V 
  if yieldingstd/core/hnd/yielding: () -> bool() then yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b(nextnext: ($4520) -> $4522 $4521) else nextnext: ($4520) -> $4522 $4521(xx: $4520)

pub inline fun yield-bind2std/core/hnd/yield-bind2: forall<a,b,e> (x : a, extend : (a) -> e b, next : (a) -> e b) -> e b( xx: $10790 : aa: V, extendextend: ($10790) -> $10792 $10791 : aa: V -> ee: E bb: V, nextnext: ($10790) -> $10792 $10791 : aa: V -> ee: E bb: V ) : ee: E bb: V 
  if yieldingstd/core/hnd/yielding: () -> bool() then yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b(extendextend: ($10790) -> $10792 $10791) else nextnext: ($10790) -> $10792 $10791(xx: $10790)

extern yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(ff: forall<a> ((a) -> $3929 $3928, a) -> $3929 $3930 : forall<bb: V> (bb: V -> ee: E aa: V, bb: V) -> ee: E rr: V ) : ee: E rr: V  // make hidden pub?
  c  "kk_yield_cont"
  js "_yield_cont"

inline extern keep-yielding-finalstd/core/hnd/keep-yielding-final: forall<e,a> () -> e a() : ee: E rr: V 
  c  "kk_box_any"
  js inline "undefined"

extern yield-promptstd/core/hnd/yield-prompt: forall<a,e,b> (m : marker<e,b>) -> yld<e,a,b>( mm: marker<$3951,$3952>: markerstd/core/hnd/marker: (E, V) -> V<ee: E,rr: V> ) : yldstd/core/hnd/yld: (E, V, V) -> V<ee: E,aa: V,rr: V> 
  c  "kk_yield_prompt"
  js "_yield_prompt"

extern yield-to-primstd/core/hnd/yield-to-prim: forall<a,e,e1,b> (m : marker<e1,b>, clause : ((resume-result<a,b>) -> e1 b) -> e1 b) -> e (() -> a)( mm: marker<$4127,$4128> : markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>, clauseclause: ((resume-result<$4125,$4128>) -> $4127 $4128) -> $4127 $4128 : (resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> e1e1: E rr: V) -> e1e1: E rr: V ) : ee: E (() -> bstd/core/types/(<>): E) 
  c  "kk_yield_to"
  js "$std_core_hnd._yield_to"

extern yield-to-finalstd/core/hnd/yield-to-final: forall<a,e,e1,b> (m : marker<e1,b>, clause : ((resume-result<a,b>) -> e1 b) -> e1 b) -> e a( mm: marker<$3972,$3973> : markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>, clauseclause: ((resume-result<$3970,$3973>) -> $3972 $3973) -> $3972 $3973 : (resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> e1e1: E rr: V) -> e1e1: E rr: V ) : ee: E bb: V 
  c  "kk_yield_final"
  js "$std_core_hnd._yield_final"

noinline fun yield-tostd/core/hnd/yield-to: forall<a,e,b> (m : marker<e,b>, clause : ((resume-result<a,b>) -> e b) -> e b) -> e a( mm: marker<$6464,$6465> : markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>, clauseclause: ((resume-result<$6463,$6465>) -> $6464 $6465) -> $6464 $6465 : (resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> e1e1: E rr: V) -> e1e1: E rr: V ) : e1e1: E bb: V 
  //val w0 = evv-get()
  val gg: () -> $6463 : () -> _b_b: V = yield-to-primstd/core/hnd/yield-to-prim: forall<a,e,e1,b> (m : marker<e1,b>, clause : ((resume-result<a,b>) -> e1 b) -> e1 b) -> e (() -> a)(mm: marker<$6464,$6465>, clauseclause: ((resume-result<$6463,$6465>) -> $6464 $6465) -> $6464 $6465)
  yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b fn(ff: () -> $6464 $6463)
    // val keep1 = guard(w0)  // check the evidence is correctly restored
    ff: () -> $6464 $6463()

pub type yield-infostd/core/hnd/yield-info: V

extern yield-capturestd/core/hnd/yield-capture: forall<e> () -> e yield-info() : ee: E yield-infostd/core/hnd/yield-info: V 
  c "kk_yield_capture"
  js "_yield_capture"

pub extern unsafe-reyieldstd/core/hnd/unsafe-reyield: forall<a,e> (yld : yield-info) -> e a(yldyld: yield-info : yield-infostd/core/hnd/yield-info: V) : ee: E aa: V 
  c "kk_yield_reyield"
  js "_reyield"


// -------------------------------------------
//
// -------------------------------------------
  
inline extern cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1> (f : () -> e1 a) -> (() -> e a)( f:() -> e1e1: E bb: V) : ((std/core/types/(<>): E) -> e0e0: E bb: V) 
  inline "#1"

inline extern cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)( f:(a1a1: V) -> e1e1: E bb: V) : ((std/core/types/(<>): Ea1a1: V) -> e0e0: E bb: V) 
  inline "#1"
  
inline extern cast-ev2std/core/hnd/cast-ev2: forall<a,b,c,e,e1> (f : (a, b) -> e1 c) -> ((a, b) -> e c)( f:(a1a1: V,a2a2: V) -> e1e1: E bb: V) : ((std/core/types/(<>): Ea1a1: V,a2a2: V) -> e0e0: E bb: V) 
  inline "#1"
  
inline extern cast-ev3std/core/hnd/cast-ev3: forall<a,b,c,d,e,e1> (f : (a, b, c) -> e1 d) -> ((a, b, c) -> e d)( f:(a1a1: V,a2a2: V,a3a3: V) -> e1e1: E bb: V) : ((std/core/types/(<>): Ea1a1: V,a2a2: V,a3a3: V) -> e0e0: E bb: V) 
  inline "#1"
  
inline extern cast-ev4std/core/hnd/cast-ev4: forall<a,b,c,d,a1,e,e1> (f : (a, b, c, d) -> e1 a1) -> ((a, b, c, d) -> e a1)( f:(a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> e1e1: E bb: V) : ((std/core/types/(<>): Ea1a1: V,a2a2: V,a3a3: V,a4a4: V) -> e0e0: E bb: V)   
  inline "#1"
  
inline extern cast-ev5std/core/hnd/cast-ev5: forall<a,b,c,d,a1,b1,e,e1> (f : (a, b, c, d, a1) -> e1 b1) -> ((a, b, c, d, a1) -> e b1)( f:(a1a1: V,a2a2: V,a3a3: V,a4a4: V,a5a5: V) -> e1e1: E bb: V) : ((std/core/types/(<>): Ea1a1: V,a2a2: V,a3a3: V,a4a4: V,a5a5: V) -> e0e0: E bb: V) 
  inline "#1"

value type resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> 
  Deepstd/core/hnd/Deep: forall<a,b> (result : a) -> resume-result<a,b>( resultresult: 80: bb: V )
  Shallowstd/core/hnd/Shallow: forall<a,b> (result : a) -> resume-result<a,b>( resultresult: 80: bb: V )
  Finalizestd/core/hnd/Finalize: forall<a,b> (result : b) -> resume-result<a,b>( resultresult: 81 : rr: V )

type yldstd/core/hnd/yld: (E, V, V) -> V<ee: E,aa: V,rr: V> 
  Purestd/core/hnd/Pure: forall<e,a,b> yld<e,a,b>
  YieldingFinalstd/core/hnd/YieldingFinal: forall<e,a,b> yld<e,a,b>
  Yieldingstd/core/hnd/Yielding: forall<e,a,b> yld<e,a,b>
  Yieldstd/core/hnd/Yield: forall<e,a,b,c> (clause : ((resume-result<c,b>) -> e b) -> e b, cont : (() -> c) -> e a) -> yld<e,a,b><bb: V>(clauseclause: ((resume-result<110,109>) -> 107 109) -> 107 109 : (resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> ee: E rr: V) -> ee: E rr: V, contcont: (() -> 110) -> 107 108 : (() -> bstd/core/types/(<>): E) -> ee: E aa: V)

extern guardstd/core/hnd/guard: forall<e> (w : evv<e>) -> e ()(ww: evv<$3902> : evvstd/core/hnd/evv: E -> V<ee: E> ) : ee: E (std/core/types/(): V)std/core/types/(): V 
  c  inline "kk_evv_guard(#1,kk_context())"
  js "_guard"

extern resume-finalstd/core/hnd/resume-final: forall<a> () -> a() : astd/core/types/(<>): E 
  c  inline "kk_fatal_resume_final(kk_context())"
  js "_throw_resume_final"

fun promptstd/core/hnd/prompt: forall<a,e,b,c> (w0 : evv<e>, w1 : evv<e>, ev : ev<b>, m : marker<e,c>, ret : (a) -> e c, result : a) -> e c( w0w0: evv<$4549> : evvstd/core/hnd/evv: E -> V<e0e0: E>,  w1w1: evv<$4549> : evvstd/core/hnd/evv: E -> V<e0e0: E>, evev: ev<$4550> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, mm: marker<$4549,$4551> : markerstd/core/hnd/marker: (E, V) -> V<e0e0: E,rr: V>, retret: ($4548) -> $4549 $4551: aa: V -> e0e0: E rr: V, resultresult: $4548 : aa: V ) : e0e0: E rr: V
  guardstd/core/hnd/guard: forall<e> (w : evv<e>) -> e ()(w1w1: evv<$4549>)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<$4549>)  // restore the previous evidence vector
  match yield-promptstd/core/hnd/yield-prompt: forall<a,e,b> (m : marker<e,b>) -> yld<e,a,b>(mm: marker<$4549,$4551>)
    Purestd/core/hnd/Pure: forall<e,a,b> yld<e,a,b> -> 
      // returning
      retret: ($4548) -> $4549 $4551(resultresult: $4548)
    YieldingFinalstd/core/hnd/YieldingFinal: forall<e,a,b> yld<e,a,b> -> 
      // yielding final (exception), keep yielding
      keep-yielding-finalstd/core/hnd/keep-yielding-final: forall<e,a> () -> e a()
    Yieldingstd/core/hnd/Yielding: forall<e,a,b> yld<e,a,b> -> 
      // regular yield, install a continuation
      yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b fn(contcont: ($4586) -> $4549 $4548,resres: $4586)
        // we resume, continue under a fresh a prompt again
        val w0'w0': evv<$4549> = evv-getstd/core/hnd/evv-get: forall<e> () -> e evv<e>()  // if not using scoped resumptions, w0' may be different from w0
        val w1'w1': evv<$4549> = if (evv-eqstd/core/hnd/evv-eq: forall<e> (evv0 : evv<e>, evv1 : evv<e>) -> bool(w0w0: evv<$4549>,w0'w0': evv<$4549>)) then w1w1: evv<$4549> else evv-insertstd/core/hnd/evv-insert: forall<e,e1,a> (evv : evv<e>, ev : ev<a>) -> e evv<e1>(w0'w0': evv<$4549>,evev: ev<$4550>)
        evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w1'w1': evv<$4549>)
        promptstd/core/hnd/prompt: forall<a,e,b,c> (w0 : evv<e>, w1 : evv<e>, ev : ev<b>, m : marker<e,c>, ret : (a) -> e c, result : a) -> e c(w0'w0': evv<$4549>,w1'w1': evv<$4549>,evev: ev<$4550>,unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(mm: marker<$4549,$4551>),retret: ($4548) -> $4549 $4551,contcont: ($4586) -> $4549 $4548(resres: $4586));      
    Yieldstd/core/hnd/Yield: forall<e,a,b,c> (clause : ((resume-result<c,b>) -> e b) -> e b, cont : (() -> c) -> e a) -> yld<e,a,b>(clauseclause: ((resume-result<$4628,$4551>) -> $4549 $4551) -> $4549 $4551,contcont: (() -> $4628) -> $4549 $4548) -> 
      // yielded to the operation `clause` in our handler
      fun resumeresume: (r : resume-result<$4628,$4551>) -> $4549 $4551(rr: resume-result<$4628,$4551>) 
        match(rr: resume-result<$4628,$4551>) 
          Deepstd/core/hnd/Deep: forall<a,b> (result : a) -> resume-result<a,b>(xx: $4628) -> 
            val w0'w0': evv<$4549> = evv-getstd/core/hnd/evv-get: forall<e> () -> e evv<e>()  // if not using scoped resumptions, w0' may be different from w0
            val w1'w1': evv<$4549> = if evv-eqstd/core/hnd/evv-eq: forall<e> (evv0 : evv<e>, evv1 : evv<e>) -> bool(w0w0: evv<$4549>,w0'w0': evv<$4549>) then w1w1: evv<$4549> else evv-insertstd/core/hnd/evv-insert: forall<e,e1,a> (evv : evv<e>, ev : ev<a>) -> e evv<e1>(w0'w0': evv<$4549>,evev: ev<$4550>)
            evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w1'w1': evv<$4549>)
            promptstd/core/hnd/prompt: forall<a,e,b,c> (w0 : evv<e>, w1 : evv<e>, ev : ev<b>, m : marker<e,c>, ret : (a) -> e c, result : a) -> e c(w0'w0': evv<$4549>,w1'w1': evv<$4549>,evev: ev<$4550>,unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(mm: marker<$4549,$4551>),retret: ($4548) -> $4549 $4551,contcont: (() -> $4628) -> $4549 $4548({xx: $4628}))
          Shallowstd/core/hnd/Shallow: forall<a,b> (result : a) -> resume-result<a,b>(xx: $4628) -> 
            yield-bindstd/core/hnd/yield-bind: forall<a,b,e> (x : a, next : (a) -> e b) -> e b( contcont: (() -> $4628) -> $4549 $4548({xx: $4628}), fn(yy: $4548) retret: ($4548) -> $4549 $4551(yy: $4548) )
          Finalizestd/core/hnd/Finalize: forall<a,b> (result : b) -> resume-result<a,b>(xx: $4551) -> 
            val w0'w0': evv<$4549> = evv-getstd/core/hnd/evv-get: forall<e> () -> e evv<e>()  // if not using scoped resumptions, w0' may be different from w0
            val w1'w1': evv<$4549> = if evv-eqstd/core/hnd/evv-eq: forall<e> (evv0 : evv<e>, evv1 : evv<e>) -> bool(w0w0: evv<$4549>,w0'w0': evv<$4549>) then w1w1: evv<$4549> else evv-insertstd/core/hnd/evv-insert: forall<e,e1,a> (evv : evv<e>, ev : ev<a>) -> e evv<e1>(w0'w0': evv<$4549>,evev: ev<$4550>)
            evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w1'w1': evv<$4549>)
            promptstd/core/hnd/prompt: forall<a,e,b,c> (w0 : evv<e>, w1 : evv<e>, ev : ev<b>, m : marker<e,c>, ret : (a) -> e c, result : a) -> e c(w0'w0': evv<$4549>,w1'w1': evv<$4549>,evev: ev<$4550>,unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(mm: marker<$4549,$4551>),retret: ($4548) -> $4549 $4551,contcont: (() -> $4628) -> $4549 $4548({ yield-to-finalstd/core/hnd/yield-to-final: forall<a,e,e1,b> (m : marker<e1,b>, clause : ((resume-result<a,b>) -> e1 b) -> e1 b) -> e a(mm: marker<$4549,$4551>, fn(_k) xx: $4551) }))            
      clauseclause: ((resume-result<$4628,$4551>) -> $4549 $4551) -> $4549 $4551(resumeresume: (r : resume-result<$4628,$4551>) -> $4549 $4551) // TODO: we should exit prompt first, and then execute clause to use constant stack space when resuming

pub noinline fun ".hhandle"( tagtag: htag<$4769>:htagstd/core/hnd/htag: ((E, V) -> V) -> V<hh: (E, V) -> V>, cfccfc: cfc: cfcstd/core/hnd/cfc: V, hh: $4769<$4767,$4770> : hh: (E, V) -> V<ee: E,rr: V>, retret: ($4766) -> $4767 $4770: aa: V -> ee: E rr: V, actionaction: () -> $4768 $4766 : () -> e1e1: E aa: V ) : ee: E rr: V 
  // insert new evidence for our handler
  val w0w0: evv<$4767> = evv-getstd/core/hnd/evv-get: forall<e> () -> e evv<e>()
  val mm: marker<$4767,$4770>  = fresh-markerstd/core/hnd/fresh-marker: forall<e,a> () -> marker<e,a>()
  val evev: ev<$4769> = Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a>(tagtag: htag<$4769>,mm: marker<$4767,$4770>,hh: $4769<$4767,$4770>,cfccfc: cfc,w0w0: evv<$4767>)
  val w1w1: evv<$4767> = evv-insertstd/core/hnd/evv-insert: forall<e,e1,a> (evv : evv<e>, ev : ev<a>) -> e evv<e1>(w0w0: evv<$4767>,evev: ev<$4769>)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w1w1: evv<$4767>)
  // call action first (this may be yielding), then check the result
  promptstd/core/hnd/prompt: forall<a,e,b,c> (w0 : evv<e>, w1 : evv<e>, ev : ev<b>, m : marker<e,c>, ret : (a) -> e c, result : a) -> e c(w0w0: evv<$4767>,w1w1: evv<$4767>,evev: ev<$4769>,mm: marker<$4767,$4770>,retret: ($4766) -> $4767 $4770,cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1> (f : () -> e1 a) -> (() -> e a)(actionaction: () -> $4768 $4766)())

// -------------------------------------------
// named handler
// -------------------------------------------

pub noinline fun ".named-handle"( tagtag: htag<$5092>:htagstd/core/hnd/htag: ((E, V) -> V) -> V<hh: (E, V) -> V>, cfccfc: cfc: cfcstd/core/hnd/cfc: V, hh: $5092<$5090,$5093> : hh: (E, V) -> V<ee: E,rr: V>, retret: ($5089) -> $5090 $5093: aa: V -> ee: E rr: V, actionaction: (ev<$5092>) -> $5091 $5089 : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V> -> e1e1: E aa: V ) : ee: E rr: V 
  val mm: marker<$5090,$5093> = fresh-marker-namedstd/core/hnd/fresh-marker-named: forall<e,a> () -> marker<e,a>()            // unique (negative) marker, but never gets inserted into the evidence vector
  val w0w0: evv<$5090> = evv-getstd/core/hnd/evv-get: forall<e> () -> e evv<e>()
  val evev: ev<$5092> = Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a>(tagtag: htag<$5092>,mm: marker<$5090,$5093>,hh: $5092<$5090,$5093>,cfccfc: cfc,w0w0: evv<$5090>)
  promptstd/core/hnd/prompt: forall<a,e,b,c> (w0 : evv<e>, w1 : evv<e>, ev : ev<b>, m : marker<e,c>, ret : (a) -> e c, result : a) -> e c(w0w0: evv<$5090>,w0w0: evv<$5090>,evev: ev<$5092>,mm: marker<$5090,$5093>,retret: ($5089) -> $5090 $5093,cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(actionaction: (ev<$5092>) -> $5091 $5089)(evev: ev<$5092>))

// -------------------------------------------
// mask
// -------------------------------------------

fun mask-at1std/core/hnd/mask-at1: forall<a,b,e,e1> (i : ev-index, behind : bool, action : (a) -> e b, x : a) -> e1 b( ii: ev-index : ev-indexstd/core/hnd/ev-index: V, behindbehind: bool : boolstd/core/types/bool: V, actionaction: ($4865) -> $4867 $4866 : (aa: V) -> e1e1: E bb: V, xx: $4865 : aa: V ) : e2e2: E bb: V 
  val w0w0: evv<_4869> = evv-swap-deletestd/core/hnd/evv-swap-delete: forall<e,e1> (i : ev-index, behind : bool) -> e1 evv<e>(ii: ev-index,behindbehind: bool)
  val yy: $4866 = cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(actionaction: ($4865) -> $4867 $4866)(xx: $4865)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_4869>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $4866 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($4941) -> $4868 $4866,resres: $4941) mask-at1std/core/hnd/mask-at1: forall<a,b,e,e1> (i : ev-index, behind : bool, action : (a) -> e b, x : a) -> e1 b(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(ii: ev-index),behindbehind: bool,contcont: ($4941) -> $4868 $4866,resres: $4941) )std/core/types/(): ()
  yy: $4866

pub fun ".mask-at"<aa: V,e1e1: E,e2e2: E>( ii: ev-index : ev-indexstd/core/hnd/ev-index: V, behindbehind: bool : boolstd/core/types/bool: V, actionaction: () -> $4979 $4978 : () -> e1e1: E aa: V ) : e2e2: E aa: V 
  val w0w0: evv<_4981> = evv-swap-deletestd/core/hnd/evv-swap-delete: forall<e,e1> (i : ev-index, behind : bool) -> e1 evv<e>(ii: ev-index,behindbehind: bool)
  val xx: $4978 = cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1> (f : () -> e1 a) -> (() -> e a)(actionaction: () -> $4979 $4978)()
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_4981>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $4978 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($5042) -> $4980 $4978,resres: $5042) mask-at1std/core/hnd/mask-at1: forall<a,b,e,e1> (i : ev-index, behind : bool, action : (a) -> e b, x : a) -> e1 b(ii: ev-index,behindbehind: bool,contcont: ($5042) -> $4980 $4978,resres: $5042) )std/core/types/(): ()
  xx: $4978

// mask for builtin effects without a handler or evidence
pub fun ".mask-builtin"<aa: V,e1e1: E,e2e2: E>( actionaction: () -> $3158 $3157 : () -> e1e1: E aa: V ) : e2e2: E aa: V 
  cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1> (f : () -> e1 a) -> (() -> e a)(actionaction: () -> $3158 $3157)()


// -------------------------------------------
// Local variables
// -------------------------------------------

fun prompt-local-varstd/core/hnd/prompt-local-var: forall<a,b,h> (loc : local-var<h,a>, res : b) -> <div,local<h>> b(locloc: local-var<$10372,$10369>:local-varstd/core/types/local-var: (H, V) -> V<ss: H,aa: V>, resres: $10370 : bb: V  ) : <divstd/core/types/div: X,localstd/core/types/local: H -> X<ss: H>|std/core/types/(<|>): (X, E) -> Eee: E> bb: V 
  if !std/core/types/(!).1: (b : bool) -> boolyieldingstd/core/hnd/yielding: () -> bool() returnreturn: $10370 resres: $10370;
  val vv: $10369 = locloc: $10369
  yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($10416) -> <div,local<$10372>|$10371> $10370,xx: $10416){ locloc: local-var<$10372,$10369> :=std/core/types/local-set: forall<a,e,h> (v : local-var<h,a>, assigned : a) -> <local<h>|e> () vv: $10369; prompt-local-varstd/core/hnd/prompt-local-var: forall<a,b,e,h> (loc : local-var<h,a>, res : b) -> <div,local<h>|e> b(byref(locloc: local-var<$10372,$10369>),contcont: ($10416) -> <div,local<$10372>|$10371> $10370(xx: $10416)) } )  // restore state early before the resume

pub inline fun local-varstd/core/hnd/local-var: forall<a,b,e,h> (init : a, action : (l : local-var<h,a>) -> <local<h>|e> b) -> <local<h>|e> b(initinit: $10465:aa: V, actionaction: (l : local-var<$10468,$10465>) -> <local<$10468>|$10467> $10466: (l:local-varstd/core/types/local-var: (H, V) -> V<ss: H,aa: V>) -> <localstd/core/types/local: H -> X<ss: H>|std/core/types/(<|>): (X, E) -> Eee: E> bb: V ) : <localstd/core/types/local: H -> X<ss: H>|std/core/types/(<|>): (X, E) -> Eee: E> bb: V 
  unsafe-no-divstd/core/types/unsafe-no-div: forall<a,e> (action : () -> <div|e> a) -> e a 
    val locloc: local-var<$10468,$10465> : local-varstd/core/types/local-var: (H, V) -> V<__w-l359-c25: H,__w-l359-c27: V> = local-newstd/core/types/local-new: forall<a,e,h> (value : a) -> <local<h>|e> local-var<h,a>(initinit: $10465)
    val resres: $10466 = cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(actionaction: (l : local-var<$10468,$10465>) -> <local<$10468>|$10467> $10466)(byref(locloc: local-var<$10468,$10465>))
    prompt-local-varstd/core/hnd/prompt-local-var: forall<a,b,h> (loc : local-var<h,a>, res : b) -> <div,local<h>> b(byref(locloc: local-var<$10468,$10465>),resres: $10466)


// -------------------------------------------
// Finally
// -------------------------------------------

pub fun finallystd/core/hnd/finally: forall<a,e> (fin : () -> e (), action : () -> e a) -> e a( finfin: () -> $10180 () : () -> ee: E (std/core/types/(): V)std/core/types/(): V, actionaction: () -> $10180 $10179 : () -> ee: E aa: V ) : ee: E aa: V 
  finally-promptstd/core/hnd/finally-prompt: forall<a,e> (fin : () -> e (), res : a) -> e a(finfin: () -> $10180 (), actionaction: () -> $10180 $10179());

fun finally-promptstd/core/hnd/finally-prompt: forall<a,e> (fin : () -> e (), res : a) -> e a(finfin: () -> $10090 () : () -> ee: E (std/core/types/(): V)std/core/types/(): V, resres: $10089 : aa: V ) : ee: E aa: V 
  if !std/core/types/(!).1: (b : bool) -> boolyieldingstd/core/hnd/yielding: () -> bool() then 
    finfin: () -> $10090 ()()
    resres: $10089
  elif yielding-non-finalstd/core/hnd/yielding-non-final: () -> bool() then 
    yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($10128) -> $10090 $10089,xx: $10128){ finally-promptstd/core/hnd/finally-prompt: forall<a,e> (fin : () -> e (), res : a) -> e a(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(finfin: () -> $10090 ()),contcont: ($10128) -> $10090 $10089(xx: $10128)) })
  else 
    val yldyld: yield-info = yield-capturestd/core/hnd/yield-capture: forall<e> () -> e yield-info()
    finfin: () -> $10090 ()()
    if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $10089 yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b( fn(_x) unsafe-reyieldstd/core/hnd/unsafe-reyield: forall<a,e> (yld : yield-info) -> e a(yldyld: yield-info) )std/core/types/(): ()
    unsafe-reyieldstd/core/hnd/unsafe-reyield: forall<a,e> (yld : yield-info) -> e a(yldyld: yield-info)

/*
fun finalize(cont : (() -> b) -> e r, res : a) : e a 
  val m : marker<_e,_r> = fresh-marker()
  val w = evv-get()
  prompt(w,w,ev-none(),m,id, yield-bind( cont({ yield-to-final(m,fn(_k) res) }), fn(_x) res ))  // TODO: special prompt that does not insert on resume?
*/

// -------------------------------------------
// Initially
// -------------------------------------------

// add integers
inline extern addstd/core/hnd/add: (i : int, j : int) -> int(i : intstd/core/types/int: V, j : intstd/core/types/int: V) : intstd/core/types/int: V 
  c  "kk_integer_add"
  cs inline "(#1 + #2)"
  js inline "(#1 + #2)" // "$std_core._int_add"

// are two integers equal?
inline extern eqstd/core/hnd/eq: (x : int, y : int) -> bool( ^x : intstd/core/types/int: V, ^y : intstd/core/types/int: V) : boolstd/core/types/bool: V  
  c  "kk_integer_eq_borrow"
  cs inline "(#1 == #2)"
  js inline "(#1 == #2)" // $std_core._int_eq"


pub fun initiallystd/core/hnd/initially: forall<a,e> (init : (int) -> e (), action : () -> e a) -> e a(initinit: (int) -> $10334 () : (intstd/core/types/int: V) -> ee: E (std/core/types/(): V)std/core/types/(): V, actionaction: () -> $10334 $10333 : () -> ee: E aa: V ) : ee: E aa: V 
  initinit: (int) -> $10334 ()(0)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $10333 yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b(fn(_ret:(std/core/types/(): V)std/core/types/(): V) initially-promptstd/core/hnd/initially-prompt: forall<a,e> (init : (int) -> e (), res : a) -> e a(initinit: (int) -> $10334 (),actionaction: () -> $10334 $10333()) )std/core/types/(): ()
  initially-promptstd/core/hnd/initially-prompt: forall<a,e> (init : (int) -> e (), res : a) -> e a(initinit: (int) -> $10334 (), actionaction: () -> $10334 $10333() )

fun initially-promptstd/core/hnd/initially-prompt: forall<a,e> (init : (int) -> e (), res : a) -> e a( initinit: (int) -> $10194 () : (intstd/core/types/int: V) -> ee: E (std/core/types/(): V)std/core/types/(): V, resres: $10193 : aa: V ) : ee: E aa: V 
  if yielding-non-finalstd/core/hnd/yielding-non-final: () -> bool() then 
    val countcount: ref<global,int> = unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){refstd/core/types/ref: forall<a,h> (value : a) -> (alloc<h>) ref<h,a>(0)}()
    yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($10215) -> $10194 $10193,xx: $10215)
      val cntcnt: int = unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){ !std/core/types/(!): forall<h,a,e> (ref : ref<h,a>) -> <read<h>|e> a with hdiv<h,a,e>countcount: ref<global,int> }()    // increase counter on every resumption
      unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){ countcount: ref<global,int> :=std/core/types/set: forall<a,h> (ref : ref<h,a>, assigned : a) -> (write<h>) () addstd/core/hnd/add: (i : int, j : int) -> int(cntcnt: int,1) }()
      if eqstd/core/hnd/eq: (x : int, y : int) -> bool(cntcnt: int,0) then (std/core/types/(): ())std/core/types/(): () else   // for every resume after the first, run the initializer
        val rr: () = initinit: (int) -> $10194 ()(cntcnt: int)
        if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $10193 yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b( fn(_ret) initially-promptstd/core/hnd/initially-prompt: forall<a,e> (init : (int) -> e (), res : a) -> e a(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(initinit: (int) -> $10194 ()), contcont: ($10215) -> $10194 $10193(xx: $10215)) )std/core/types/(): ()
      initially-promptstd/core/hnd/initially-prompt: forall<a,e> (init : (int) -> e (), res : a) -> e a(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(initinit: (int) -> $10194 ()), contcont: ($10215) -> $10194 $10193(xx: $10215))
    )
  else resres: $10193


// -------------------------------------------
// Resume context
// -------------------------------------------

abstract struct resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E::E,e0e0: E::E,rr: V>( kk: (resume-result<89,92>) -> 90 92 : resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> ee: E rr: V )

pub fun resumestd/core/hnd/resume: forall<a,e,e1,b> (r : resume-context<a,e,e1,b>, x : a) -> e b( rr: resume-context<$4380,$4381,$4382,$4383> : resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E,e0e0: E,rr: V>, xx: $4380 : bb: V ) : ee: E rr: V 
  (rr: resume-context<$4380,$4381,$4382,$4383>.kstd/core/hnd/k: forall<a,e,e1,b> (resume-context<a,e,e1,b>) -> ((resume-result<a,b>) -> e b))(Deepstd/core/hnd/Deep: forall<a,b> (result : a) -> resume-result<a,b>(xx: $4380))

pub fun resume-shallowstd/core/hnd/resume-shallow: forall<a,e,e1,b> (r : resume-context<a,e,e1,b>, x : a) -> e1 b( rr: resume-context<$4418,$4419,$4420,$4421> : resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E,e0e0: E,rr: V>, xx: $4418 : bb: V ) : e0e0: E rr: V 
  cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(rr: resume-context<$4418,$4419,$4420,$4421>.kstd/core/hnd/k: forall<a,e,e1,b> (resume-context<a,e,e1,b>) -> ((resume-result<a,b>) -> e b))(Shallowstd/core/hnd/Shallow: forall<a,b> (result : a) -> resume-result<a,b>(xx: $4418))


pub fun finalizestd/core/hnd/finalize: forall<a,e,e1,b> (r : resume-context<a,e,e1,b>, x : b) -> e b( rr: resume-context<$6881,$6882,$6883,$6884> : resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E,e0e0: E,rr: V>, xx: $6884 : rr: V ) : ee: E rr: V 
  //finalize(r.k,x)
  (rr: resume-context<$6881,$6882,$6883,$6884>.kstd/core/hnd/k: forall<a,e,e1,b> (resume-context<a,e,e1,b>) -> ((resume-result<a,b>) -> e b))(Finalizestd/core/hnd/Finalize: forall<a,b> (result : b) -> resume-result<a,b>(xx: $6884))

// -------------------------------------------
// Clauses
// -------------------------------------------

abstract type clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,ee: E::E,rr: V> 
  Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>( clauseclause: (marker<54,55>, ev<53>, 51) -> 54 52: (markerstd/core/hnd/marker: (E, V) -> V<ee: E,rr: V>, evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, aa: V) -> ee: E bb: V )

inline extern cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1,b,c> (f : (marker<e1,c>, ev<b>) -> e1 a) -> e ((marker<e1,c>, ev<b>) -> e a)( f : (markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>,evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>) -> e1e1: E bb: V) : ee: E ((markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>,evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>) -> ee: E bb: V)  
  inline "#1"
  
inline extern cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1,c,d> (f : (marker<e1,d>, ev<c>, a) -> e1 b) -> e ((marker<e1,d>, ev<c>, a) -> e b)( f : (markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>,evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>,aa: V) -> e1e1: E bb: V) : ee: E ((markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>,evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>,aa: V) -> ee: E bb: V) 
  inline "#1"
  
inline extern cast-ev2std/core/hnd/cast-ev2: forall<a,b,c,e,e1,d,a1> (f : (marker<e1,a1>, ev<d>, a, b) -> e1 c) -> e ((marker<e1,a1>, ev<d>, a, b) -> e c)( f : (markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>,evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>,a1a1: V,a2a2: V) -> e1e1: E bb: V) : ee: E ((markerstd/core/hnd/marker: (E, V) -> V<e1e1: E,rr: V>,evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>,a1a1: V,a2a2: V) -> ee: E bb: V) 
  inline "#1"

  
pub inline fun ".perform1"( evev: ev<$3638> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: forall<e,a> ($3638<e,a>) -> clause1<$3635,$3636,$3638,e,a> : (forall<e1e1: E,rr: V> hh: (E, V) -> V<e1e1: E,rr: V> -> clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,e1e1: E,rr: V>), xx: $3635 : aa: V ) : ee: E bb: V 
  match evev: ev<$3638>
    Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a>(_tag,mm: marker<$3641,$3642>,hh: $3638<$3641,$3642>,_c,_w) -> match hh: $3638<$3641,$3642>.opop: forall<e,a> ($3638<e,a>) -> clause1<$3635,$3636,$3638,e,a> 
      Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>(ff: (marker<$3641,$3642>, ev<$3638>, $3635) -> $3641 $3636) -> cast-ev1std/core/hnd/cast-ev1.1: forall<a,b,e,e1,c,d> (f : (marker<e1,d>, ev<c>, a) -> e1 b) -> e ((marker<e1,d>, ev<c>, a) -> e b)(ff: (marker<$3641,$3642>, ev<$3638>, $3635) -> $3641 $3636)(mm: marker<$3641,$3642>,evev: ev<$3638>,xx: $3635)

fun evv-swap-withstd/core/hnd/evv-swap-with: forall<a,e> (ev : ev<a>) -> evv<e>(evev: ev<$4246> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>) 
  match(evev: ev<$4246>) 
    Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a>(_tag,_m,_h,_c,ww: evv<$4249>) -> evv-swapstd/core/hnd/evv-swap: forall<e,e1,e2> (w : evv<e1>) -> e evv<e2>(ww: evv<$4249>)

inline fun under1std/core/hnd/under1: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b( evev: ev<$9258> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: ($9255) -> $9257 $9256 : aa: V -> ee: E bb: V, xx: $9255 : aa: V ) : ee: E bb: V 
  val w0w0: evv<_9260> = evv-swap-withstd/core/hnd/evv-swap-with: forall<a,e> (ev : ev<a>) -> evv<e>(evev: ev<$9258>)
  val yy: $9256 = opop: ($9255) -> $9257 $9256(xx: $9255)
  // evv-set(w0)   // only needed before yielding for evidence expected check in prompt
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $9256 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($9276) -> $9257 $9256,resres: $9276) under1xstd/core/hnd/under1x: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(evev: ev<$9258>),contcont: ($9276) -> $9257 $9256,resres: $9276) )std/core/types/(): ()
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_9260>)
  yy: $9256

// extra under1x to make under1 inlineable
noinline fun under1xstd/core/hnd/under1x: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b( evev: ev<$9197> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: ($9194) -> $9196 $9195 : aa: V -> ee: E bb: V, xx: $9194 : aa: V ) : ee: E bb: V 
  val w0w0: evv<_9199> = evv-swap-withstd/core/hnd/evv-swap-with: forall<a,e> (ev : ev<a>) -> evv<e>(evev: ev<$9197>)
  val yy: $9195 = opop: ($9194) -> $9196 $9195(xx: $9194)
  // evv-set(w0)   // only needed before yielding for evidence expected check in prompt
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $9195 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($9215) -> $9196 $9195,resres: $9215) under1xstd/core/hnd/under1x: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(evev: ev<$9197>),contcont: ($9215) -> $9196 $9195,resres: $9215) )std/core/types/(): ()
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_9199>)
  yy: $9195

pub fun clause-control-raw1std/core/hnd/clause-control-raw1: forall<a,b,e,e1,c,d> (op : (x : a, r : resume-context<b,e,e1,d>) -> e d) -> clause1<a,b,c,e,d>( opop: (x : $6535, r : resume-context<$6536,$6537,$6538,$6540>) -> $6537 $6540 : (x:aa: V, r: resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E,e0e0: E,rr: V>) -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>(fn(mm: marker<$6537,$6540>,_ev,xx: $6535){ yield-tostd/core/hnd/yield-to: forall<a,e,b> (m : marker<e,b>, clause : ((resume-result<a,b>) -> e b) -> e b) -> e a(mm: marker<$6537,$6540>, fn(kk: (resume-result<$6536,$6540>) -> $6537 $6540){ opop: (x : $6535, r : resume-context<$6536,$6537,$6538,$6540>) -> $6537 $6540(xx: $6535,Resume-contextstd/core/hnd/Resume-context: forall<a,e,e1,b> (k : (resume-result<a,b>) -> e b) -> resume-context<a,e,e1,b>(kk: (resume-result<$6536,$6540>) -> $6537 $6540)) } ) } )

fun getstd/core/hnd/get: forall<a,h> (ref : ref<h,a>) -> <read<h>,div> a( refref: ref<$4327,$4326>: refstd/core/types/ref: (H, V) -> V<hh: H,aa: V>) : <std/core/types/(<>): Ereadstd/core/types/read: H -> X<hh: H>,divstd/core/types/div: X> aa: V 
  !std/core/types/(!): forall<h,a,e> (ref : ref<h,a>) -> <read<h>|e> a with hdiv<h,a,e>refref: ref<$4327,$4326>

inline extern unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a)(f : () -> <ststd/core/types/st: H -> E<globalstd/core/types/global: H>|ee: E> aa: V ) : ((std/core/types/(<>): E) -> ee: E aa: V) 
  inline "#1"

fun protect-checkstd/core/hnd/protect-check: forall<a,e,b> (resumed : ref<global,bool>, k : (resume-result<a,b>) -> e b, res : b) -> e b( resumedresumed: ref<global,bool> : refstd/core/types/ref: (H, V) -> V<globalstd/core/types/global: H,boolstd/core/types/bool: V>,  kk: (resume-result<$6916,$6918>) -> $6917 $6918 : resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> ee: E rr: V, resres: $6918 : rr: V ) : ee: E rr: V 
  val did-resumedid-resume: bool : boolstd/core/types/bool: V = (unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){ !std/core/types/(!): forall<h,a,e> (ref : ref<h,a>) -> <read<h>|e> a with hdiv<h,a,e>resumedresumed: ref<global,bool> })()
  if !std/core/types/(!).1: (b : bool) -> booldid-resumedid-resume: bool
   then kk: (resume-result<$6916,$6918>) -> $6917 $6918(Finalizestd/core/hnd/Finalize: forall<a,b> (result : b) -> resume-result<a,b>(resres: $6918)) //finalize(k,res)
   else resres: $6918

fun protectstd/core/hnd/protect: forall<a,b,e,c> (x : a, clause : (x : a, k : (b) -> e c) -> e c, k : (resume-result<b,c>) -> e c) -> e c( xx: $7003 : aa: V, clauseclause: (x : $7003, k : ($7004) -> $7005 $7006) -> $7005 $7006 : (x:aa: V, k: bb: V -> ee: E rr: V) -> ee: E rr: V, kk: (resume-result<$7004,$7006>) -> $7005 $7006 : resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> ee: E rr: V ) : ee: E rr: V 
  val resumedresumed: ref<global,bool> = (unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){refstd/core/types/ref: forall<a,h> (value : a) -> (alloc<h>) ref<h,a>(Falsestd/core/types/False: bool)})()
  fun kprotectkprotect: (ret : $7004) -> $7005 $7006(retret: $7004) 
    (unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){resumedresumed: ref<global,bool> :=std/core/types/set: forall<a,h> (ref : ref<h,a>, assigned : a) -> (write<h>) () Truestd/core/types/True: bool})()
    kk: (resume-result<$7004,$7006>) -> $7005 $7006(Deepstd/core/hnd/Deep: forall<a,b> (result : a) -> resume-result<a,b>(retret: $7004))
  val resres: $7006 = clauseclause: (x : $7003, k : ($7004) -> $7005 $7006) -> $7005 $7006(xx: $7003,kprotectkprotect: (ret : $7004) -> $7005 $7006)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $7006 yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b( fn(xresxres: $7006) protect-checkstd/core/hnd/protect-check: forall<a,e,b> (resumed : ref<global,bool>, k : (resume-result<a,b>) -> e b, res : b) -> e b(resumedresumed: ref<global,bool>,kk: (resume-result<$7004,$7006>) -> $7005 $7006,xresxres: $7006) )std/core/types/(): ()
  protect-checkstd/core/hnd/protect-check: forall<a,e,b> (resumed : ref<global,bool>, k : (resume-result<a,b>) -> e b, res : b) -> e b(resumedresumed: ref<global,bool>,kk: (resume-result<$7004,$7006>) -> $7005 $7006,resres: $7006)

/*
pub fun clause-control1( clause : (x:a, k: b -> e r) -> e r ) : clause1<a,b,e,r> 
  Clause1(fn(m,w,x){ yield-to(m, fn(k){ clause(x, fn(r){ k({r}) } ) }) })
*/

pub fun clause-control1std/core/hnd/clause-control1: forall<a,b,e,c,d> (clause : (x : a, k : (b) -> e d) -> e d) -> clause1<a,b,c,e,d>( clauseclause: (x : $7288, k : ($7289) -> $7290 $7292) -> $7290 $7292 : (x:aa: V, k: bb: V -> ee: E rr: V) -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>(fn(mm: marker<$7290,$7292>,_ev,xx: $7288){ yield-tostd/core/hnd/yield-to: forall<a,e,b> (m : marker<e,b>, clause : ((resume-result<a,b>) -> e b) -> e b) -> e a(mm: marker<$7290,$7292>, fn(kk: (resume-result<$7289,$7292>) -> $7290 $7292) protectstd/core/hnd/protect: forall<a,b,e,c> (x : a, clause : (x : a, k : (b) -> e c) -> e c, k : (resume-result<b,c>) -> e c) -> e c(xx: $7288,clauseclause: (x : $7288, k : ($7289) -> $7290 $7292) -> $7290 $7292,kk: (resume-result<$7289,$7292>) -> $7290 $7292) ) })

pub fun clause-tail1std/core/hnd/clause-tail1: forall<e,a,b,c,d> (op : (b) -> e c) -> clause1<b,c,d,e,a><ee: E,rr: V,aa: V,bb: V>(opop: ($9402) -> $9400 $9403 : aa: V -> ee: E bb: V) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>(fn(_m,evev: ev<$9404>,xx: $9402){ under1std/core/hnd/under1: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b(evev: ev<$9404>,opop: ($9402) -> $9400 $9403,xx: $9402) })

pub fun clause-tail-noyield1std/core/hnd/clause-tail-noyield1: forall<e,a,b,c,d> (op : (b) -> e c) -> clause1<b,c,d,e,a><ee: E,rr: V,aa: V,bb: V>(opop: ($4178) -> $4176 $4179 : aa: V -> ee: E bb: V) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>(fn(_m,_ev,xx: $4178){ opop: ($4178) -> $4176 $4179(xx: $4178) })

pub fun clause-never1std/core/hnd/clause-never1: forall<a,b,e,c,d> (op : (a) -> e d) -> clause1<a,b,c,e,d>( opop: ($8024) -> $8026 $8028 : aa: V -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>(fn(mm: marker<$8026,$8028>,_ev,xx: $8024){ yield-to-finalstd/core/hnd/yield-to-final: forall<a,e,e1,b> (m : marker<e1,b>, clause : ((resume-result<a,b>) -> e1 b) -> e1 b) -> e a(mm: marker<$8026,$8028>, fn(_k) opop: ($8024) -> $8026 $8028(xx: $8024) ) })

//----------------------------------------------------------------
// 0 arguments; reuse 1 argument Clauses
//----------------------------------------------------------------

abstract type clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>( clauseclause: (marker<39,40>, ev<38>) -> 39 37: (markerstd/core/hnd/marker: (E, V) -> V<ee: E,rr: V>, evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>) -> ee: E bb: V )


//inline extern cast-hnd( h : h<e1,r> ) : e h<e,r> { inline "#1"//inline extern cast-marker( m : marker<e1,r> ) : e marker<e,r> { inline "#1"
pub inline fun ".perform0"( evev: ev<$3548> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: forall<e,a> ($3548<e,a>) -> clause0<$3546,$3548,e,a> : (forall<e1e1: E,rr: V> hh: (E, V) -> V<e1e1: E,rr: V> -> clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,e1e1: E,rr: V>) ) : ee: E bb: V 
  match evev: ev<$3548>
    Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a>(_tag,mm: marker<$3551,$3552>,hh: $3548<$3551,$3552>,_c,_w) -> match hh: $3548<$3551,$3552>.opop: forall<e,a> ($3548<e,a>) -> clause0<$3546,$3548,e,a> 
      Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>(ff: (marker<$3551,$3552>, ev<$3548>) -> $3551 $3546) -> cast-ev0std/core/hnd/cast-ev0.1: forall<a,e,e1,b,c> (f : (marker<e1,c>, ev<b>) -> e1 a) -> e ((marker<e1,c>, ev<b>) -> e a)(ff: (marker<$3551,$3552>, ev<$3548>) -> $3551 $3546)(mm: marker<$3551,$3552>,evev: ev<$3548>)

inline fun under0std/core/hnd/under0: forall<a,e,b> (ev : ev<b>, op : () -> e a) -> e a( evev: ev<$9318> : evstd/core/hnd/ev: ((E, V) -> V) -> V<ii: (E, V) -> V>, opop: () -> $9317 $9316 : () -> ee: E bb: V) : ee: E bb: V 
  val w0w0: evv<_9320> = evv-swap-withstd/core/hnd/evv-swap-with: forall<a,e> (ev : ev<a>) -> evv<e>(evev: ev<$9318>)
  val yy: $9316 = opop: () -> $9317 $9316()
  // evv-set(w0)   // only needed before yielding for evidence expected check in prompt
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_9320>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $9316 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($9339) -> $9317 $9316,resres: $9339) under1std/core/hnd/under1: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b(evev: ev<$9318>,contcont: ($9339) -> $9317 $9316,resres: $9339) )std/core/types/(): ()
  yy: $9316

pub fun clause-control-raw0std/core/hnd/clause-control-raw0: forall<a,e,e1,b,c> (op : (resume-context<a,e,e1,c>) -> e c) -> clause0<a,b,e,c>( opop: (resume-context<$6492,$6493,$6494,$6496>) -> $6493 $6496 : resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E,e0e0: E,rr: V> -> ee: E rr: V ) : clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>(fn(mm: marker<$6493,$6496>,_ev){ yield-tostd/core/hnd/yield-to: forall<a,e,b> (m : marker<e,b>, clause : ((resume-result<a,b>) -> e b) -> e b) -> e a(mm: marker<$6493,$6496>, fn(kk: (resume-result<$6492,$6496>) -> $6493 $6496){ opop: (resume-context<$6492,$6493,$6494,$6496>) -> $6493 $6496(Resume-contextstd/core/hnd/Resume-context: forall<a,e,e1,b> (k : (resume-result<a,b>) -> e b) -> resume-context<a,e,e1,b>(kk: (resume-result<$6492,$6496>) -> $6493 $6496)) } ) })

/*
pub fun clause-control0( op : (b -> e r) -> e r ) : clause0<b,e,r> 
  Clause0(fn(m,w){ yield-to(m, fn(k){ op(fn(r){ k({r} )}) }) })
*/

pub fun clause-control0std/core/hnd/clause-control0: forall<a,e,b,c> (op : ((a) -> e c) -> e c) -> clause0<a,b,e,c>( opop: (($7217) -> $7218 $7220) -> $7218 $7220 : (bb: V -> ee: E rr: V) -> ee: E rr: V ) : clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>(fn(mm: marker<$7218,$7220>,_ev){ yield-tostd/core/hnd/yield-to: forall<a,e,b> (m : marker<e,b>, clause : ((resume-result<a,b>) -> e b) -> e b) -> e a(mm: marker<$7218,$7220>, fn(kk: (resume-result<$7217,$7220>) -> $7218 $7220){ protectstd/core/hnd/protect: forall<a,b,e,c> (x : a, clause : (x : a, k : (b) -> e c) -> e c, k : (resume-result<b,c>) -> e c) -> e c((std/core/types/(): ())std/core/types/(): (),fn(_x,rr: ($7217) -> $7218 $7220){ opop: (($7217) -> $7218 $7220) -> $7218 $7220(rr: ($7217) -> $7218 $7220) }, kk: (resume-result<$7217,$7220>) -> $7218 $7220) }) })


pub fun clause-tail0std/core/hnd/clause-tail0: forall<e,a,b,c> (op : () -> e b) -> clause0<b,c,e,a><ee: E,rr: V,bb: V>(opop: () -> $9369 $9371 : () -> ee: E bb: V) : clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>(fn(_m,evev: ev<$9372>){ under0std/core/hnd/under0: forall<a,e,b> (ev : ev<b>, op : () -> e a) -> e a(evev: ev<$9372>,opop: () -> $9369 $9371) })

pub fun clause-tail-noyield0std/core/hnd/clause-tail-noyield0: forall<e,a,b,c> (op : () -> e b) -> clause0<b,c,e,a><ee: E,rr: V,bb: V>(opop: () -> $4150 $4152 : () -> ee: E bb: V) : clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>(fn(_m,_ev){ opop: () -> $4150 $4152() })

pub fun clause-valuestd/core/hnd/clause-value: forall<a,e,b,c> (v : a) -> clause0<a,b,e,c>(vv: $4270 : bb: V) : clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>(fn(_m,_ev){ vv: $4270 })

pub fun clause-never0std/core/hnd/clause-never0: forall<a,e,b,c> (op : () -> e c) -> clause0<a,b,e,c>( opop: () -> $7992 $7994 : () -> ee: E rr: V ) : clause0std/core/hnd/clause0: (V, (E, V) -> V, E, V) -> V<bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause0std/core/hnd/Clause0: forall<a,b,e,c> (clause : (marker<e,c>, ev<b>) -> e a) -> clause0<a,b,e,c>(fn(mm: marker<$7992,$7994>,_ev){ yield-to-finalstd/core/hnd/yield-to-final: forall<a,e,e1,b> (m : marker<e1,b>, clause : ((resume-result<a,b>) -> e1 b) -> e1 b) -> e a(mm: marker<$7992,$7994>, fn(_k){ opop: () -> $7992 $7994() }) })

//----------------------------------------------------------------
// 2 arguments
//----------------------------------------------------------------

abstract type clause2std/core/hnd/clause2: (V, V, V, (E, V) -> V, E, V) -> V<a1a1: V,a2a2: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause2std/core/hnd/Clause2: forall<a,b,c,d,e,a1> (clause : (marker<e,a1>, ev<d>, a, b) -> e c) -> clause2<a,b,c,d,e,a1>( clauseclause: (marker<72,73>, ev<71>, 68, 69) -> 72 70: (markerstd/core/hnd/marker: (E, V) -> V<ee: E,rr: V>, evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, a1a1: V, a2a2: V) -> ee: E bb: V )

fun under2std/core/hnd/under2: forall<a,b,c,e,d> (ev : ev<d>, op : (a, b) -> e c, x1 : a, x2 : b) -> e c( evev: ev<$9442> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: ($9438, $9439) -> $9441 $9440 : (a1a1: V,a2a2: V) -> ee: E bb: V, x1x1: $9438 : a1a1: V, x2x2: $9439 : a2a2: V ) : ee: E bb: V 
  val w0w0: evv<_9444> = evv-swap-withstd/core/hnd/evv-swap-with: forall<a,e> (ev : ev<a>) -> evv<e>(evev: ev<$9442>)
  val zz: $9440 = opop: ($9438, $9439) -> $9441 $9440(x1x1: $9438,x2x2: $9439)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_9444>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $9440 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($9465) -> $9441 $9440,resres: $9465) under1std/core/hnd/under1: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b(evev: ev<$9442>,contcont: ($9465) -> $9441 $9440,resres: $9465) )std/core/types/(): ()
  zz: $9440

fun protectstd/core/hnd/protect.1: forall<a,b,c,e,d> (x1 : a, x2 : b, clause : (x : a, x : b, k : (c) -> e d) -> e d, k : (resume-result<c,d>) -> e d) -> e d( x1x1: $7091 : a1a1: V, x2x2: $7092:a2a2: V, clauseclause: (x : $7091, x : $7092, k : ($7093) -> $7094 $7095) -> $7094 $7095 : (x:a1a1: V,x:a2a2: V, k: bb: V -> ee: E rr: V) -> ee: E rr: V, kk: (resume-result<$7093,$7095>) -> $7094 $7095 : resume-resultstd/core/hnd/resume-result: (V, V) -> V<bb: V,rr: V> -> ee: E rr: V ) : ee: E rr: V 
  val resumedresumed: ref<global,bool> = (unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){refstd/core/types/ref: forall<a,h> (value : a) -> (alloc<h>) ref<h,a>(Falsestd/core/types/False: bool)})()
  fun kprotectkprotect: (ret : $7093) -> $7094 $7095(retret: $7093) 
    (unsafe-ststd/core/hnd/unsafe-st: forall<a,e> (f : () -> <st<global>|e> a) -> (() -> e a){ resumedresumed: ref<global,bool> :=std/core/types/set: forall<a,h> (ref : ref<h,a>, assigned : a) -> (write<h>) () Truestd/core/types/True: bool })()
    kk: (resume-result<$7093,$7095>) -> $7094 $7095(Deepstd/core/hnd/Deep: forall<a,b> (result : a) -> resume-result<a,b>(retret: $7093))
  val resres: $7095 = clauseclause: (x : $7091, x : $7092, k : ($7093) -> $7094 $7095) -> $7094 $7095(x1x1: $7091,x2x2: $7092,kprotectkprotect: (ret : $7093) -> $7094 $7095)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $7095 yield-extendstd/core/hnd/yield-extend: forall<a,b,e> (next : (a) -> e b) -> e b( fn(xresxres: $7095) protect-checkstd/core/hnd/protect-check: forall<a,e,b> (resumed : ref<global,bool>, k : (resume-result<a,b>) -> e b, res : b) -> e b(resumedresumed: ref<global,bool>,kk: (resume-result<$7093,$7095>) -> $7094 $7095,xresxres: $7095) )std/core/types/(): ()
  protect-checkstd/core/hnd/protect-check: forall<a,e,b> (resumed : ref<global,bool>, k : (resume-result<a,b>) -> e b, res : b) -> e b(resumedresumed: ref<global,bool>,kk: (resume-result<$7093,$7095>) -> $7094 $7095,resres: $7095)

pub fun clause-control2std/core/hnd/clause-control2: forall<a,b,c,e,d,a1> (clause : (x1 : a, x2 : b, k : (c) -> e a1) -> e a1) -> clause2<a,b,c,d,e,a1>( clauseclause: (x1 : $7362, x2 : $7363, k : ($7364) -> $7365 $7367) -> $7365 $7367 : (x1:a1a1: V, x2:a2a2: V, k: bb: V -> ee: E rr: V) -> ee: E rr: V ) : clause2std/core/hnd/clause2: (V, V, V, (E, V) -> V, E, V) -> V<a1a1: V,a2a2: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause2std/core/hnd/Clause2: forall<a,b,c,d,e,a1> (clause : (marker<e,a1>, ev<d>, a, b) -> e c) -> clause2<a,b,c,d,e,a1>(fn(mm: marker<$7365,$7367>,_ev,x1x1: $7362,x2x2: $7363){ yield-tostd/core/hnd/yield-to: forall<a,e,b> (m : marker<e,b>, clause : ((resume-result<a,b>) -> e b) -> e b) -> e a(mm: marker<$7365,$7367>, fn(kk: (resume-result<$7364,$7367>) -> $7365 $7367){ protectstd/core/hnd/protect.1: forall<a,b,c,e,d> (x1 : a, x2 : b, clause : (x : a, x : b, k : (c) -> e d) -> e d, k : (resume-result<c,d>) -> e d) -> e d(x1x1: $7362,x2x2: $7363,clauseclause: (x1 : $7362, x2 : $7363, k : ($7364) -> $7365 $7367) -> $7365 $7367,kk: (resume-result<$7364,$7367>) -> $7365 $7367) }) })


pub fun clause-control-raw2std/core/hnd/clause-control-raw2: forall<a,b,c,e,e1,d,a1> (op : (x1 : a, x2 : b, r : resume-context<c,e,e1,a1>) -> e a1) -> clause2<a,b,c,d,e,a1>( opop: (x1 : $6584, x2 : $6585, r : resume-context<$6586,$6587,$6588,$6590>) -> $6587 $6590 : (x1:a1a1: V, x2:a2a2: V, r: resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E,e0e0: E,rr: V>) -> ee: E rr: V ) : clause2std/core/hnd/clause2: (V, V, V, (E, V) -> V, E, V) -> V<a1a1: V,a2a2: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause2std/core/hnd/Clause2: forall<a,b,c,d,e,a1> (clause : (marker<e,a1>, ev<d>, a, b) -> e c) -> clause2<a,b,c,d,e,a1>(fn(mm: marker<$6587,$6590>,_ev,x1x1: $6584,x2x2: $6585){ yield-tostd/core/hnd/yield-to: forall<a,e,b> (m : marker<e,b>, clause : ((resume-result<a,b>) -> e b) -> e b) -> e a(mm: marker<$6587,$6590>, fn(kk: (resume-result<$6586,$6590>) -> $6587 $6590){ opop: (x1 : $6584, x2 : $6585, r : resume-context<$6586,$6587,$6588,$6590>) -> $6587 $6590(x1x1: $6584,x2x2: $6585,Resume-contextstd/core/hnd/Resume-context: forall<a,e,e1,b> (k : (resume-result<a,b>) -> e b) -> resume-context<a,e,e1,b>(kk: (resume-result<$6586,$6590>) -> $6587 $6590)) } ) })

pub fun clause-tail2std/core/hnd/clause-tail2: forall<e,a,b,c,d,a1> (op : (b, c) -> e d) -> clause2<b,c,d,a1,e,a><ee: E,rr: V,a1a1: V,a2a2: V,bb: V>(opop: ($9503, $9504) -> $9501 $9505 : (a1a1: V,a2a2: V) -> ee: E bb: V) : clause2std/core/hnd/clause2: (V, V, V, (E, V) -> V, E, V) -> V<a1a1: V,a2a2: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause2std/core/hnd/Clause2: forall<a,b,c,d,e,a1> (clause : (marker<e,a1>, ev<d>, a, b) -> e c) -> clause2<a,b,c,d,e,a1>(fn(mm: marker<$9501,$9502>,evev: ev<$9506>,x1x1: $9503,x2x2: $9504){ under2std/core/hnd/under2: forall<a,b,c,e,d> (ev : ev<d>, op : (a, b) -> e c, x1 : a, x2 : b) -> e c(evev: ev<$9506>,opop: ($9503, $9504) -> $9501 $9505,x1x1: $9503,x2x2: $9504) })

pub fun clause-tail-noyield2std/core/hnd/clause-tail-noyield2: forall<e,a,b,c,d,a1> (op : (b, c) -> e d) -> clause2<b,c,d,a1,e,a><ee: E,rr: V,a1a1: V,a2a2: V,bb: V>(opop: ($4210, $4211) -> $4208 $4212 : (a1a1: V,a2a2: V) -> ee: E bb: V) : clause2std/core/hnd/clause2: (V, V, V, (E, V) -> V, E, V) -> V<a1a1: V,a2a2: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause2std/core/hnd/Clause2: forall<a,b,c,d,e,a1> (clause : (marker<e,a1>, ev<d>, a, b) -> e c) -> clause2<a,b,c,d,e,a1>(fn(_m,_ev,x1x1: $4210,x2x2: $4211){ opop: ($4210, $4211) -> $4208 $4212(x1x1: $4210,x2x2: $4211) })

pub inline fun ".perform2"( evxevx: ev<$3744> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: forall<e,a> ($3744<e,a>) -> clause2<$3740,$3741,$3742,$3744,e,a> : (forall<e1e1: E,rr: V> hh: (E, V) -> V<e1e1: E,rr: V> -> clause2std/core/hnd/clause2: (V, V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,cc: V,hh: (E, V) -> V,e1e1: E,rr: V>), xx: $3740 : aa: V, yy: $3741 : bb: V ) : ee: E cc: V 
  match evxevx: ev<$3744>
    Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a>(_tag,mm: marker<$3747,$3748>,hh: $3744<$3747,$3748>,_c,_w) -> match hh: $3744<$3747,$3748>.opop: forall<e,a> ($3744<e,a>) -> clause2<$3740,$3741,$3742,$3744,e,a> 
      Clause2std/core/hnd/Clause2: forall<a,b,c,d,e,a1> (clause : (marker<e,a1>, ev<d>, a, b) -> e c) -> clause2<a,b,c,d,e,a1>(ff: (marker<$3747,$3748>, ev<$3744>, $3740, $3741) -> $3747 $3742) -> cast-ev2std/core/hnd/cast-ev2.1: forall<a,b,c,e,e1,d,a1> (f : (marker<e1,a1>, ev<d>, a, b) -> e1 c) -> e ((marker<e1,a1>, ev<d>, a, b) -> e c)(ff: (marker<$3747,$3748>, ev<$3744>, $3740, $3741) -> $3747 $3742)(mm: marker<$3747,$3748>,evxevx: ev<$3744>,xx: $3740,yy: $3741)

pub fun clause-never2std/core/hnd/clause-never2: forall<a,b,c,e,d,a1> (op : (a, b) -> e a1) -> clause2<a,b,c,d,e,a1>( opop: ($8063, $8064) -> $8066 $8068 : (a1a1: V,a2a2: V) -> ee: E rr: V ) : clause2std/core/hnd/clause2: (V, V, V, (E, V) -> V, E, V) -> V<a1a1: V,a2a2: V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  Clause2std/core/hnd/Clause2: forall<a,b,c,d,e,a1> (clause : (marker<e,a1>, ev<d>, a, b) -> e c) -> clause2<a,b,c,d,e,a1>(fn(mm: marker<$8066,$8068>,_ev,x1x1: $8063,x2x2: $8064){ yield-to-finalstd/core/hnd/yield-to-final: forall<a,e,e1,b> (m : marker<e1,b>, clause : ((resume-result<a,b>) -> e1 b) -> e1 b) -> e a(mm: marker<$8066,$8068>, fn(_k){ opop: ($8063, $8064) -> $8066 $8068(x1x1: $8063,x2x2: $8064) }) })


//----------------------------------------------------------------
// 3 arguments: reuse 1 argument clause.
// Or should the compiler do tupling/untupling?
//----------------------------------------------------------------

// For interal use
fun xperform1std/core/hnd/xperform1: forall<a,b,e,c> (ev : ev<c>, op : forall<e1,d> (c<e1,d>) -> clause1<a,b,c,e1,d>, x : a) -> e b( evev: ev<$4023> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: forall<e,a> ($4023<e,a>) -> clause1<$4020,$4021,$4023,e,a> : (forall<e1e1: E,rr: V> hh: (E, V) -> V<e1e1: E,rr: V> -> clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<aa: V,bb: V,hh: (E, V) -> V,e1e1: E,rr: V>), xx: $4020 : aa: V ) : ee: E bb: V 
  match evev: ev<$4023>
    Evstd/core/hnd/Ev: forall<a,e,b> (htag : htag<a>, marker : marker<e,b>, hnd : a<e,b>, cfc : cfc, hevv : evv<e>) -> ev<a>(_tag,mm: marker<$4026,$4027>,hh: $4023<$4026,$4027>,_c,_w) -> match hh: $4023<$4026,$4027>.opop: forall<e,a> ($4023<e,a>) -> clause1<$4020,$4021,$4023,e,a> 
      Clause1std/core/hnd/Clause1: forall<a,b,c,e,d> (clause : (marker<e,d>, ev<c>, a) -> e b) -> clause1<a,b,c,e,d>(ff: (marker<$4026,$4027>, ev<$4023>, $4020) -> $4026 $4021) -> cast-ev1std/core/hnd/cast-ev1.1: forall<a,b,e,e1,c,d> (f : (marker<e1,d>, ev<c>, a) -> e1 b) -> e ((marker<e1,d>, ev<c>, a) -> e b)(ff: (marker<$4026,$4027>, ev<$4023>, $4020) -> $4026 $4021)(mm: marker<$4026,$4027>,evev: ev<$4023>,xx: $4020)

pub fun clause-control-raw3std/core/hnd/clause-control-raw3: forall<a,b,c,d,e,e1,a1,b1> (op : (x1 : a, x2 : b, x3 : c, r : resume-context<d,e,e1,b1>) -> e b1) -> clause1<(a, b, c),d,a1,e,b1>( opop: (x1 : $6639, x2 : $6640, x3 : $6641, r : resume-context<$6642,$6643,$6644,$6646>) -> $6643 $6646 : (x1:a1a1: V, x2:a2a2: V, x3:a3a3: V, r: resume-contextstd/core/hnd/resume-context: (V, E, E, V) -> V<bb: V,ee: E,e0e0: E,rr: V>) -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,): (V, V, V) -> Va1a1: V,a2a2: V,a3a3: V)std/core/types/(,,): (V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-control-raw1std/core/hnd/clause-control-raw1: forall<a,b,e,e1,c,d> (op : (x : a, r : resume-context<b,e,e1,d>) -> e d) -> clause1<a,b,c,e,d>( fn(xx: ($6639, $6640, $6641):(std/core/types/(,,): (V, V, V) -> V__w-l630-c30: V,__w-l630-c32: V,__w-l630-c34: V)std/core/types/(,,): (V, V, V) -> V,rr: resume-context<$6642,$6643,$6644,$6646>){ opop: (x1 : $6639, x2 : $6640, x3 : $6641, r : resume-context<$6642,$6643,$6644,$6646>) -> $6643 $6646(xx: ($6639, $6640, $6641).fststd/core/types/fst.1: forall<a,b,c> ((a, b, c)) -> a,xx: ($6639, $6640, $6641).sndstd/core/types/snd.1: forall<a,b,c> ((a, b, c)) -> b,xx: ($6639, $6640, $6641).thdstd/core/types/thd: forall<a,b,c> ((a, b, c)) -> c,rr: resume-context<$6642,$6643,$6644,$6646>) } )

pub fun clause-control3std/core/hnd/clause-control3: forall<a,b,c,d,e,a1,b1> (op : (x1 : a, x2 : b, x3 : c, k : (d) -> e b1) -> e b1) -> clause1<(a, b, c),d,a1,e,b1>( opop: (x1 : $7446, x2 : $7447, x3 : $7448, k : ($7449) -> $7450 $7452) -> $7450 $7452 : (x1:a1a1: V, x2:a2a2: V, x3:a3a3: V, k: bb: V -> ee: E rr: V) -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,): (V, V, V) -> Va1a1: V,a2a2: V,a3a3: V)std/core/types/(,,): (V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-control1std/core/hnd/clause-control1: forall<a,b,e,c,d> (clause : (x : a, k : (b) -> e d) -> e d) -> clause1<a,b,c,e,d>( fn(xx: ($7446, $7447, $7448):(std/core/types/(,,): (V, V, V) -> V__w-l633-c26: V,__w-l633-c28: V,__w-l633-c30: V)std/core/types/(,,): (V, V, V) -> V,kk: ($7449) -> $7450 $7452){ opop: (x1 : $7446, x2 : $7447, x3 : $7448, k : ($7449) -> $7450 $7452) -> $7450 $7452(xx: ($7446, $7447, $7448).fststd/core/types/fst.1: forall<a,b,c> ((a, b, c)) -> a,xx: ($7446, $7447, $7448).sndstd/core/types/snd.1: forall<a,b,c> ((a, b, c)) -> b,xx: ($7446, $7447, $7448).thdstd/core/types/thd: forall<a,b,c> ((a, b, c)) -> c,kk: ($7449) -> $7450 $7452) } )

pub fun clause-tail3std/core/hnd/clause-tail3: forall<a,b,c,d,e,a1,b1> (op : (a, b, c) -> e d) -> clause1<(a, b, c),d,a1,e,b1>(opop: ($9546, $9547, $9548) -> $9550 $9549 : (a1a1: V,a2a2: V,a3a3: V) -> ee: E bb: V) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,): (V, V, V) -> Va1a1: V,a2a2: V,a3a3: V)std/core/types/(,,): (V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-tail1std/core/hnd/clause-tail1: forall<e,a,b,c,d> (op : (b) -> e c) -> clause1<b,c,d,e,a>( fn( xx: ($9546, $9547, $9548):(std/core/types/(,,): (V, V, V) -> V__w-l636-c24: V,__w-l636-c26: V,__w-l636-c28: V)std/core/types/(,,): (V, V, V) -> V ){ opop: ($9546, $9547, $9548) -> $9550 $9549(xx: ($9546, $9547, $9548).fststd/core/types/fst.1: forall<a,b,c> ((a, b, c)) -> a,xx: ($9546, $9547, $9548).sndstd/core/types/snd.1: forall<a,b,c> ((a, b, c)) -> b,xx: ($9546, $9547, $9548).thdstd/core/types/thd: forall<a,b,c> ((a, b, c)) -> c) } )

pub fun clause-tail-noyield3std/core/hnd/clause-tail-noyield3: forall<a,b,c,d,e,a1,b1> (op : (a, b, c) -> e d) -> clause1<(a, b, c),d,a1,e,b1>(opop: ($8651, $8652, $8653) -> $8655 $8654 : (a1a1: V,a2a2: V,a3a3: V) -> ee: E bb: V) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,): (V, V, V) -> Va1a1: V,a2a2: V,a3a3: V)std/core/types/(,,): (V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-tail-noyield1std/core/hnd/clause-tail-noyield1: forall<e,a,b,c,d> (op : (b) -> e c) -> clause1<b,c,d,e,a>( fn( xx: ($8651, $8652, $8653):(std/core/types/(,,): (V, V, V) -> V__w-l639-c32: V,__w-l639-c34: V,__w-l639-c36: V)std/core/types/(,,): (V, V, V) -> V ){ opop: ($8651, $8652, $8653) -> $8655 $8654(xx: ($8651, $8652, $8653).fststd/core/types/fst.1: forall<a,b,c> ((a, b, c)) -> a,xx: ($8651, $8652, $8653).sndstd/core/types/snd.1: forall<a,b,c> ((a, b, c)) -> b,xx: ($8651, $8652, $8653).thdstd/core/types/thd: forall<a,b,c> ((a, b, c)) -> c) } )

pub fun clause-never3std/core/hnd/clause-never3: forall<a,b,c,d,e,a1,b1> (op : (a, b, c) -> e b1) -> clause1<(a, b, c),d,a1,e,b1>( opop: ($8108, $8109, $8110) -> $8112 $8114 : (a1a1: V,a2a2: V,a3a3: V) -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,): (V, V, V) -> Va1a1: V,a2a2: V,a3a3: V)std/core/types/(,,): (V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-never1std/core/hnd/clause-never1: forall<a,b,e,c,d> (op : (a) -> e d) -> clause1<a,b,c,e,d>(fn(xx: ($8108, $8109, $8110):(std/core/types/(,,): (V, V, V) -> V__w-l642-c23: V,__w-l642-c25: V,__w-l642-c27: V)std/core/types/(,,): (V, V, V) -> V){ opop: ($8108, $8109, $8110) -> $8112 $8114(xx: ($8108, $8109, $8110).fststd/core/types/fst.1: forall<a,b,c> ((a, b, c)) -> a,xx: ($8108, $8109, $8110).sndstd/core/types/snd.1: forall<a,b,c> ((a, b, c)) -> b,xx: ($8108, $8109, $8110).thdstd/core/types/thd: forall<a,b,c> ((a, b, c)) -> c) } )

pub fun ".perform3"( evev: ev<$6364> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: forall<e,a> ($6364<e,a>) -> clause1<($6359, $6360, $6361),$6362,$6364,e,a> : (forall<e1e1: E,rr: V> hh: (E, V) -> V<e1e1: E,rr: V> -> clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,): (V, V, V) -> Va1a1: V,a2a2: V,a3a3: V)std/core/types/(,,): (V, V, V) -> V,bb: V,hh: (E, V) -> V,e1e1: E,rr: V>), x1x1: $6359 : a1a1: V, x2x2: $6360 : a2a2: V, x3x3: $6361 : a3a3: V ) : ee: E bb: V 
  xperform1std/core/hnd/xperform1: forall<a,b,e,c> (ev : ev<c>, op : forall<e1,d> (c<e1,d>) -> clause1<a,b,c,e1,d>, x : a) -> e b(evev: ev<$6364>,opop: forall<e,a> ($6364<e,a>) -> clause1<($6359, $6360, $6361),$6362,$6364,e,a>,(std/core/types/(,,): forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c)x1x1: $6359,x2x2: $6360,x3x3: $6361)std/core/types/(,,): forall<a,b,c> (fst : a, snd : b, thd : c) -> (a, b, c))

fun under3std/core/hnd/under3: forall<a,b,c,d,e,a1> (ev : ev<a1>, op : (a, b, c) -> e d, x1 : a, x2 : b, x3 : c) -> e d( evev: ev<$10641> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: ($10636, $10637, $10638) -> $10640 $10639 : (a1a1: V,a2a2: V,a3a3: V) -> ee: E bb: V, x1x1: $10636 : a1a1: V, x2x2: $10637 : a2a2: V, x3x3: $10638 : a3a3: V ) : ee: E bb: V 
  val w0w0: evv<_10643> = evv-swap-withstd/core/hnd/evv-swap-with: forall<a,e> (ev : ev<a>) -> evv<e>(evev: ev<$10641>)
  val zz: $10639 = opop: ($10636, $10637, $10638) -> $10640 $10639(x1x1: $10636,x2x2: $10637,x3x3: $10638)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_10643>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $10639 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($10665) -> $10640 $10639,resres: $10665) under1std/core/hnd/under1: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b(evev: ev<$10641>,contcont: ($10665) -> $10640 $10639,resres: $10665) )std/core/types/(): ()
  zz: $10639



pub fun clause-control4std/core/hnd/clause-control4: forall<a,b,c,d,a1,e,b1,c1> (op : (x1 : a, x2 : b, x3 : c, x4 : d, k : (a1) -> e c1) -> e c1) -> clause1<(a, b, c, d),a1,b1,e,c1>( opop: (x1 : $7683, x2 : $7684, x3 : $7685, x4 : $7686, k : ($7687) -> $7688 $7690) -> $7688 $7690 : (x1:a1a1: V, x2:a2a2: V, x3:a3a3: V, x4:a4a4: V, k: bb: V -> ee: E rr: V) -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,,): (V, V, V, V) -> Va1a1: V,a2a2: V,a3a3: V,a4a4: V)std/core/types/(,,,): (V, V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-control1std/core/hnd/clause-control1: forall<a,b,e,c,d> (clause : (x : a, k : (b) -> e d) -> e d) -> clause1<a,b,c,e,d>( fn(xx: ($7683, $7684, $7685, $7686):(std/core/types/(,,,): (V, V, V, V) -> V__w-l657-c26: V,__w-l657-c28: V,__w-l657-c30: V,__w-l657-c32: V)std/core/types/(,,,): (V, V, V, V) -> V,kk: ($7687) -> $7688 $7690){ opop: (x1 : $7683, x2 : $7684, x3 : $7685, x4 : $7686, k : ($7687) -> $7688 $7690) -> $7688 $7690(xx: ($7683, $7684, $7685, $7686).fststd/core/types/fst.2: forall<a,b,c,d> ((a, b, c, d)) -> a,xx: ($7683, $7684, $7685, $7686).sndstd/core/types/snd.2: forall<a,b,c,d> ((a, b, c, d)) -> b,xx: ($7683, $7684, $7685, $7686).thdstd/core/types/thd.1: forall<a,b,c,d> ((a, b, c, d)) -> c,xx: ($7683, $7684, $7685, $7686).field4std/core/types/field4: forall<a,b,c,d> ((a, b, c, d)) -> d,kk: ($7687) -> $7688 $7690) } )

pub fun clause-tail4std/core/hnd/clause-tail4: forall<a,b,c,d,a1,e,b1,c1> (op : (a, b, c, d) -> e a1) -> clause1<(a, b, c, d),a1,b1,e,c1>(opop: ($9782, $9783, $9784, $9785) -> $9787 $9786 : (a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> ee: E bb: V) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,,): (V, V, V, V) -> Va1a1: V,a2a2: V,a3a3: V,a4a4: V)std/core/types/(,,,): (V, V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-tail1std/core/hnd/clause-tail1: forall<e,a,b,c,d> (op : (b) -> e c) -> clause1<b,c,d,e,a>( fn( xx: ($9782, $9783, $9784, $9785):(std/core/types/(,,,): (V, V, V, V) -> V__w-l660-c24: V,__w-l660-c26: V,__w-l660-c28: V,__w-l660-c30: V)std/core/types/(,,,): (V, V, V, V) -> V ){ opop: ($9782, $9783, $9784, $9785) -> $9787 $9786(xx: ($9782, $9783, $9784, $9785).fststd/core/types/fst.2: forall<a,b,c,d> ((a, b, c, d)) -> a,xx: ($9782, $9783, $9784, $9785).sndstd/core/types/snd.2: forall<a,b,c,d> ((a, b, c, d)) -> b,xx: ($9782, $9783, $9784, $9785).thdstd/core/types/thd.1: forall<a,b,c,d> ((a, b, c, d)) -> c,xx: ($9782, $9783, $9784, $9785).field4std/core/types/field4: forall<a,b,c,d> ((a, b, c, d)) -> d) } )

pub fun clause-tail-noyield4std/core/hnd/clause-tail-noyield4: forall<a,b,c,d,a1,e,b1,c1> (op : (a, b, c, d) -> e a1) -> clause1<(a, b, c, d),a1,b1,e,c1>(opop: ($8887, $8888, $8889, $8890) -> $8892 $8891 : (a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> ee: E bb: V) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,,): (V, V, V, V) -> Va1a1: V,a2a2: V,a3a3: V,a4a4: V)std/core/types/(,,,): (V, V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-tail-noyield1std/core/hnd/clause-tail-noyield1: forall<e,a,b,c,d> (op : (b) -> e c) -> clause1<b,c,d,e,a>( fn( xx: ($8887, $8888, $8889, $8890):(std/core/types/(,,,): (V, V, V, V) -> V__w-l663-c32: V,__w-l663-c34: V,__w-l663-c36: V,__w-l663-c38: V)std/core/types/(,,,): (V, V, V, V) -> V ){ opop: ($8887, $8888, $8889, $8890) -> $8892 $8891(xx: ($8887, $8888, $8889, $8890).fststd/core/types/fst.2: forall<a,b,c,d> ((a, b, c, d)) -> a,xx: ($8887, $8888, $8889, $8890).sndstd/core/types/snd.2: forall<a,b,c,d> ((a, b, c, d)) -> b,xx: ($8887, $8888, $8889, $8890).thdstd/core/types/thd.1: forall<a,b,c,d> ((a, b, c, d)) -> c,xx: ($8887, $8888, $8889, $8890).field4std/core/types/field4: forall<a,b,c,d> ((a, b, c, d)) -> d) } )

pub fun clause-never4std/core/hnd/clause-never4: forall<a,b,c,d,a1,e,b1,c1> (op : (a, b, c, d) -> e c1) -> clause1<(a, b, c, d),a1,b1,e,c1>( opop: ($8344, $8345, $8346, $8347) -> $8349 $8351 : (a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> ee: E rr: V ) : clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,,): (V, V, V, V) -> Va1a1: V,a2a2: V,a3a3: V,a4a4: V)std/core/types/(,,,): (V, V, V, V) -> V,bb: V,hh: (E, V) -> V,ee: E,rr: V> 
  clause-never1std/core/hnd/clause-never1: forall<a,b,e,c,d> (op : (a) -> e d) -> clause1<a,b,c,e,d>(fn(xx: ($8344, $8345, $8346, $8347):(std/core/types/(,,,): (V, V, V, V) -> V__w-l666-c23: V,__w-l666-c25: V,__w-l666-c27: V,__w-l666-c29: V)std/core/types/(,,,): (V, V, V, V) -> V){ opop: ($8344, $8345, $8346, $8347) -> $8349 $8351(xx: ($8344, $8345, $8346, $8347).fststd/core/types/fst.2: forall<a,b,c,d> ((a, b, c, d)) -> a,xx: ($8344, $8345, $8346, $8347).sndstd/core/types/snd.2: forall<a,b,c,d> ((a, b, c, d)) -> b,xx: ($8344, $8345, $8346, $8347).thdstd/core/types/thd.1: forall<a,b,c,d> ((a, b, c, d)) -> c,xx: ($8344, $8345, $8346, $8347).field4std/core/types/field4: forall<a,b,c,d> ((a, b, c, d)) -> d) } )

pub fun ".perform4"( evev: ev<$6414> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: forall<e,a> ($6414<e,a>) -> clause1<($6408, $6409, $6410, $6411),$6412,$6414,e,a> : (forall<e1e1: E,rr: V> hh: (E, V) -> V<e1e1: E,rr: V> -> clause1std/core/hnd/clause1: (V, V, (E, V) -> V, E, V) -> V<(std/core/types/(,,,): (V, V, V, V) -> Va1a1: V,a2a2: V,a3a3: V,a4a4: V)std/core/types/(,,,): (V, V, V, V) -> V,bb: V,hh: (E, V) -> V,e1e1: E,rr: V>), x1x1: $6408 : a1a1: V, x2x2: $6409 : a2a2: V, x3x3: $6410 : a3a3: V, x4x4: $6411 : a4a4: V ) : ee: E bb: V 
  xperform1std/core/hnd/xperform1: forall<a,b,e,c> (ev : ev<c>, op : forall<e1,d> (c<e1,d>) -> clause1<a,b,c,e1,d>, x : a) -> e b(evev: ev<$6414>,opop: forall<e,a> ($6414<e,a>) -> clause1<($6408, $6409, $6410, $6411),$6412,$6414,e,a>,(std/core/types/(,,,): forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d)x1x1: $6408,x2x2: $6409,x3x3: $6410,x4x4: $6411)std/core/types/(,,,): forall<a,b,c,d> (fst : a, snd : b, thd : c, field4 : d) -> (a, b, c, d))

fun under4std/core/hnd/under4: forall<a,b,c,d,a1,e,b1> (ev : ev<b1>, op : (a, b, c, d) -> e a1, x1 : a, x2 : b, x3 : c, x4 : d) -> e a1( evev: ev<$10710> : evstd/core/hnd/ev: ((E, V) -> V) -> V<hh: (E, V) -> V>, opop: ($10704, $10705, $10706, $10707) -> $10709 $10708 : (a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> ee: E bb: V, x1x1: $10704 : a1a1: V, x2x2: $10705 : a2a2: V, x3x3: $10706 : a3a3: V, x4x4: $10707 : a4a4: V ) : ee: E bb: V 
  val w0w0: evv<_10712> = evv-swap-withstd/core/hnd/evv-swap-with: forall<a,e> (ev : ev<a>) -> evv<e>(evev: ev<$10710>)
  val zz: $10708 = opop: ($10704, $10705, $10706, $10707) -> $10709 $10708(x1x1: $10704,x2x2: $10705,x3x3: $10706,x4x4: $10707)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(w0w0: evv<_10712>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $10708 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b( fn(contcont: ($10735) -> $10709 $10708,resres: $10735) under1std/core/hnd/under1: forall<a,b,e,c> (ev : ev<c>, op : (a) -> e b, x : a) -> e b(evev: ev<$10710>,contcont: ($10735) -> $10709 $10708,resres: $10735) )std/core/types/(): ()
  zz: $10708


// -------------------------------------------
// Open
// -------------------------------------------

pub fun ".open-none0"<bb: V,e1e1: E,e2e2: E>( ff: () -> $3222 $3221 : () -> e1e1: E bb: V ) : e2e2: E bb: V 
  val ww: evv<$3223> = evv-swap-create0std/core/hnd/evv-swap-create0: forall<e> () -> e evv<e>()
  val xx: $3221 = cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1> (f : () -> e1 a) -> (() -> e a)(ff: () -> $3222 $3221)()
  val keepkeep: () = evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$3223>)
  xx: $3221

pub fun ".open-none1"<aa: V,bb: V,e1e1: E,e2e2: E>( ff: ($3283) -> $3285 $3284 : aa: V -> e1e1: E bb: V, x1x1: $3283 : aa: V ) : e2e2: E bb: V 
  val ww: evv<$3286> = evv-swap-create0std/core/hnd/evv-swap-create0: forall<e> () -> e evv<e>()
  val xx: $3284 = cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(ff: ($3283) -> $3285 $3284)(x1x1: $3283)
  val keepkeep: () = evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$3286>)
  xx: $3284

pub fun ".open-none2"<a1a1: V,a2a2: V,bb: V,e1e1: E,e2e2: E>( ff: ($3360, $3361) -> $3363 $3362 : (a1a1: V,a2a2: V) -> e1e1: E bb: V, x1x1: $3360 : a1a1: V, x2x2: $3361 : a2a2: V ) : e2e2: E bb: V 
  val ww: evv<$3364> = evv-swap-create0std/core/hnd/evv-swap-create0: forall<e> () -> e evv<e>()
  val xx: $3362 = cast-ev2std/core/hnd/cast-ev2: forall<a,b,c,e,e1> (f : (a, b) -> e1 c) -> ((a, b) -> e c)(ff: ($3360, $3361) -> $3363 $3362)(x1x1: $3360,x2x2: $3361)
  val keepkeep: () = evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$3364>)
  xx: $3362

pub fun ".open-none3"<a1a1: V,a2a2: V,a3a3: V,bb: V,e1e1: E,e2e2: E>( ff: ($3452, $3453, $3454) -> $3456 $3455 : (a1a1: V,a2a2: V,a3a3: V) -> e1e1: E bb: V, x1x1: $3452 : a1a1: V, x2x2: $3453 : a2a2: V, x3x3: $3454 : a3a3: V ) : e2e2: E bb: V 
  val ww: evv<$3457> = evv-swap-create0std/core/hnd/evv-swap-create0: forall<e> () -> e evv<e>()
  val xx: $3455 = cast-ev3std/core/hnd/cast-ev3: forall<a,b,c,d,e,e1> (f : (a, b, c) -> e1 d) -> ((a, b, c) -> e d)(ff: ($3452, $3453, $3454) -> $3456 $3455)(x1x1: $3452,x2x2: $3453,x3x3: $3454)
  val keepkeep: () = evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$3457>)
  xx: $3455

pub fun ".open-none4"<a1a1: V,a2a2: V,a3a3: V,a4a4: V,bb: V,e1e1: E,e2e2: E>( ff: ($3496, $3497, $3498, $3499) -> $3501 $3500 : (a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> e1e1: E bb: V, x1x1: $3496 : a1a1: V, x2x2: $3497 : a2a2: V, x3x3: $3498 : a3a3: V, x4x4: $3499 : a4a4: V ) : e2e2: E bb: V 
  val ww: evv<$3502> = evv-swap-create0std/core/hnd/evv-swap-create0: forall<e> () -> e evv<e>()
  val xx: $3500 = cast-ev4std/core/hnd/cast-ev4: forall<a,b,c,d,a1,e,e1> (f : (a, b, c, d) -> e1 a1) -> ((a, b, c, d) -> e a1)(ff: ($3496, $3497, $3498, $3499) -> $3501 $3500)(x1x1: $3496,x2x2: $3497,x3x3: $3498,x4x4: $3499)
  val keepkeep: () = evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$3502>)
  xx: $3500


noinline fun open-at1std/core/hnd/open-at1: forall<a,b,e,e1> (i : ev-index, f : (a) -> e b, x : a) -> e1 b<aa: V,bb: V,e1e1: E,e2e2: E>( ii: ev-index: ev-indexstd/core/hnd/ev-index: V, ff: ($5189) -> $5191 $5190 : aa: V -> e1e1: E bb: V, xx: $5189 : aa: V ) : e2e2: E bb: V 
  val ww: evv<$5192> = evv-swap-create1std/core/hnd/evv-swap-create1: forall<e> (i : ev-index) -> e evv<e>(ii: ev-index)
  val yy: $5190 = cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(ff: ($5189) -> $5191 $5190)(xx: $5189)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5192>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5190 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5263) -> $5192 $5190,resres: $5263){ open-at1std/core/hnd/open-at1: forall<a,b,e,e1> (i : ev-index, f : (a) -> e b, x : a) -> e1 b(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(ii: ev-index),contcont: ($5263) -> $5192 $5190,resres: $5263) })std/core/types/(): ()
  yy: $5190

pub fun ".open-at0"<bb: V,e1e1: E,e2e2: E>( ii: ev-index: ev-indexstd/core/hnd/ev-index: V, ff: () -> $5300 $5299 : () -> e1e1: E bb: V ) : e2e2: E bb: V 
  val ww: evv<$5301> = evv-swap-create1std/core/hnd/evv-swap-create1: forall<e> (i : ev-index) -> e evv<e>(ii: ev-index)
  val yy: $5299 = cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1> (f : () -> e1 a) -> (() -> e a)(ff: () -> $5300 $5299)()
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5301>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5299 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5361) -> $5301 $5299,resres: $5361){ open-at1std/core/hnd/open-at1: forall<a,b,e,e1> (i : ev-index, f : (a) -> e b, x : a) -> e1 b(ii: ev-index,contcont: ($5361) -> $5301 $5299,resres: $5361) })std/core/types/(): ()
  yy: $5299

pub fun ".open-at1"<aa: V,bb: V,e1e1: E,e2e2: E>( ii: ev-index: ev-indexstd/core/hnd/ev-index: V, ff: ($5391) -> $5393 $5392 : aa: V -> e1e1: E bb: V, xx: $5391 : aa: V ) : e2e2: E bb: V 
  val ww: evv<$5394> = evv-swap-create1std/core/hnd/evv-swap-create1: forall<e> (i : ev-index) -> e evv<e>(ii: ev-index)
  val yy: $5392 = cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(ff: ($5391) -> $5393 $5392)(xx: $5391)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5394>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5392 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5465) -> $5394 $5392,resres: $5465){ open-at1std/core/hnd/open-at1: forall<a,b,e,e1> (i : ev-index, f : (a) -> e b, x : a) -> e1 b(ii: ev-index,contcont: ($5465) -> $5394 $5392,resres: $5465) })std/core/types/(): ()
  yy: $5392

pub fun ".open-at2"<a1a1: V,a2a2: V,bb: V,e1e1: E,e2e2: E> ( ii: ev-index: ev-indexstd/core/hnd/ev-index: V, ff: ($5498, $5499) -> $5501 $5500 : (a1a1: V,a2a2: V) -> e1e1: E bb: V, x1x1: $5498 : a1a1: V, x2x2: $5499 : a2a2: V ) : e2e2: E bb: V 
  val ww: evv<$5502> = evv-swap-create1std/core/hnd/evv-swap-create1: forall<e> (i : ev-index) -> e evv<e>(ii: ev-index)
  val yy: $5500 = cast-ev2std/core/hnd/cast-ev2: forall<a,b,c,e,e1> (f : (a, b) -> e1 c) -> ((a, b) -> e c)(ff: ($5498, $5499) -> $5501 $5500)(x1x1: $5498,x2x2: $5499)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5502>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5500 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5584) -> $5502 $5500,resres: $5584){ open-at1std/core/hnd/open-at1: forall<a,b,e,e1> (i : ev-index, f : (a) -> e b, x : a) -> e1 b(ii: ev-index,contcont: ($5584) -> $5502 $5500,resres: $5584) })std/core/types/(): ()
  yy: $5500

pub fun ".open-at3"<a1a1: V,a2a2: V,a3a3: V,bb: V,e1e1: E,e2e2: E> ( ii: ev-index: ev-indexstd/core/hnd/ev-index: V, ff: ($5620, $5621, $5622) -> $5624 $5623 : (a1a1: V,a2a2: V,a3a3: V) -> e1e1: E bb: V, x1x1: $5620 : a1a1: V, x2x2: $5621 : a2a2: V, x3x3: $5622 : a3a3: V ) : e2e2: E bb: V 
  val ww: evv<$5625> = evv-swap-create1std/core/hnd/evv-swap-create1: forall<e> (i : ev-index) -> e evv<e>(ii: ev-index)
  val yy: $5623 = cast-ev3std/core/hnd/cast-ev3: forall<a,b,c,d,e,e1> (f : (a, b, c) -> e1 d) -> ((a, b, c) -> e d)(ff: ($5620, $5621, $5622) -> $5624 $5623)(x1x1: $5620,x2x2: $5621,x3x3: $5622)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5625>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5623 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5655) -> $5625 $5623,resres: $5655){ open-at1std/core/hnd/open-at1: forall<a,b,e,e1> (i : ev-index, f : (a) -> e b, x : a) -> e1 b(ii: ev-index,contcont: ($5655) -> $5625 $5623,resres: $5655) })std/core/types/(): ()
  yy: $5623

pub fun ".open-at4"<a1a1: V,a2a2: V,a3a3: V,a4a4: V,bb: V,e1e1: E,e2e2: E> ( ii: ev-index: ev-indexstd/core/hnd/ev-index: V, ff: ($5694, $5695, $5696, $5697) -> $5699 $5698 : (a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> e1e1: E bb: V, x1x1: $5694 : a1a1: V, x2x2: $5695 : a2a2: V, x3x3: $5696 : a3a3: V, x4x4: $5697 : a4a4: V ) : e2e2: E bb: V 
  val ww: evv<$5700> = evv-swap-create1std/core/hnd/evv-swap-create1: forall<e> (i : ev-index) -> e evv<e>(ii: ev-index)
  val yy: $5698 = cast-ev4std/core/hnd/cast-ev4: forall<a,b,c,d,a1,e,e1> (f : (a, b, c, d) -> e1 a1) -> ((a, b, c, d) -> e a1)(ff: ($5694, $5695, $5696, $5697) -> $5699 $5698)(x1x1: $5694,x2x2: $5695,x3x3: $5696,x4x4: $5697)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5700>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5698 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5732) -> $5700 $5698,resres: $5732){ open-at1std/core/hnd/open-at1: forall<a,b,e,e1> (i : ev-index, f : (a) -> e b, x : a) -> e1 b(ii: ev-index,contcont: ($5732) -> $5700 $5698,resres: $5732) })std/core/types/(): ()
  yy: $5698


noinline fun open1std/core/hnd/open1: forall<a,b,e,e1> (indices : vector<ev-index>, f : (a) -> e b, x : a) -> e1 b<aa: V,bb: V,e1e1: E,e2e2: E>( indicesindices: vector<ev-index> : vectorstd/core/types/vector: V -> V<ev-indexstd/core/hnd/ev-index: V>, ff: ($5774) -> $5776 $5775 : aa: V -> e1e1: E bb: V, xx: $5774 : aa: V ) : e2e2: E bb: V 
  val ww: evv<$5777> = evv-swap-createstd/core/hnd/evv-swap-create: forall<e> (indices : vector<ev-index>) -> e evv<e>(indicesindices: vector<ev-index>)
  val yy: $5775 = cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(ff: ($5774) -> $5776 $5775)(xx: $5774)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5777>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5775 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5848) -> $5777 $5775,resres: $5848){ open1std/core/hnd/open1: forall<a,b,e,e1> (indices : vector<ev-index>, f : (a) -> e b, x : a) -> e1 b(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(indicesindices: vector<ev-index>),contcont: ($5848) -> $5777 $5775,resres: $5848) })std/core/types/(): ()
  yy: $5775


pub fun ".open0"<bb: V,e1e1: E,e2e2: E>( indicesindices: vector<ev-index> : vectorstd/core/types/vector: V -> V<ev-indexstd/core/hnd/ev-index: V>, ff: () -> $5885 $5884 : () -> e1e1: E bb: V ) : e2e2: E bb: V 
  val ww: evv<$5886> = evv-swap-createstd/core/hnd/evv-swap-create: forall<e> (indices : vector<ev-index>) -> e evv<e>(indicesindices: vector<ev-index>)
  val yy: $5884 = cast-ev0std/core/hnd/cast-ev0: forall<a,e,e1> (f : () -> e1 a) -> (() -> e a)(ff: () -> $5885 $5884)()
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5886>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5884 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($5946) -> $5886 $5884,resres: $5946){ open1std/core/hnd/open1: forall<a,b,e,e1> (indices : vector<ev-index>, f : (a) -> e b, x : a) -> e1 b(indicesindices: vector<ev-index>,contcont: ($5946) -> $5886 $5884,resres: $5946) })std/core/types/(): ()
  yy: $5884

pub fun ".open1"<aa: V,bb: V,e1e1: E,e2e2: E>( indicesindices: vector<ev-index> : vectorstd/core/types/vector: V -> V<ev-indexstd/core/hnd/ev-index: V>, ff: ($5976) -> $5978 $5977 : aa: V -> e1e1: E bb: V, xx: $5976 : aa: V ) : e2e2: E bb: V 
  val ww: evv<$5979> = evv-swap-createstd/core/hnd/evv-swap-create: forall<e> (indices : vector<ev-index>) -> e evv<e>(indicesindices: vector<ev-index>)
  val yy: $5977 = cast-ev1std/core/hnd/cast-ev1: forall<a,b,e,e1> (f : (a) -> e1 b) -> ((a) -> e b)(ff: ($5976) -> $5978 $5977)(xx: $5976)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$5979>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $5977 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($6050) -> $5979 $5977,resres: $6050){ open1std/core/hnd/open1: forall<a,b,e,e1> (indices : vector<ev-index>, f : (a) -> e b, x : a) -> e1 b(indicesindices: vector<ev-index>,contcont: ($6050) -> $5979 $5977,resres: $6050) })std/core/types/(): ()
  yy: $5977

pub fun ".open2"<a1a1: V,a2a2: V,bb: V,e1e1: E,e2e2: E>( indicesindices: vector<ev-index> : vectorstd/core/types/vector: V -> V<ev-indexstd/core/hnd/ev-index: V>, ff: ($6083, $6084) -> $6086 $6085 : (a1a1: V,a2a2: V) -> e1e1: E bb: V, x1x1: $6083 : a1a1: V, x2x2: $6084 : a2a2: V ) : e2e2: E bb: V 
  val ww: evv<$6087> = evv-swap-createstd/core/hnd/evv-swap-create: forall<e> (indices : vector<ev-index>) -> e evv<e>(indicesindices: vector<ev-index>)
  val yy: $6085 = cast-ev2std/core/hnd/cast-ev2: forall<a,b,c,e,e1> (f : (a, b) -> e1 c) -> ((a, b) -> e c)(ff: ($6083, $6084) -> $6086 $6085)(x1x1: $6083,x2x2: $6084)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$6087>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $6085 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($6169) -> $6087 $6085,resres: $6169){ open1std/core/hnd/open1: forall<a,b,e,e1> (indices : vector<ev-index>, f : (a) -> e b, x : a) -> e1 b(indicesindices: vector<ev-index>,contcont: ($6169) -> $6087 $6085,resres: $6169) })std/core/types/(): ()
  yy: $6085

pub fun ".open3"<a1a1: V,a2a2: V,a3a3: V,bb: V,e1e1: E,e2e2: E>( indicesindices: vector<ev-index> : vectorstd/core/types/vector: V -> V<ev-indexstd/core/hnd/ev-index: V>, ff: ($6205, $6206, $6207) -> $6209 $6208 : (a1a1: V,a2a2: V,a3a3: V) -> e1e1: E bb: V, x1x1: $6205 : a1a1: V, x2x2: $6206 : a2a2: V, x3x3: $6207 : a3a3: V ) : e2e2: E bb: V 
  val ww: evv<$6210> = evv-swap-createstd/core/hnd/evv-swap-create: forall<e> (indices : vector<ev-index>) -> e evv<e>(indicesindices: vector<ev-index>)
  val yy: $6208 = cast-ev3std/core/hnd/cast-ev3: forall<a,b,c,d,e,e1> (f : (a, b, c) -> e1 d) -> ((a, b, c) -> e d)(ff: ($6205, $6206, $6207) -> $6209 $6208)(x1x1: $6205,x2x2: $6206,x3x3: $6207)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$6210>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $6208 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($6240) -> $6210 $6208,resres: $6240){ open1std/core/hnd/open1: forall<a,b,e,e1> (indices : vector<ev-index>, f : (a) -> e b, x : a) -> e1 b(indicesindices: vector<ev-index>,contcont: ($6240) -> $6210 $6208,resres: $6240) })std/core/types/(): ()
  yy: $6208

pub fun ".open4"<a1a1: V,a2a2: V,a3a3: V,a4a4: V,bb: V,e1e1: E,e2e2: E>( indicesindices: vector<ev-index> : vectorstd/core/types/vector: V -> V<ev-indexstd/core/hnd/ev-index: V>, ff: ($6279, $6280, $6281, $6282) -> $6284 $6283 : (a1a1: V,a2a2: V,a3a3: V,a4a4: V) -> e1e1: E bb: V, x1x1: $6279 : a1a1: V, x2x2: $6280 : a2a2: V, x3x3: $6281 : a3a3: V, x4x4: $6282 : a4a4: V ) : e2e2: E bb: V 
  val ww: evv<$6285> = evv-swap-createstd/core/hnd/evv-swap-create: forall<e> (indices : vector<ev-index>) -> e evv<e>(indicesindices: vector<ev-index>)
  val yy: $6283 = cast-ev4std/core/hnd/cast-ev4: forall<a,b,c,d,a1,e,e1> (f : (a, b, c, d) -> e1 a1) -> ((a, b, c, d) -> e a1)(ff: ($6279, $6280, $6281, $6282) -> $6284 $6283)(x1x1: $6279,x2x2: $6280,x3x3: $6281,x4x4: $6282)
  evv-setstd/core/hnd/evv-set: forall<e,e1> (w : evv<e1>) -> e ()(ww: evv<$6285>)
  if yieldingstd/core/hnd/yielding: () -> bool() returnreturn: $6283 yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($6317) -> $6285 $6283,resres: $6317){ open1std/core/hnd/open1: forall<a,b,e,e1> (indices : vector<ev-index>, f : (a) -> e b, x : a) -> e1 b(indicesindices: vector<ev-index>,contcont: ($6317) -> $6285 $6283,resres: $6317) })std/core/types/(): ()
  yy: $6283

// -------------------------------------------
// capture yields
// -------------------------------------------

pub fun unsafe-try-finalizestd/core/hnd/unsafe-try-finalize: forall<a,e> (action : () -> e a) -> e either<yield-info,a>( actionaction: () -> $10778 $10777 : () -> ee: E aa: V ) : ee: E eitherstd/core/types/either: (V, V) -> V<yield-infostd/core/hnd/yield-info: V,aa: V> 
  try-finalize-promptstd/core/hnd/try-finalize-prompt: forall<a,e> (res : a) -> e either<yield-info,a>(actionaction: () -> $10778 $10777());

fun try-finalize-promptstd/core/hnd/try-finalize-prompt: forall<a,e> (res : a) -> e either<yield-info,a>( resres: $10561 : aa: V ) : ee: E eitherstd/core/types/either: (V, V) -> V<yield-infostd/core/hnd/yield-info: V,aa: V> 
  if yielding-non-finalstd/core/hnd/yielding-non-final: () -> bool() returnreturn: either<yield-info,$10561> yield-contstd/core/hnd/yield-cont: forall<a,e,b> (f : forall<c> ((c) -> e a, c) -> e b) -> e b(fn(contcont: ($10570) -> $10562 $10561,xx: $10570) try-finalize-promptstd/core/hnd/try-finalize-prompt: forall<a,e> (res : a) -> e either<yield-info,a>(unsafe-decreasingstd/core/types/unsafe-decreasing: forall<a> (x : a) -> a(contcont: ($10570) -> $10562 $10561(xx: $10570))) )