watr 4.6.8 → 4.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/watr.js CHANGED
@@ -1367,27 +1367,25 @@ var parse_default = (str2) => {
1367
1367
  };
1368
1368
 
1369
1369
  // src/compile.js
1370
- var cleanup = (node, result) => !Array.isArray(node) ? typeof node !== "string" ? node : (
1371
- // skip comments: ;; ... or (; ... ;)
1372
- node[0] === ";" || node[1] === ";" ? null : (
1370
+ var isDroppable = (n) => typeof n === "string" && (n[0] === ";" || n[1] === ";") || Array.isArray(n) && n[0]?.[0] === "@" && n[0] !== "@custom" && !n[0]?.startsWith?.("@metadata.code.");
1371
+ var cleanup = (node, result) => {
1372
+ if (typeof node === "string") return (
1373
1373
  // normalize quoted ids: $"name" -> $name (if no escapes), else $unescaped
1374
1374
  node[0] === "$" && node[1] === '"' ? node.includes("\\") ? "$" + unescape(node.slice(1)) : "$" + node.slice(2, -1) : (
1375
1375
  // convert string literals to byte arrays with valueOf
1376
1376
  node[0] === '"' ? str(node) : node
1377
1377
  )
1378
- )
1379
- ) : (
1380
- // remove annotations like (@name ...) except @custom and @metadata.code.*
1381
- node[0]?.[0] === "@" && node[0] !== "@custom" && !node[0]?.startsWith?.("@metadata.code.") ? null : (
1382
- // unwrap single-element array containing module (after removing comments), preserve .loc
1383
- (result = node.map(cleanup).filter((n) => n != null), result.loc = node.loc, result.length === 1 && result[0]?.[0] === "module" ? result[0] : result)
1384
- )
1385
- );
1378
+ );
1379
+ if (!Array.isArray(node)) return node;
1380
+ result = node.filter((c) => !isDroppable(c)).map(cleanup);
1381
+ result.loc = node.loc;
1382
+ return result.length === 1 && result[0]?.[0] === "module" ? result[0] : result;
1383
+ };
1386
1384
  function compile(nodes) {
1387
1385
  if (typeof nodes === "string") err.src = nodes, nodes = parse_default(nodes) || [];
1388
1386
  else err.src = "";
1389
1387
  err.loc = 0;
1390
- nodes = cleanup(nodes) || [];
1388
+ nodes = isDroppable(nodes) ? [] : cleanup(nodes) ?? [];
1391
1389
  let idx = 0;
1392
1390
  if (nodes[0] === "module") idx++, isId(nodes[idx]) && idx++;
1393
1391
  else if (typeof nodes[0] === "string") nodes = [nodes];
@@ -2157,7 +2155,7 @@ function print(tree, options = {}) {
2157
2155
  let flat = !!newline && node.length < 4 && !node.some((n) => typeof n === "string" && n[0] === ";" && n[1] === ";");
2158
2156
  let curIndent = indent.repeat(level + 1);
2159
2157
  for (let i = 1; i < node.length; i++) {
2160
- const sub = node[i].valueOf();
2158
+ const sub = node[i]?.valueOf?.() ?? node[i];
2161
2159
  if (typeof sub === "string" && sub[1] === ";") {
2162
2160
  if (!comments) continue;
2163
2161
  if (sub[0] === ";") {
@@ -3755,6 +3753,17 @@ var readsMemory = (node) => {
3755
3753
  for (let i = 1; i < node.length; i++) if (readsMemory(node[i])) return true;
3756
3754
  return false;
3757
3755
  };
3756
+ var readsCallableState = (node) => {
3757
+ if (!Array.isArray(node)) return false;
3758
+ const op = node[0];
3759
+ if (typeof op === "string") {
3760
+ if (op === "global.get" || op === "table.get" || op === "table.size") return true;
3761
+ if (op === "call" || op === "call_indirect" || op === "return_call" || op === "return_call_indirect") return true;
3762
+ if (op.includes(".load") || op === "memory.copy" || op === "memory.size") return true;
3763
+ }
3764
+ for (let i = 1; i < node.length; i++) if (readsCallableState(node[i])) return true;
3765
+ return false;
3766
+ };
3758
3767
  var writesMemory = (node) => {
3759
3768
  if (!Array.isArray(node)) return false;
3760
3769
  const op = node[0];
@@ -3816,6 +3825,13 @@ var forwardPropagate = (funcNode, params, useCounts) => {
3816
3825
  instr2[2] = sr;
3817
3826
  changed = true;
3818
3827
  }
3828
+ walk(instr2[2], (n) => {
3829
+ if (!Array.isArray(n)) return;
3830
+ if ((n[0] === "local.set" || n[0] === "local.tee") && typeof n[1] === "string") {
3831
+ known.delete(n[1]);
3832
+ purgeRefs(known, n[1]);
3833
+ }
3834
+ });
3819
3835
  const uses = getUseCount(instr2[1]);
3820
3836
  purgeRefs(known, instr2[1]);
3821
3837
  if (writesMemory(instr2[2])) {
@@ -3831,7 +3847,7 @@ var forwardPropagate = (funcNode, params, useCounts) => {
3831
3847
  }
3832
3848
  if (op === "block" || op === "loop" || op === "if") known.clear();
3833
3849
  if (op === "call" || op === "call_indirect" || op === "return_call" || op === "return_call_indirect") {
3834
- for (const [key, tracked] of known) if (!getConst(tracked.val)) known.delete(key);
3850
+ for (const [key, tracked] of known) if (readsCallableState(tracked.val)) known.delete(key);
3835
3851
  }
3836
3852
  if (op === "local.get" && instr2.length === 2 && typeof instr2[1] === "string") {
3837
3853
  const tracked = known.get(instr2[1]);
package/dist/watr.min.js CHANGED
@@ -1,6 +1,6 @@
1
- var Le=Object.defineProperty;var Ce=(t,e)=>{for(var r in e)Le(t,r,{get:e[r],enumerable:!0})};var bt={};Ce(bt,{f32:()=>ct,f64:()=>ft,i16:()=>je,i32:()=>P,i64:()=>nt,i8:()=>Pe,uleb:()=>h,uleb5:()=>We,v128:()=>Ct});var B=(t,e=B.loc)=>{if(e!=null&&B.src){let r=1,i=1;for(let s=0;s<e&&s<B.src.length;s++)B.src[s]===`
2
- `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)},se=/^_|_$|[^\da-f]_|_[^\da-f]/i,ne=/^[+-]?(?:0x[\da-f]+|\d+)$/i,De=new TextEncoder,Re=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),ie={n:10,r:13,t:9,'"':34,"'":39,"\\":92},At=t=>{let e=[],r=1,i,s,n="",l=()=>(n&&e.push(...De.encode(n)),n="");for(;r<t.length-1;)s=t[r++],i=null,s==="\\"&&(t[r]==="u"?(r++,r++,s=String.fromCodePoint(parseInt(t.slice(r,r=t.indexOf("}",r)),16)),r++):ie[t[r]]?i=ie[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(l(),e.push(i)):n+=s;return l(),e.valueOf=()=>t,e},le=t=>Re.decode(new Uint8Array(At(t))),G=t=>Array.isArray(t)?t.map(G):t,S=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)S(t[s],e,t,s)},U=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++)U(t[n],e,t,n);let s=e(t,r,i);return s!==void 0&&r&&(r[i]=s),s!==void 0?s:t};var h=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):P.parse(t)),typeof t=="bigint"){for(;;){let i=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(i);break}e.push(i|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),h(t,e))};function We(t){let e=[];for(let r=0;r<5;r++){let i=t&127;t>>>=7,r<4&&(i|=128),e.push(i)}return e}function P(t,e=[]){for(typeof t=="string"&&(t=P.parse(t));;){let r=Number(t&127);if(t>>=7,t===0&&!(r&64)||t===-1&&r&64){e.push(r);break}e.push(r|128)}return e}var oe=t=>!se.test(t)&&ne.test(t=t.replaceAll("_",""))?t:B(`Bad int ${t}`),Pe=P,je=P;P.parse=t=>(t=parseInt(oe(t)),(t<-2147483648||t>4294967295)&&B("i32 constant out of range"),t);function nt(t,e=[]){for(typeof t=="string"?t=nt.parse(t):typeof t=="number"&&(t=BigInt(t)),typeof t=="bigint"&&t>0x7fffffffffffffffn&&(t=t-0x10000000000000000n);;){let r=Number(t&0x7Fn);if(t>>=7n,t===0n&&!(r&64)||t===-1n&&r&64){e.push(r);break}e.push(r|128)}return e}var _t=new ArrayBuffer(8),X=new Uint8Array(_t),Ge=new Int32Array(_t),He=new Float32Array(_t),Ve=new Float64Array(_t),Lt=new BigInt64Array(_t);nt.parse=t=>{t=oe(t);let e=t[0]==="-",r=e||t[0]==="+"?t.slice(1):t,i;if(r[0]==="0"&&(r[1]==="x"||r[1]==="X")){let n=r.slice(2).replace(/^0+/,"")||"0";i=e?"8000000000000000":"ffffffffffffffff",(n.length>16||n.length===16&&n.toLowerCase()>i)&&B("i64 constant out of range")}else{let n=r.replace(/^0+/,"")||"0";i=e?"9223372036854775808":"18446744073709551615",(n.length>i.length||n.length===i.length&&n>i)&&B("i64 constant out of range")}let s=BigInt(r);return e&&(s=0n-s),Lt[0]=s,Lt[0]};var Ye=2147483648,Xe=2139095040,ae=4194304;function ct(t,e,r){if(typeof t=="string"&&(r=t.indexOf("nan"))>=0){if(t[r+3]===":"){let i=t.slice(r+4);e=i==="canonical"||i==="arithmetic"?ae:P.parse(i)}else e=ae;e=(e|Xe)>>>0,t[0]==="-"&&(e=(e|Ye)>>>0),Ge[0]=e|0}else e=typeof t=="string"?ct.parse(t):t,He[0]=e;return[X[0],X[1],X[2],X[3]]}var Ze=0x8000000000000000n,Ke=0x7ff0000000000000n,fe=0x8000000000000n;function ft(t,e,r){if(typeof t=="string"&&(r=t.indexOf("nan"))>=0){if(t[r+3]===":"){let i=t.slice(r+4);e=i==="canonical"||i==="arithmetic"?fe:nt.parse(i)}else e=fe;e|=Ke,t[0]==="-"&&(e|=Ze),Lt[0]=e}else e=typeof t=="string"?ft.parse(t):t,Ve[0]=e;return[X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7]]}ft.parse=(t,e=Number.MAX_VALUE)=>{t=t.replaceAll("_","");let r=1;if(t[0]==="-"?(r=-1,t=t.slice(1)):t[0]==="+"&&(t=t.slice(1)),t[1]==="x"){let[i,s="0"]=t.split(/p/i),[n,l=""]=i.split("."),a=l.length??0,o=0;for(let u=n.length-1;u>=2;u--){let p=parseInt(n[u],16);o+=p*16**(n.length-1-u)}let f=l?parseInt("0x"+l)/16**a:0;s=parseInt(s,10);let c=r*(o+f)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};ct.parse=t=>ft.parse(t,34028234663852886e22);var Ct=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let i=0;i<16;i++)r[i]=Number(e&0xffn),e>>=8n;return[...r]};var ht=["unreachable","nop","block block","loop block","if block","else null","then null",,"throw tagidx",,"throw_ref","end end","br labelidx","br_if labelidx","br_table br_table","return","call funcidx","call_indirect call_indirect","return_call funcidx","return_call_indirect call_indirect","call_ref typeidx","return_call_ref typeidx",,,,,"drop","select select","",,,"try_table try_table","local.get localidx","local.set localidx","local.tee localidx","global.get globalidx","global.set globalidx","table.get tableidx","table.set tableidx",,"i32.load memarg","i64.load memarg","f32.load memarg","f64.load memarg","i32.load8_s memarg","i32.load8_u memarg","i32.load16_s memarg","i32.load16_u memarg","i64.load8_s memarg","i64.load8_u memarg","i64.load16_s memarg","i64.load16_u memarg","i64.load32_s memarg","i64.load32_u memarg","i32.store memarg","i64.store memarg","f32.store memarg","f64.store memarg","i32.store8 memarg","i32.store16 memarg","i64.store8 memarg","i64.store16 memarg","i64.store32 memarg","memory.size opt_memory","memory.grow opt_memory","i32.const i32","i64.const i64","f32.const f32","f64.const f64","i32.eqz","i32.eq","i32.ne","i32.lt_s","i32.lt_u","i32.gt_s","i32.gt_u","i32.le_s","i32.le_u","i32.ge_s","i32.ge_u","i64.eqz","i64.eq","i64.ne","i64.lt_s","i64.lt_u","i64.gt_s","i64.gt_u","i64.le_s","i64.le_u","i64.ge_s","i64.ge_u","f32.eq","f32.ne","f32.lt","f32.gt","f32.le","f32.ge","f64.eq","f64.ne","f64.lt","f64.gt","f64.le","f64.ge","i32.clz","i32.ctz","i32.popcnt","i32.add","i32.sub","i32.mul","i32.div_s","i32.div_u","i32.rem_s","i32.rem_u","i32.and","i32.or","i32.xor","i32.shl","i32.shr_s","i32.shr_u","i32.rotl","i32.rotr","i64.clz","i64.ctz","i64.popcnt","i64.add","i64.sub","i64.mul","i64.div_s","i64.div_u","i64.rem_s","i64.rem_u","i64.and","i64.or","i64.xor","i64.shl","i64.shr_s","i64.shr_u","i64.rotl","i64.rotr","f32.abs","f32.neg","f32.ceil","f32.floor","f32.trunc","f32.nearest","f32.sqrt","f32.add","f32.sub","f32.mul","f32.div","f32.min","f32.max","f32.copysign","f64.abs","f64.neg","f64.ceil","f64.floor","f64.trunc","f64.nearest","f64.sqrt","f64.add","f64.sub","f64.mul","f64.div","f64.min","f64.max","f64.copysign","i32.wrap_i64","i32.trunc_f32_s","i32.trunc_f32_u","i32.trunc_f64_s","i32.trunc_f64_u","i64.extend_i32_s","i64.extend_i32_u","i64.trunc_f32_s","i64.trunc_f32_u","i64.trunc_f64_s","i64.trunc_f64_u","f32.convert_i32_s","f32.convert_i32_u","f32.convert_i64_s","f32.convert_i64_u","f32.demote_f64","f64.convert_i32_s","f64.convert_i32_u","f64.convert_i64_s","f64.convert_i64_u","f64.promote_f32","i32.reinterpret_f32","i64.reinterpret_f64","f32.reinterpret_i32","f64.reinterpret_i64","i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s",,,,,,,,,,,,"ref.null ref_null","ref.is_null","ref.func funcidx","ref.eq","ref.as_non_null","br_on_null labelidx","br_on_non_null labelidx",,,,,,,,,,"cont.new typeidx","cont.bind cont_bind","suspend tagidx","resume resume","resume_throw resume_throw","resume_throw_ref resume_throw_ref","switch switch_cont",,,,,,,,,,,,,,,,,,,,,["struct.new typeidx","struct.new_default typeidx","struct.get typeidx_field","struct.get_s typeidx_field","struct.get_u typeidx_field","struct.set typeidx_field","array.new typeidx","array.new_default typeidx","array.new_fixed typeidx_multi","array.new_data typeidx_dataidx","array.new_elem typeidx_elemidx","array.get typeidx","array.get_s typeidx","array.get_u typeidx","array.set typeidx","array.len","array.fill typeidx","array.copy typeidx_typeidx","array.init_data typeidx_dataidx","array.init_elem typeidx_elemidx","ref.test reftype","ref.test_null reftype","ref.cast reftype","ref.cast_null reftype","br_on_cast reftype2","br_on_cast_fail reftype2","any.convert_extern","extern.convert_any","ref.i31","i31.get_s","i31.get_u",,"struct.new_desc typeidx","struct.new_default_desc typeidx","ref.get_desc typeidx","ref.cast_desc_eq reftype",,"br_on_cast_desc_eq reftype2","br_on_cast_desc_eq_fail reftype2",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"string.new_utf8 memoryidx?","string.new_wtf16 memoryidx?","string.const stringidx","string.measure_utf8","string.measure_wtf8","string.measure_wtf16","string.encode_utf8 memoryidx?","string.encode_wtf16 memoryidx?","string.concat","string.eq","string.is_usv_sequence","string.new_lossy_utf8 memoryidx?","string.new_wtf8 memoryidx?","string.encode_lossy_utf8 memoryidx?","string.encode_wtf8 memoryidx?",,"string.as_wtf8","stringview_wtf8.advance","stringview_wtf8.encode_utf8 memoryidx?","stringview_wtf8.slice","stringview_wtf8.encode_lossy_utf8 memoryidx?","stringview_wtf8.encode_wtf8 memoryidx?",,,"string.as_wtf16","stringview_wtf16.length","stringview_wtf16.get_codeunit","stringview_wtf16.encode memoryidx?","stringview_wtf16.slice",,,,"string.as_iter","stringview_iter.next","stringview_iter.advance","stringview_iter.rewind","stringview_iter.slice",,,,,,,,,,,,"string.new_utf8_array","string.new_wtf16_array","string.encode_utf8_array","string.encode_wtf16_array","string.new_lossy_utf8_array","string.new_wtf8_array","string.encode_lossy_utf8_array","string.encode_wtf8_array"],["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u","memory.init dataidx_memoryidx","data.drop dataidx","memory.copy memoryidx_memoryidx","memory.fill memoryidx?","table.init reversed","elem.drop elemidx","table.copy tableidx_tableidx","table.grow tableidx","table.size tableidx","table.fill tableidx",,"i64.add128","i64.sub128","i64.mul_wide_s","i64.mul_wide_u",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"f32.sqrt_ceil","f32.add_ceil","f32.sub_ceil","f32.mul_ceil","f32.div_ceil","f64.sqrt_ceil","f64.add_ceil","f64.sub_ceil","f64.mul_ceil","f64.div_ceil","f32.convert_ceil_i32_s","f32.convert_ceil_i32_u","f32.convert_ceil_i64_s","f32.convert_ceil_i64_u","f32.demote_ceil_f64","f64.convert_ceil_i32_s","f64.convert_ceil_i32_u","f64.convert_ceil_i64_s","f64.convert_ceil_i64_u","f64.promote_ceil_f32","f32.sqrt_floor","f32.add_floor","f32.sub_floor","f32.mul_floor","f32.div_floor","f64.sqrt_floor","f64.add_floor","f64.sub_floor","f64.mul_floor","f64.div_floor","f32.convert_floor_i32_s","f32.convert_floor_i32_u","f32.convert_floor_i64_s","f32.convert_floor_i64_u","f32.demote_floor_f64","f64.convert_floor_i32_s","f64.convert_floor_i32_u","f64.convert_floor_i64_s","f64.convert_floor_i64_u","f64.promote_floor_f32","f32.sqrt_trunc","f32.add_trunc","f32.sub_trunc","f32.mul_trunc","f32.div_trunc","f64.sqrt_trunc","f64.add_trunc","f64.sub_trunc","f64.mul_trunc","f64.div_trunc","f32.convert_trunc_i32_s","f32.convert_trunc_i32_u","f32.convert_trunc_i64_s","f32.convert_trunc_i64_u","f32.demote_trunc_f64","f64.convert_trunc_i32_s","f64.convert_trunc_i32_u","f64.convert_trunc_i64_s","f64.convert_trunc_i64_u","f64.promote_trunc_f32"],["v128.load memarg","v128.load8x8_s memarg","v128.load8x8_u memarg","v128.load16x4_s memarg","v128.load16x4_u memarg","v128.load32x2_s memarg","v128.load32x2_u memarg","v128.load8_splat memarg","v128.load16_splat memarg","v128.load32_splat memarg","v128.load64_splat memarg","v128.store memarg","v128.const v128const","i8x16.shuffle shuffle","i8x16.swizzle","i8x16.splat","i16x8.splat","i32x4.splat","i64x2.splat","f32x4.splat","f64x2.splat","i8x16.extract_lane_s laneidx","i8x16.extract_lane_u laneidx","i8x16.replace_lane laneidx","i16x8.extract_lane_s laneidx","i16x8.extract_lane_u laneidx","i16x8.replace_lane laneidx","i32x4.extract_lane laneidx","i32x4.replace_lane laneidx","i64x2.extract_lane laneidx","i64x2.replace_lane laneidx","f32x4.extract_lane laneidx","f32x4.replace_lane laneidx","f64x2.extract_lane laneidx","f64x2.replace_lane laneidx","i8x16.eq","i8x16.ne","i8x16.lt_s","i8x16.lt_u","i8x16.gt_s","i8x16.gt_u","i8x16.le_s","i8x16.le_u","i8x16.ge_s","i8x16.ge_u","i16x8.eq","i16x8.ne","i16x8.lt_s","i16x8.lt_u","i16x8.gt_s","i16x8.gt_u","i16x8.le_s","i16x8.le_u","i16x8.ge_s","i16x8.ge_u","i32x4.eq","i32x4.ne","i32x4.lt_s","i32x4.lt_u","i32x4.gt_s","i32x4.gt_u","i32x4.le_s","i32x4.le_u","i32x4.ge_s","i32x4.ge_u","f32x4.eq","f32x4.ne","f32x4.lt","f32x4.gt","f32x4.le","f32x4.ge","f64x2.eq","f64x2.ne","f64x2.lt","f64x2.gt","f64x2.le","f64x2.ge","v128.not","v128.and","v128.andnot","v128.or","v128.xor","v128.bitselect","v128.any_true","v128.load8_lane memlane","v128.load16_lane memlane","v128.load32_lane memlane","v128.load64_lane memlane","v128.store8_lane memlane","v128.store16_lane memlane","v128.store32_lane memlane","v128.store64_lane memlane","v128.load32_zero memarg","v128.load64_zero memarg","f32x4.demote_f64x2_zero","f64x2.promote_low_f32x4","i8x16.abs","i8x16.neg","i8x16.popcnt","i8x16.all_true","i8x16.bitmask","i8x16.narrow_i16x8_s","i8x16.narrow_i16x8_u","f32x4.ceil","f32x4.floor","f32x4.trunc","f32x4.nearest","i8x16.shl","i8x16.shr_s","i8x16.shr_u","i8x16.add","i8x16.add_sat_s","i8x16.add_sat_u","i8x16.sub","i8x16.sub_sat_s","i8x16.sub_sat_u","f64x2.ceil","f64x2.floor","i8x16.min_s","i8x16.min_u","i8x16.max_s","i8x16.max_u","f64x2.trunc","i8x16.avgr_u","i16x8.extadd_pairwise_i8x16_s","i16x8.extadd_pairwise_i8x16_u","i32x4.extadd_pairwise_i16x8_s","i32x4.extadd_pairwise_i16x8_u","i16x8.abs","i16x8.neg","i16x8.q15mulr_sat_s","i16x8.all_true","i16x8.bitmask","i16x8.narrow_i32x4_s","i16x8.narrow_i32x4_u","i16x8.extend_low_i8x16_s","i16x8.extend_high_i8x16_s","i16x8.extend_low_i8x16_u","i16x8.extend_high_i8x16_u","i16x8.shl","i16x8.shr_s","i16x8.shr_u","i16x8.add","i16x8.add_sat_s","i16x8.add_sat_u","i16x8.sub","i16x8.sub_sat_s","i16x8.sub_sat_u","f64x2.nearest","i16x8.mul","i16x8.min_s","i16x8.min_u","i16x8.max_s","i16x8.max_u",,"i16x8.avgr_u","i16x8.extmul_low_i8x16_s","i16x8.extmul_high_i8x16_s","i16x8.extmul_low_i8x16_u","i16x8.extmul_high_i8x16_u","i32x4.abs","i32x4.neg",,"i32x4.all_true","i32x4.bitmask",,,"i32x4.extend_low_i16x8_s","i32x4.extend_high_i16x8_s","i32x4.extend_low_i16x8_u","i32x4.extend_high_i16x8_u","i32x4.shl","i32x4.shr_s","i32x4.shr_u","i32x4.add",,,"i32x4.sub",,,,"i32x4.mul","i32x4.min_s","i32x4.min_u","i32x4.max_s","i32x4.max_u","i32x4.dot_i16x8_s",,"i32x4.extmul_low_i16x8_s","i32x4.extmul_high_i16x8_s","i32x4.extmul_low_i16x8_u","i32x4.extmul_high_i16x8_u","i64x2.abs","i64x2.neg",,"i64x2.all_true","i64x2.bitmask",,,"i64x2.extend_low_i32x4_s","i64x2.extend_high_i32x4_s","i64x2.extend_low_i32x4_u","i64x2.extend_high_i32x4_u","i64x2.shl","i64x2.shr_s","i64x2.shr_u","i64x2.add",,,"i64x2.sub",,,,"i64x2.mul","i64x2.eq","i64x2.ne","i64x2.lt_s","i64x2.gt_s","i64x2.le_s","i64x2.ge_s","i64x2.extmul_low_i32x4_s","i64x2.extmul_high_i32x4_s","i64x2.extmul_low_i32x4_u","i64x2.extmul_high_i32x4_u","f32x4.abs","f32x4.neg",,"f32x4.sqrt","f32x4.add","f32x4.sub","f32x4.mul","f32x4.div","f32x4.min","f32x4.max","f32x4.pmin","f32x4.pmax","f64x2.abs","f64x2.neg",,"f64x2.sqrt","f64x2.add","f64x2.sub","f64x2.mul","f64x2.div","f64x2.min","f64x2.max","f64x2.pmin","f64x2.pmax","i32x4.trunc_sat_f32x4_s","i32x4.trunc_sat_f32x4_u","f32x4.convert_i32x4_s","f32x4.convert_i32x4_u","i32x4.trunc_sat_f64x2_s_zero","i32x4.trunc_sat_f64x2_u_zero","f64x2.convert_low_i32x4_s","f64x2.convert_low_i32x4_u","i8x16.relaxed_swizzle","i32x4.relaxed_trunc_f32x4_s","i32x4.relaxed_trunc_f32x4_u","i32x4.relaxed_trunc_f64x2_s_zero","i32x4.relaxed_trunc_f64x2_u_zero","f32x4.relaxed_madd","f32x4.relaxed_nmadd","f64x2.relaxed_madd","f64x2.relaxed_nmadd","i8x16.relaxed_laneselect","i16x8.relaxed_laneselect","i32x4.relaxed_laneselect","i64x2.relaxed_laneselect","f32x4.relaxed_min","f32x4.relaxed_max","f64x2.relaxed_min","f64x2.relaxed_max","i16x8.relaxed_q15mulr_s","i16x8.relaxed_dot_i8x16_i7x16_s","i32x4.relaxed_dot_i8x16_i7x16_add_s"],["memory.atomic.notify memarg","memory.atomic.wait32 memarg","memory.atomic.wait64 memarg","atomic.fence opt_memory",,,,,,,,,,,,,"i32.atomic.load memarg","i64.atomic.load memarg","i32.atomic.load8_u memarg","i32.atomic.load16_u memarg","i64.atomic.load8_u memarg","i64.atomic.load16_u memarg","i64.atomic.load32_u memarg","i32.atomic.store memarg","i64.atomic.store memarg","i32.atomic.store8 memarg","i32.atomic.store16 memarg","i64.atomic.store8 memarg","i64.atomic.store16 memarg","i64.atomic.store32 memarg","i32.atomic.rmw.add memarg","i64.atomic.rmw.add memarg","i32.atomic.rmw8.add_u memarg","i32.atomic.rmw16.add_u memarg","i64.atomic.rmw8.add_u memarg","i64.atomic.rmw16.add_u memarg","i64.atomic.rmw32.add_u memarg","i32.atomic.rmw.sub memarg","i64.atomic.rmw.sub memarg","i32.atomic.rmw8.sub_u memarg","i32.atomic.rmw16.sub_u memarg","i64.atomic.rmw8.sub_u memarg","i64.atomic.rmw16.sub_u memarg","i64.atomic.rmw32.sub_u memarg","i32.atomic.rmw.and memarg","i64.atomic.rmw.and memarg","i32.atomic.rmw8.and_u memarg","i32.atomic.rmw16.and_u memarg","i64.atomic.rmw8.and_u memarg","i64.atomic.rmw16.and_u memarg","i64.atomic.rmw32.and_u memarg","i32.atomic.rmw.or memarg","i64.atomic.rmw.or memarg","i32.atomic.rmw8.or_u memarg","i32.atomic.rmw16.or_u memarg","i64.atomic.rmw8.or_u memarg","i64.atomic.rmw16.or_u memarg","i64.atomic.rmw32.or_u memarg","i32.atomic.rmw.xor memarg","i64.atomic.rmw.xor memarg","i32.atomic.rmw8.xor_u memarg","i32.atomic.rmw16.xor_u memarg","i64.atomic.rmw8.xor_u memarg","i64.atomic.rmw16.xor_u memarg","i64.atomic.rmw32.xor_u memarg","i32.atomic.rmw.xchg memarg","i64.atomic.rmw.xchg memarg","i32.atomic.rmw8.xchg_u memarg","i32.atomic.rmw16.xchg_u memarg","i64.atomic.rmw8.xchg_u memarg","i64.atomic.rmw16.xchg_u memarg","i64.atomic.rmw32.xchg_u memarg","i32.atomic.rmw.cmpxchg memarg","i64.atomic.rmw.cmpxchg memarg","i32.atomic.rmw8.cmpxchg_u memarg","i32.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw8.cmpxchg_u memarg","i64.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw32.cmpxchg_u memarg"]],xt=t=>{if(typeof t!="string")return null;let e=t.indexOf(".");if(e<0)return null;let r=t.slice(0,e),i=r==="i32"||r==="i64"||r==="f32"||r==="f64";return i&&/^(eqz?|ne|[lg][te])(_[su])?$/.test(t.slice(e+1))?"i32":i||r==="v128"?r:t==="memory.size"||t==="memory.grow"?"i32":null},R={custom:0,type:1,import:2,func:3,table:4,memory:5,tag:13,strings:14,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},W={i8:120,i16:119,i32:127,i64:126,f32:125,f64:124,void:64,v128:123,exn:105,noexn:116,nofunc:115,noextern:114,none:113,func:112,extern:111,any:110,eq:109,i31:108,struct:107,array:106,data:107,cont:104,nocont:117,string:103,stringview_wtf8:102,stringview_wtf16:96,stringview_iter:97,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,contref:104,nocontref:117,stringref:103,ref:100,refnull:99,sub:80,subfinal:79,rec:78},lt={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},Dt={func:0,table:1,memory:2,global:3,tag:4};var et=t=>{let e=0,r=[],i="",s=0,n=0,l=()=>i&&(r.push(i),i=""),a=o=>{r.loc=o;for(let f,c,u;e<t.length;)if(f=t.charCodeAt(e),s===34)i+=t[e++],f===92?i+=t[e++]:f===34&&(l(),s=0);else if(s>59)f===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(l(),s=0)):i+=t[e++];else if(s<0)f===10||f===13?(i+=t[e++],l(),s=0):s===-2&&f===41?(l(),s=0):i+=t[e++];else if(f===34)i!=="$"&&l(),s=34,i+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)l(),s=60,i=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)l(),s=t.indexOf(`
3
- `,e)<0?-2:-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)l(),u=e,e+=2,i="@",n++,(c=r).push(r=[]),a(u),r=c;else if(f===40)l(),u=e++,n++,(c=r).push(r=[]),a(u),r=c;else{if(f===41)return l(),e++,n--;f<=32?(l(),e++):i+=t[e++]}s<0&&l(),l()};return a(0),s===34&&B("Unclosed quote",e),s>59&&B("Unclosed block comment",e),n>0&&B("Unclosed parenthesis",e),e<t.length&&B("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var ye=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(ye).filter(r=>r!=null),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):typeof t!="string"?t:t[0]===";"||t[1]===";"?null:t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+le(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?At(t):t;function yt(t){typeof t=="string"?(B.src=t,t=et(t)||[]):B.src="",B.loc=0,t=ye(t)||[];let e=0;if(t[0]==="module"?(e++,H(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return yt(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,p)=>{if(p<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,y,...g]=u;if(!g.some(_=>Array.isArray(_)&&_[0]==="item"))return[u];if(Array.isArray(g.at(-1))&&g.at(-1)[0]!=="item"){let _=g.at(-1);return g.slice(0,-1).filter(b=>b[0]==="item").map(([,b])=>["import",y,b,_])}return g.filter(_=>_[0]==="item").map(([,_,b])=>["import",y,_,b])});let r=[];for(let u in R)(r[R[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let g=B.loc,m=B.src,_;for(;(g=m.indexOf(u,g))>=0;){if(_=m.charCodeAt(g-1),g>0&&(_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95||_===36)){g++;continue}if(_=m.charCodeAt(g+u.length),_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95){g++;continue}break}g>=0&&(B.loc=g),B(`Unexpected token ${u}`)}let[p,...y]=u;if(B.loc=u.loc,p==="@custom")r.custom.push(y);else if(p==="rec")for(let g=0;g<y.length;g++){let[,...m]=y[g];Rt(m,r.type);let _=[];for(;m[0]?.[0]==="descriptor"||m[0]?.[0]==="describes";)_.push(m.shift());(m=ce(m,r)).push(g?!0:[r.type.length,y.length]),_.length&&(m.desc=m.desc?[..._,...m.desc]:_),r.type.push(m)}else if(p==="type"){Rt(y,r.type);let g=[];for(;y[0]?.[0]==="descriptor"||y[0]?.[0]==="describes";)g.push(y.shift());let m=ce(y,r);g.length&&(m.desc=m.desc?[...g,...m.desc]:g),r.type.push(m)}else if(p==="start"||p==="export")r[p].push(y);else return!0}).forEach(u=>{let[p,...y]=u;B.loc=u.loc;let g;p==="import"&&([p,...y]=(g=y).pop());let m=r[p];for(m||B(`Unknown section ${p}`),Rt(y,m);y[0]?.[0]==="export";)r.export.push([y.shift()[1],[p,m?.length]]);if(y[0]?.[0]==="import"&&([,...g]=y.shift()),p==="table"){let _=y[0]==="i64",b=_?1:0;if(y[b+1]?.[0]==="elem"){let[v,[,...A]]=[y[b],y[b+1]];y=_?["i64",A.length,A.length,v]:[A.length,A.length,v],r.elem.push([["table",m.length],["offset",[_?"i64.const":"i32.const",_?0n:0]],v,...A])}}else if(p==="memory"){let _=y[0]==="i64",b=_?1:0;if(y[b]?.[0]==="data"){let v=y.find(I=>Array.isArray(I)&&I[0]==="pagesize")?.[1]??65536,[,...A]=y.splice(b,1)[0],z=""+Math.ceil(A.reduce((I,M)=>I+M.length,0)/v);r.data.push([["memory",m.length],[_?"i64.const":"i32.const",_?0n:0],...A]),y=_?["i64",z,z]:[z,z]}}else if(p==="func"){let[_,b,v]=Nt(y,r);_??=Mt(b,v,r),!g&&r.code.push([[_,b,v],...st(y,r)]),y=[["type",_]]}else if(p==="tag"){let[_,b]=Nt(y,r);_??=Mt(b,[],r),y=[["type",_]]}g&&(r.import.push([...g,[p,...y]]),y=null),m.push(y)});let i=(u,p=!0)=>{let y=r[u].filter(Boolean).map(g=>pe[u](g,r)).filter(Boolean);return u===R.custom?y.flatMap(g=>[u,...C(g)]):y.length?[u,...C(p?C(y):y.flat())]:[]},s=()=>{let u=[];for(let p in r.metadata){let y=C(At(`"metadata.code.${p}"`)),g=C(r.metadata[p].map(([m,_])=>[...h(m),...C(_.map(([b,v])=>[...h(b),...C(v)]))]));u.push(0,...C([...y,...g]))}return u},n=i(R.global),l=i(R.elem),a=i(R.code),o=s(),f=i(R.data),c=r.strings.length?[R.strings,...C([0,...C(r.strings.map(u=>C(u)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(R.custom),...i(R.type),...i(R.import),...i(R.func),...i(R.table),...i(R.memory),...i(R.tag),...c,...n,...i(R.export),...i(R.start,!1),...l,...i(R.datacount,!1),...a,...o,...f])}var Z=t=>t?.[0]==="$"||!isNaN(t),H=t=>t?.[0]==="$",Wt=t=>t?.[0]==="a"||t?.[0]==="o";function st(t,e){let r=[];for(t=[...t];t.length;){let i=t.shift();if(typeof i=="string")if(r.push(i),i==="block"||i==="if"||i==="loop")H(t[0])&&r.push(t.shift()),r.push(wt(t,e));else if(i==="else"||i==="end")H(t[0])&&t.shift();else if(i==="select")r.push(Bt(t)[1]);else if(i.endsWith("call_indirect")){let s=Z(t[0])?t.shift():0,[n,l,a]=Nt(t,e);r.push(s,["type",n??Mt(l,a,e)])}else i==="table.init"?r.push(Z(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(Z(t[0])?t.shift():0,Z(t[0])?t.shift():0):i.startsWith("table.")?r.push(Z(t[0])?t.shift():0):i==="memory.init"?(r.push(...Z(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):i==="data.drop"||i==="array.new_data"||i==="array.init_data"?(i==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(i.startsWith("memory.")||i.endsWith("load")||i.endsWith("store"))&&Z(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(B.loc=i.loc),s?.startsWith?.("@metadata.code.")){let l=s.slice(15);r.push(["@metadata",l,i[1]]);continue}if(typeof s!="string"||!Array.isArray(ht[s])){r.push(i);continue}let n=i.slice(1);if(s==="block"||s==="loop")r.push(s),H(n[0])&&r.push(n.shift()),r.push(wt(n,e),...st(n,e),"end");else if(s==="if"){let l=[],a=[];n.at(-1)?.[0]==="else"&&(a=st(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=st(n.pop().slice(1),e));let o=[s];H(n[0])&&o.push(n.shift()),o.push(wt(n,e)),r.push(...st(n,e),...o,...l),a.length&&r.push("else",...a),r.push("end")}else if(s==="try_table"){for(r.push(s),H(n[0])&&r.push(n.shift()),r.push(wt(n,e));n[0]?.[0]==="catch"||n[0]?.[0]==="catch_ref"||n[0]?.[0]==="catch_all"||n[0]?.[0]==="catch_all_ref";)r.push(n.shift());r.push(...st(n,e),"end")}else if(s==="ref.test"||s==="ref.cast"){let l=n[0];(!Array.isArray(l)||l[1]==="null"||l[0]!=="ref")&&(s+="_null"),r.push(...st(n.slice(1),e),s,l),t.unshift(...r.splice(r.length-2))}else{let l=[];for(;n.length&&(!Array.isArray(n[0])||n[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(n[0][0]));)l.push(n.shift());r.push(...st(n,e),s,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(i)}return r}var Mt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),Pt=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=H(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},Bt=t=>{let e=Pt(t,"param"),r=Pt(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},Nt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...Bt(t)];let[,r]=t.shift(),[i,s]=Bt(t),n=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!n)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&n[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...n[1]]},wt=(t,e)=>{let[r,i,s]=Nt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??Mt(i,s,e)]},Rt=(t,e)=>{let r=H(t[0])&&t.shift();return r&&(r in e?B(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},ce=([t],e)=>{let r="subfinal",i=[],s,n=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(n.push(a),!1):!0)),[s,...t]=t,s==="func"?(t=Bt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=Pt(t,"field"):s==="array"&&([t]=t);let l=[s,t,r,i];return n.length&&(l.desc=n),l},pe=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...C(t),...i.flat()]},(t,e)=>{let[r,i,s,n,l]=t;if(l===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...h($(c,e.type))]),o=(f,c)=>f==="func"?[lt.func,...C(c[0].map(u=>Y(u,e))),...C(c[1].map(u=>Y(u,e)))]:f==="array"?[lt.array,...vt(c,e)]:f==="struct"?[lt.struct,...C(c.map(u=>vt(u,e)))]:f==="cont"?[lt.cont,...h($(c[0]??c,e.type))]:[lt[f]];if(l){let[f,c]=l,u=Array.from({length:c},(p,y)=>{let g=e.type[f+y],m=g.slice(0,4);return g.desc&&(m.desc=g.desc),pe[R.type](m,e)});return[lt.rec,...C(u)]}else if(s==="sub"||n?.length)return[lt[s],...C(n.map(f=>$(f,e.type))),...a,...o(r,i)];return[...a,...o(r,i)]},([t,e,[r,...i]],s)=>{let n,l=Dt[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(l=32);let[[,o]]=i;n=h($(o,s.type))}else if(r==="tag"){let[[,a]]=i;n=[0,...h($(a,s.type))]}else r==="memory"?n=$t(i):r==="global"?n=vt(i[0],s):r==="table"?n=[...Y(i.pop(),s),...$t(i)]:B(`Unknown kind ${r}`);return[...C(t),...C(e),l,...n]},([[,t]],e)=>h($(t,e.type)),(t,e)=>{let r=$t(t),i=Y(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...ut(s,e)]:[...i,...r]},(t,e)=>$t(t),([t,e],r)=>[...vt(t,r),...ut(e,r)],([t,[e,r]],i)=>[...C(t),Dt[e],...h($(r,i[e]))],([t],e)=>h($(t,e.func)),(t,e)=>{let r=0,i=0,s=0,n=0,l,a,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=$(l,e.table)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&t[1][0]!=="item"&&!t[1][0]?.startsWith("ref"))&&(l=$(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(a=t.shift(),a[0]==="offset"&&([,a]=a),a=ut(a,e)):i||(r=1),W[t[0]]||t[0]?.[0]==="ref"?o=Y(t.shift(),e):t[0]==="func"?o=[W[t.shift()]]:o=[W.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==W.funcref&&(n=1,s=1);let f=s<<2|(r||i?i:!!l||n)<<1|(r||i);return[f,...f===0?a:f===1?[0]:f===2?[...h(l||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...h(l||0),...a,...o]:o,...C(t.map(s?c=>ut(typeof c=="string"?["ref.func",c]:c,e):c=>h($(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[$(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(H(o[0])){let f=o.shift();f in e.local?B(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let n=ge(t,e),l=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([l,e.meta[o]]);let a=e.local.slice(i.length).reduce((o,f)=>(f==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,f]),o),[]);return e.local=e.block=e.meta=null,C([...C(a.map(([o,f])=>[...h(o),...Y(f,e)])),...n])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=$(i,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(i=$(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??B("Bad offset",r)),[...i?[2,...h(i),...ut(r,e)]:r?[0,...ut(r,e)]:[1],...C(t.flatMap(s=>tr(s)??[...s]))]},(t,e)=>h(e.data.length),([[,t]],e)=>[0,...h($(t,e.type))]],Y=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[W.refnull,98,...h($(t[2][1],e.type))]:W[t[2]]?[W[t[2]]]:[W.refnull,...h($(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[W.ref,98,...h($(t[1][1],e.type))]:[W.ref,...h(W[t[t.length-1]]||$(t[t.length-1],e.type))]:[W[t]??B(`Unknown type ${t}`)],vt=(t,e,r=t[0]==="mut"?1:0)=>[...Y(r?t[1]:t,e),r],me={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...h($(i,e.elem)),...h($(r,e.table))]},block:(t,e)=>{e.block.push(1),H(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?Y(r[1],e):h($(r[1],e.type)):[W.void]},try_table:(t,e)=>{H(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?Y(r[1],e):h($(r[1],e.type)):[W.void],s=[],n=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let l=t.shift(),a=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;a<=1?s.push(a,...h($(l[1],e.tag)),...h(at(l[2],e.block))):s.push(a,...h(at(l[1],e.block))),n++}return e.block.push(1),[...i,...h(n),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...h($(i,e.type)),...h($(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||H(t[0]));)r.push(...h(at(t.shift(),e.block))),i++;return[...h(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?C(r.map(i=>Y(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...h($(r[1],e.type))]:W[r]?[W[r]]:h($(r,e.type))},memarg:(t,e,r)=>ue(t,r,Z(t[0])&&!Wt(t[0])?$(t.shift(),e.memory):0),opt_memory:(t,e)=>h($(Z(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=Y(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=at(t.shift(),e.block),i=Y(t.shift(),e),s=Y(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(s[0]!==W.ref)<<1|i[0]!==W.ref,...h(r),...n(i),...n(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let l=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)l[a]=bt[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(bt[e](t.shift()),l*s);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(kt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&B("invalid lane length"),e},memlane:(t,e,r)=>{let i=H(t[0])||Z(t[0])&&(Wt(t[1])||Z(t[1]))?$(t.shift(),e.memory):0;return[...ue(t,r,i),...h(kt(t.shift()))]},"*":t=>h(t.shift()),labelidx:(t,e)=>h(at(t.shift(),e.block)),laneidx:t=>[kt(t.shift(),255)],funcidx:(t,e)=>h($(t.shift(),e.func)),typeidx:(t,e)=>h($(t.shift(),e.type)),tableidx:(t,e)=>h($(t.shift(),e.table)),memoryidx:(t,e)=>h($(t.shift(),e.memory)),globalidx:(t,e)=>h($(t.shift(),e.global)),localidx:(t,e)=>h($(t.shift(),e.local)),dataidx:(t,e)=>h($(t.shift(),e.data)),elemidx:(t,e)=>h($(t.shift(),e.elem)),tagidx:(t,e)=>h($(t.shift(),e.tag)),"memoryidx?":(t,e)=>h($(Z(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(n=>n.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),h(s)},i32:t=>P(t.shift()),i64:t=>nt(t.shift()),f32:t=>ct(t.shift()),f64:t=>ft(t.shift()),v128:t=>Ct(t.shift()),typeidx_field:(t,e)=>{let r=$(t.shift(),e.type);return[...h(r),...h($(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...h($(t.shift(),e.type)),...h(t.shift())],typeidx_dataidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...h($(t.shift(),e.data)),...h($(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...h($(t.shift(),e.memory)),...h($(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...h($(t.shift(),e.table)),...h($(t.shift(),e.table))],cont_bind:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.type))],switch_cont:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.tag))],resume:(t,e)=>{let r=h($(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...h($(n,e.tag))):i.push(0,...h($(n,e.tag)),...h(at(l,e.block))),s++}return[...r,...h(s),...i]},resume_throw:(t,e)=>{let r=h($(t.shift(),e.type)),i=h($(t.shift(),e.tag)),s=[],n=0;for(;t[0]?.[0]==="on";){let[,l,a]=t.shift();a==="switch"?s.push(1,...h($(l,e.tag))):s.push(0,...h($(l,e.tag)),...h(at(a,e.block))),n++}return[...r,...i,...h(n),...s]},resume_throw_ref:(t,e)=>{let r=h($(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...h($(n,e.tag))):i.push(0,...h($(n,e.tag)),...h(at(l,e.block))),s++}return[...r,...h(s),...i]}},It={};(function t(e,r){for(let i=0,s,n,l;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([n,l]=s.split(" "),ht[n]=r?[r,...h(i)]:[i],l&&(It[n]=me[l])))})(ht);var ge=(t,e)=>{let r=[],i=[];for(;t?.length;){let s=t.shift();if(s?.[0]==="@metadata"){i.push(s.slice(1));continue}Array.isArray(s)&&(s.loc!=null&&(B.loc=s.loc),B(`Unknown instruction ${s[0]}`));let[...n]=ht[s]||B(`Unknown instruction ${s}`);It[s]&&(s==="select"&&t[0]?.length?n[0]++:It[s]===me.reftype&&!s.endsWith("_null")&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...It[s](t,e,s)));for(let[l,a]of i)(e.meta[l]??=[]).push([r.length,a]);r.push(...n)}return r.push(11),r},ut=(t,e)=>ge(st([t],e),e),$=(t,e,r)=>(r=H(t)?e[t]:+t,r in e?r:B(`Unknown ${e.name} ${t}`)),at=(t,e,r)=>(r=H(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?B(`Bad label ${t}`):r),Qe=t=>{let e,r,i,s;for(;Wt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:B(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&B(`Bad offset ${r}`),(e<=0||e>4294967295)&&B(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&B(`Bad align ${e}`),[e,r]},ue=(t,e,r=0)=>{let[i,s]=Qe(t),n=(i??Je(e))|(r&&64);return r?[...h(n),...h(r),...h(s??0)]:[...h(n),...h(s??0)]},Je=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let n=t.slice(e,e+6).match(/\d+/);return Math.log2(n?n[0]/8:+r/8)}let i=t[e]==="l"?e+4:e+5,s=t.slice(i).match(/(\d+)(x|_|$)/);return Math.log2(s?s[2]==="x"?8:s[1]/8:+r/8)},tr=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?i.push(P.parse(n)&511&255):e==="i16"?(s.setInt16(0,P.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,P.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(n),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...ct(n)):e==="f64"&&i.push(...ft(n));return i},$t=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let n=!isNaN(parseInt(t[1])),l=(s>=0?8:0)|(e?4:0)|(r?2:0)|(n?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:kt,o=s>=0?h(s):[];return n?[l,...h(a(t.shift())),...h(a(t.shift())),...o]:[l,...h(a(t.shift())),...o]},kt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?P.parse(t):typeof t=="number"?t:B(`Bad int ${t}`);return r>e?B(`Value out of range ${t}`):r},C=t=>[...h(t.length),...t.flat()];function _e(t,e={}){typeof t=="string"&&(t=et(t));let{indent:r=" ",newline:i=`
4
- `,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return l(t);return t.filter(a=>s||!n(a)).map(a=>l(a)).join(i);function n(a){return typeof a=="string"&&a[1]===";"}function l(a,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let y=1;for(typeof a[y]=="string"&&a[y][0]==="$"&&(f+=" "+a[y++]),Array.isArray(a[y])&&(a[y][0]==="result"||a[y][0]==="type")&&(f+=" "+l(a[y++],o));Array.isArray(a[y])&&/^catch/.test(a[y][0]);)f+=" "+l(a[y++],o).trim();for(;y<a.length;y++)f+=Array.isArray(a[y])?i+r.repeat(o+1)+l(a[y],o+1):" "+a[y];return`(${f+i+r.repeat(o)})`}let u=!!i&&a.length<4&&!a.some(y=>typeof y=="string"&&y[0]===";"&&y[1]===";"),p=r.repeat(o+1);for(let y=1;y<a.length;y++){let g=a[y].valueOf();if(typeof g=="string"&&g[1]===";"){if(!s)continue;if(g[0]===";")if(i)f+=i+p+g.trimEnd(),c=!0;else{let m=f[f.length-1];m&&m!==" "&&m!=="("&&(f+=" "),f+=g.trimEnd()+`
1
+ var De=Object.defineProperty;var Re=(t,e)=>{for(var r in e)De(t,r,{get:e[r],enumerable:!0})};var bt={};Re(bt,{f32:()=>ct,f64:()=>ft,i16:()=>He,i32:()=>P,i64:()=>nt,i8:()=>Ge,uleb:()=>h,uleb5:()=>je,v128:()=>Dt});var B=(t,e=B.loc)=>{if(e!=null&&B.src){let r=1,i=1;for(let s=0;s<e&&s<B.src.length;s++)B.src[s]===`
2
+ `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)},se=/^_|_$|[^\da-f]_|_[^\da-f]/i,ne=/^[+-]?(?:0x[\da-f]+|\d+)$/i,We=new TextEncoder,Pe=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),ie={n:10,r:13,t:9,'"':34,"'":39,"\\":92},At=t=>{let e=[],r=1,i,s,n="",l=()=>(n&&e.push(...We.encode(n)),n="");for(;r<t.length-1;)s=t[r++],i=null,s==="\\"&&(t[r]==="u"?(r++,r++,s=String.fromCodePoint(parseInt(t.slice(r,r=t.indexOf("}",r)),16)),r++):ie[t[r]]?i=ie[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(l(),e.push(i)):n+=s;return l(),e.valueOf=()=>t,e},le=t=>Pe.decode(new Uint8Array(At(t))),G=t=>Array.isArray(t)?t.map(G):t,S=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)S(t[s],e,t,s)},U=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++)U(t[n],e,t,n);let s=e(t,r,i);return s!==void 0&&r&&(r[i]=s),s!==void 0?s:t};var h=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):P.parse(t)),typeof t=="bigint"){for(;;){let i=Number(t&0x7Fn);if(t>>=7n,t===0n){e.push(i);break}e.push(i|128)}return e}let r=t&127;return t>>>=7,t===0?(e.push(r),e):(e.push(r|128),h(t,e))};function je(t){let e=[];for(let r=0;r<5;r++){let i=t&127;t>>>=7,r<4&&(i|=128),e.push(i)}return e}function P(t,e=[]){for(typeof t=="string"&&(t=P.parse(t));;){let r=Number(t&127);if(t>>=7,t===0&&!(r&64)||t===-1&&r&64){e.push(r);break}e.push(r|128)}return e}var oe=t=>!se.test(t)&&ne.test(t=t.replaceAll("_",""))?t:B(`Bad int ${t}`),Ge=P,He=P;P.parse=t=>(t=parseInt(oe(t)),(t<-2147483648||t>4294967295)&&B("i32 constant out of range"),t);function nt(t,e=[]){for(typeof t=="string"?t=nt.parse(t):typeof t=="number"&&(t=BigInt(t)),typeof t=="bigint"&&t>0x7fffffffffffffffn&&(t=t-0x10000000000000000n);;){let r=Number(t&0x7Fn);if(t>>=7n,t===0n&&!(r&64)||t===-1n&&r&64){e.push(r);break}e.push(r|128)}return e}var _t=new ArrayBuffer(8),X=new Uint8Array(_t),Ve=new Int32Array(_t),Ye=new Float32Array(_t),Xe=new Float64Array(_t),Lt=new BigInt64Array(_t);nt.parse=t=>{t=oe(t);let e=t[0]==="-",r=e||t[0]==="+"?t.slice(1):t,i;if(r[0]==="0"&&(r[1]==="x"||r[1]==="X")){let n=r.slice(2).replace(/^0+/,"")||"0";i=e?"8000000000000000":"ffffffffffffffff",(n.length>16||n.length===16&&n.toLowerCase()>i)&&B("i64 constant out of range")}else{let n=r.replace(/^0+/,"")||"0";i=e?"9223372036854775808":"18446744073709551615",(n.length>i.length||n.length===i.length&&n>i)&&B("i64 constant out of range")}let s=BigInt(r);return e&&(s=0n-s),Lt[0]=s,Lt[0]};var Ze=2147483648,Ke=2139095040,ae=4194304;function ct(t,e,r){if(typeof t=="string"&&(r=t.indexOf("nan"))>=0){if(t[r+3]===":"){let i=t.slice(r+4);e=i==="canonical"||i==="arithmetic"?ae:P.parse(i)}else e=ae;e=(e|Ke)>>>0,t[0]==="-"&&(e=(e|Ze)>>>0),Ve[0]=e|0}else e=typeof t=="string"?ct.parse(t):t,Ye[0]=e;return[X[0],X[1],X[2],X[3]]}var Qe=0x8000000000000000n,Je=0x7ff0000000000000n,fe=0x8000000000000n;function ft(t,e,r){if(typeof t=="string"&&(r=t.indexOf("nan"))>=0){if(t[r+3]===":"){let i=t.slice(r+4);e=i==="canonical"||i==="arithmetic"?fe:nt.parse(i)}else e=fe;e|=Je,t[0]==="-"&&(e|=Qe),Lt[0]=e}else e=typeof t=="string"?ft.parse(t):t,Xe[0]=e;return[X[0],X[1],X[2],X[3],X[4],X[5],X[6],X[7]]}ft.parse=(t,e=Number.MAX_VALUE)=>{t=t.replaceAll("_","");let r=1;if(t[0]==="-"?(r=-1,t=t.slice(1)):t[0]==="+"&&(t=t.slice(1)),t[1]==="x"){let[i,s="0"]=t.split(/p/i),[n,l=""]=i.split("."),a=l.length??0,o=0;for(let u=n.length-1;u>=2;u--){let p=parseInt(n[u],16);o+=p*16**(n.length-1-u)}let f=l?parseInt("0x"+l)/16**a:0;s=parseInt(s,10);let c=r*(o+f)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};ct.parse=t=>ft.parse(t,34028234663852886e22);var Dt=t=>{let e=BigInt(typeof t=="string"?t.replaceAll("_",""):t),r=new Uint8Array(16);for(let i=0;i<16;i++)r[i]=Number(e&0xffn),e>>=8n;return[...r]};var ht=["unreachable","nop","block block","loop block","if block","else null","then null",,"throw tagidx",,"throw_ref","end end","br labelidx","br_if labelidx","br_table br_table","return","call funcidx","call_indirect call_indirect","return_call funcidx","return_call_indirect call_indirect","call_ref typeidx","return_call_ref typeidx",,,,,"drop","select select","",,,"try_table try_table","local.get localidx","local.set localidx","local.tee localidx","global.get globalidx","global.set globalidx","table.get tableidx","table.set tableidx",,"i32.load memarg","i64.load memarg","f32.load memarg","f64.load memarg","i32.load8_s memarg","i32.load8_u memarg","i32.load16_s memarg","i32.load16_u memarg","i64.load8_s memarg","i64.load8_u memarg","i64.load16_s memarg","i64.load16_u memarg","i64.load32_s memarg","i64.load32_u memarg","i32.store memarg","i64.store memarg","f32.store memarg","f64.store memarg","i32.store8 memarg","i32.store16 memarg","i64.store8 memarg","i64.store16 memarg","i64.store32 memarg","memory.size opt_memory","memory.grow opt_memory","i32.const i32","i64.const i64","f32.const f32","f64.const f64","i32.eqz","i32.eq","i32.ne","i32.lt_s","i32.lt_u","i32.gt_s","i32.gt_u","i32.le_s","i32.le_u","i32.ge_s","i32.ge_u","i64.eqz","i64.eq","i64.ne","i64.lt_s","i64.lt_u","i64.gt_s","i64.gt_u","i64.le_s","i64.le_u","i64.ge_s","i64.ge_u","f32.eq","f32.ne","f32.lt","f32.gt","f32.le","f32.ge","f64.eq","f64.ne","f64.lt","f64.gt","f64.le","f64.ge","i32.clz","i32.ctz","i32.popcnt","i32.add","i32.sub","i32.mul","i32.div_s","i32.div_u","i32.rem_s","i32.rem_u","i32.and","i32.or","i32.xor","i32.shl","i32.shr_s","i32.shr_u","i32.rotl","i32.rotr","i64.clz","i64.ctz","i64.popcnt","i64.add","i64.sub","i64.mul","i64.div_s","i64.div_u","i64.rem_s","i64.rem_u","i64.and","i64.or","i64.xor","i64.shl","i64.shr_s","i64.shr_u","i64.rotl","i64.rotr","f32.abs","f32.neg","f32.ceil","f32.floor","f32.trunc","f32.nearest","f32.sqrt","f32.add","f32.sub","f32.mul","f32.div","f32.min","f32.max","f32.copysign","f64.abs","f64.neg","f64.ceil","f64.floor","f64.trunc","f64.nearest","f64.sqrt","f64.add","f64.sub","f64.mul","f64.div","f64.min","f64.max","f64.copysign","i32.wrap_i64","i32.trunc_f32_s","i32.trunc_f32_u","i32.trunc_f64_s","i32.trunc_f64_u","i64.extend_i32_s","i64.extend_i32_u","i64.trunc_f32_s","i64.trunc_f32_u","i64.trunc_f64_s","i64.trunc_f64_u","f32.convert_i32_s","f32.convert_i32_u","f32.convert_i64_s","f32.convert_i64_u","f32.demote_f64","f64.convert_i32_s","f64.convert_i32_u","f64.convert_i64_s","f64.convert_i64_u","f64.promote_f32","i32.reinterpret_f32","i64.reinterpret_f64","f32.reinterpret_i32","f64.reinterpret_i64","i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s",,,,,,,,,,,,"ref.null ref_null","ref.is_null","ref.func funcidx","ref.eq","ref.as_non_null","br_on_null labelidx","br_on_non_null labelidx",,,,,,,,,,"cont.new typeidx","cont.bind cont_bind","suspend tagidx","resume resume","resume_throw resume_throw","resume_throw_ref resume_throw_ref","switch switch_cont",,,,,,,,,,,,,,,,,,,,,["struct.new typeidx","struct.new_default typeidx","struct.get typeidx_field","struct.get_s typeidx_field","struct.get_u typeidx_field","struct.set typeidx_field","array.new typeidx","array.new_default typeidx","array.new_fixed typeidx_multi","array.new_data typeidx_dataidx","array.new_elem typeidx_elemidx","array.get typeidx","array.get_s typeidx","array.get_u typeidx","array.set typeidx","array.len","array.fill typeidx","array.copy typeidx_typeidx","array.init_data typeidx_dataidx","array.init_elem typeidx_elemidx","ref.test reftype","ref.test_null reftype","ref.cast reftype","ref.cast_null reftype","br_on_cast reftype2","br_on_cast_fail reftype2","any.convert_extern","extern.convert_any","ref.i31","i31.get_s","i31.get_u",,"struct.new_desc typeidx","struct.new_default_desc typeidx","ref.get_desc typeidx","ref.cast_desc_eq reftype",,"br_on_cast_desc_eq reftype2","br_on_cast_desc_eq_fail reftype2",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"string.new_utf8 memoryidx?","string.new_wtf16 memoryidx?","string.const stringidx","string.measure_utf8","string.measure_wtf8","string.measure_wtf16","string.encode_utf8 memoryidx?","string.encode_wtf16 memoryidx?","string.concat","string.eq","string.is_usv_sequence","string.new_lossy_utf8 memoryidx?","string.new_wtf8 memoryidx?","string.encode_lossy_utf8 memoryidx?","string.encode_wtf8 memoryidx?",,"string.as_wtf8","stringview_wtf8.advance","stringview_wtf8.encode_utf8 memoryidx?","stringview_wtf8.slice","stringview_wtf8.encode_lossy_utf8 memoryidx?","stringview_wtf8.encode_wtf8 memoryidx?",,,"string.as_wtf16","stringview_wtf16.length","stringview_wtf16.get_codeunit","stringview_wtf16.encode memoryidx?","stringview_wtf16.slice",,,,"string.as_iter","stringview_iter.next","stringview_iter.advance","stringview_iter.rewind","stringview_iter.slice",,,,,,,,,,,,"string.new_utf8_array","string.new_wtf16_array","string.encode_utf8_array","string.encode_wtf16_array","string.new_lossy_utf8_array","string.new_wtf8_array","string.encode_lossy_utf8_array","string.encode_wtf8_array"],["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u","memory.init dataidx_memoryidx","data.drop dataidx","memory.copy memoryidx_memoryidx","memory.fill memoryidx?","table.init reversed","elem.drop elemidx","table.copy tableidx_tableidx","table.grow tableidx","table.size tableidx","table.fill tableidx",,"i64.add128","i64.sub128","i64.mul_wide_s","i64.mul_wide_u",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,"f32.sqrt_ceil","f32.add_ceil","f32.sub_ceil","f32.mul_ceil","f32.div_ceil","f64.sqrt_ceil","f64.add_ceil","f64.sub_ceil","f64.mul_ceil","f64.div_ceil","f32.convert_ceil_i32_s","f32.convert_ceil_i32_u","f32.convert_ceil_i64_s","f32.convert_ceil_i64_u","f32.demote_ceil_f64","f64.convert_ceil_i32_s","f64.convert_ceil_i32_u","f64.convert_ceil_i64_s","f64.convert_ceil_i64_u","f64.promote_ceil_f32","f32.sqrt_floor","f32.add_floor","f32.sub_floor","f32.mul_floor","f32.div_floor","f64.sqrt_floor","f64.add_floor","f64.sub_floor","f64.mul_floor","f64.div_floor","f32.convert_floor_i32_s","f32.convert_floor_i32_u","f32.convert_floor_i64_s","f32.convert_floor_i64_u","f32.demote_floor_f64","f64.convert_floor_i32_s","f64.convert_floor_i32_u","f64.convert_floor_i64_s","f64.convert_floor_i64_u","f64.promote_floor_f32","f32.sqrt_trunc","f32.add_trunc","f32.sub_trunc","f32.mul_trunc","f32.div_trunc","f64.sqrt_trunc","f64.add_trunc","f64.sub_trunc","f64.mul_trunc","f64.div_trunc","f32.convert_trunc_i32_s","f32.convert_trunc_i32_u","f32.convert_trunc_i64_s","f32.convert_trunc_i64_u","f32.demote_trunc_f64","f64.convert_trunc_i32_s","f64.convert_trunc_i32_u","f64.convert_trunc_i64_s","f64.convert_trunc_i64_u","f64.promote_trunc_f32"],["v128.load memarg","v128.load8x8_s memarg","v128.load8x8_u memarg","v128.load16x4_s memarg","v128.load16x4_u memarg","v128.load32x2_s memarg","v128.load32x2_u memarg","v128.load8_splat memarg","v128.load16_splat memarg","v128.load32_splat memarg","v128.load64_splat memarg","v128.store memarg","v128.const v128const","i8x16.shuffle shuffle","i8x16.swizzle","i8x16.splat","i16x8.splat","i32x4.splat","i64x2.splat","f32x4.splat","f64x2.splat","i8x16.extract_lane_s laneidx","i8x16.extract_lane_u laneidx","i8x16.replace_lane laneidx","i16x8.extract_lane_s laneidx","i16x8.extract_lane_u laneidx","i16x8.replace_lane laneidx","i32x4.extract_lane laneidx","i32x4.replace_lane laneidx","i64x2.extract_lane laneidx","i64x2.replace_lane laneidx","f32x4.extract_lane laneidx","f32x4.replace_lane laneidx","f64x2.extract_lane laneidx","f64x2.replace_lane laneidx","i8x16.eq","i8x16.ne","i8x16.lt_s","i8x16.lt_u","i8x16.gt_s","i8x16.gt_u","i8x16.le_s","i8x16.le_u","i8x16.ge_s","i8x16.ge_u","i16x8.eq","i16x8.ne","i16x8.lt_s","i16x8.lt_u","i16x8.gt_s","i16x8.gt_u","i16x8.le_s","i16x8.le_u","i16x8.ge_s","i16x8.ge_u","i32x4.eq","i32x4.ne","i32x4.lt_s","i32x4.lt_u","i32x4.gt_s","i32x4.gt_u","i32x4.le_s","i32x4.le_u","i32x4.ge_s","i32x4.ge_u","f32x4.eq","f32x4.ne","f32x4.lt","f32x4.gt","f32x4.le","f32x4.ge","f64x2.eq","f64x2.ne","f64x2.lt","f64x2.gt","f64x2.le","f64x2.ge","v128.not","v128.and","v128.andnot","v128.or","v128.xor","v128.bitselect","v128.any_true","v128.load8_lane memlane","v128.load16_lane memlane","v128.load32_lane memlane","v128.load64_lane memlane","v128.store8_lane memlane","v128.store16_lane memlane","v128.store32_lane memlane","v128.store64_lane memlane","v128.load32_zero memarg","v128.load64_zero memarg","f32x4.demote_f64x2_zero","f64x2.promote_low_f32x4","i8x16.abs","i8x16.neg","i8x16.popcnt","i8x16.all_true","i8x16.bitmask","i8x16.narrow_i16x8_s","i8x16.narrow_i16x8_u","f32x4.ceil","f32x4.floor","f32x4.trunc","f32x4.nearest","i8x16.shl","i8x16.shr_s","i8x16.shr_u","i8x16.add","i8x16.add_sat_s","i8x16.add_sat_u","i8x16.sub","i8x16.sub_sat_s","i8x16.sub_sat_u","f64x2.ceil","f64x2.floor","i8x16.min_s","i8x16.min_u","i8x16.max_s","i8x16.max_u","f64x2.trunc","i8x16.avgr_u","i16x8.extadd_pairwise_i8x16_s","i16x8.extadd_pairwise_i8x16_u","i32x4.extadd_pairwise_i16x8_s","i32x4.extadd_pairwise_i16x8_u","i16x8.abs","i16x8.neg","i16x8.q15mulr_sat_s","i16x8.all_true","i16x8.bitmask","i16x8.narrow_i32x4_s","i16x8.narrow_i32x4_u","i16x8.extend_low_i8x16_s","i16x8.extend_high_i8x16_s","i16x8.extend_low_i8x16_u","i16x8.extend_high_i8x16_u","i16x8.shl","i16x8.shr_s","i16x8.shr_u","i16x8.add","i16x8.add_sat_s","i16x8.add_sat_u","i16x8.sub","i16x8.sub_sat_s","i16x8.sub_sat_u","f64x2.nearest","i16x8.mul","i16x8.min_s","i16x8.min_u","i16x8.max_s","i16x8.max_u",,"i16x8.avgr_u","i16x8.extmul_low_i8x16_s","i16x8.extmul_high_i8x16_s","i16x8.extmul_low_i8x16_u","i16x8.extmul_high_i8x16_u","i32x4.abs","i32x4.neg",,"i32x4.all_true","i32x4.bitmask",,,"i32x4.extend_low_i16x8_s","i32x4.extend_high_i16x8_s","i32x4.extend_low_i16x8_u","i32x4.extend_high_i16x8_u","i32x4.shl","i32x4.shr_s","i32x4.shr_u","i32x4.add",,,"i32x4.sub",,,,"i32x4.mul","i32x4.min_s","i32x4.min_u","i32x4.max_s","i32x4.max_u","i32x4.dot_i16x8_s",,"i32x4.extmul_low_i16x8_s","i32x4.extmul_high_i16x8_s","i32x4.extmul_low_i16x8_u","i32x4.extmul_high_i16x8_u","i64x2.abs","i64x2.neg",,"i64x2.all_true","i64x2.bitmask",,,"i64x2.extend_low_i32x4_s","i64x2.extend_high_i32x4_s","i64x2.extend_low_i32x4_u","i64x2.extend_high_i32x4_u","i64x2.shl","i64x2.shr_s","i64x2.shr_u","i64x2.add",,,"i64x2.sub",,,,"i64x2.mul","i64x2.eq","i64x2.ne","i64x2.lt_s","i64x2.gt_s","i64x2.le_s","i64x2.ge_s","i64x2.extmul_low_i32x4_s","i64x2.extmul_high_i32x4_s","i64x2.extmul_low_i32x4_u","i64x2.extmul_high_i32x4_u","f32x4.abs","f32x4.neg",,"f32x4.sqrt","f32x4.add","f32x4.sub","f32x4.mul","f32x4.div","f32x4.min","f32x4.max","f32x4.pmin","f32x4.pmax","f64x2.abs","f64x2.neg",,"f64x2.sqrt","f64x2.add","f64x2.sub","f64x2.mul","f64x2.div","f64x2.min","f64x2.max","f64x2.pmin","f64x2.pmax","i32x4.trunc_sat_f32x4_s","i32x4.trunc_sat_f32x4_u","f32x4.convert_i32x4_s","f32x4.convert_i32x4_u","i32x4.trunc_sat_f64x2_s_zero","i32x4.trunc_sat_f64x2_u_zero","f64x2.convert_low_i32x4_s","f64x2.convert_low_i32x4_u","i8x16.relaxed_swizzle","i32x4.relaxed_trunc_f32x4_s","i32x4.relaxed_trunc_f32x4_u","i32x4.relaxed_trunc_f64x2_s_zero","i32x4.relaxed_trunc_f64x2_u_zero","f32x4.relaxed_madd","f32x4.relaxed_nmadd","f64x2.relaxed_madd","f64x2.relaxed_nmadd","i8x16.relaxed_laneselect","i16x8.relaxed_laneselect","i32x4.relaxed_laneselect","i64x2.relaxed_laneselect","f32x4.relaxed_min","f32x4.relaxed_max","f64x2.relaxed_min","f64x2.relaxed_max","i16x8.relaxed_q15mulr_s","i16x8.relaxed_dot_i8x16_i7x16_s","i32x4.relaxed_dot_i8x16_i7x16_add_s"],["memory.atomic.notify memarg","memory.atomic.wait32 memarg","memory.atomic.wait64 memarg","atomic.fence opt_memory",,,,,,,,,,,,,"i32.atomic.load memarg","i64.atomic.load memarg","i32.atomic.load8_u memarg","i32.atomic.load16_u memarg","i64.atomic.load8_u memarg","i64.atomic.load16_u memarg","i64.atomic.load32_u memarg","i32.atomic.store memarg","i64.atomic.store memarg","i32.atomic.store8 memarg","i32.atomic.store16 memarg","i64.atomic.store8 memarg","i64.atomic.store16 memarg","i64.atomic.store32 memarg","i32.atomic.rmw.add memarg","i64.atomic.rmw.add memarg","i32.atomic.rmw8.add_u memarg","i32.atomic.rmw16.add_u memarg","i64.atomic.rmw8.add_u memarg","i64.atomic.rmw16.add_u memarg","i64.atomic.rmw32.add_u memarg","i32.atomic.rmw.sub memarg","i64.atomic.rmw.sub memarg","i32.atomic.rmw8.sub_u memarg","i32.atomic.rmw16.sub_u memarg","i64.atomic.rmw8.sub_u memarg","i64.atomic.rmw16.sub_u memarg","i64.atomic.rmw32.sub_u memarg","i32.atomic.rmw.and memarg","i64.atomic.rmw.and memarg","i32.atomic.rmw8.and_u memarg","i32.atomic.rmw16.and_u memarg","i64.atomic.rmw8.and_u memarg","i64.atomic.rmw16.and_u memarg","i64.atomic.rmw32.and_u memarg","i32.atomic.rmw.or memarg","i64.atomic.rmw.or memarg","i32.atomic.rmw8.or_u memarg","i32.atomic.rmw16.or_u memarg","i64.atomic.rmw8.or_u memarg","i64.atomic.rmw16.or_u memarg","i64.atomic.rmw32.or_u memarg","i32.atomic.rmw.xor memarg","i64.atomic.rmw.xor memarg","i32.atomic.rmw8.xor_u memarg","i32.atomic.rmw16.xor_u memarg","i64.atomic.rmw8.xor_u memarg","i64.atomic.rmw16.xor_u memarg","i64.atomic.rmw32.xor_u memarg","i32.atomic.rmw.xchg memarg","i64.atomic.rmw.xchg memarg","i32.atomic.rmw8.xchg_u memarg","i32.atomic.rmw16.xchg_u memarg","i64.atomic.rmw8.xchg_u memarg","i64.atomic.rmw16.xchg_u memarg","i64.atomic.rmw32.xchg_u memarg","i32.atomic.rmw.cmpxchg memarg","i64.atomic.rmw.cmpxchg memarg","i32.atomic.rmw8.cmpxchg_u memarg","i32.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw8.cmpxchg_u memarg","i64.atomic.rmw16.cmpxchg_u memarg","i64.atomic.rmw32.cmpxchg_u memarg"]],xt=t=>{if(typeof t!="string")return null;let e=t.indexOf(".");if(e<0)return null;let r=t.slice(0,e),i=r==="i32"||r==="i64"||r==="f32"||r==="f64";return i&&/^(eqz?|ne|[lg][te])(_[su])?$/.test(t.slice(e+1))?"i32":i||r==="v128"?r:t==="memory.size"||t==="memory.grow"?"i32":null},R={custom:0,type:1,import:2,func:3,table:4,memory:5,tag:13,strings:14,global:6,export:7,start:8,elem:9,datacount:12,code:10,data:11},W={i8:120,i16:119,i32:127,i64:126,f32:125,f64:124,void:64,v128:123,exn:105,noexn:116,nofunc:115,noextern:114,none:113,func:112,extern:111,any:110,eq:109,i31:108,struct:107,array:106,data:107,cont:104,nocont:117,string:103,stringview_wtf8:102,stringview_wtf16:96,stringview_iter:97,nullfuncref:115,nullexternref:114,nullexnref:116,nullref:113,funcref:112,externref:111,exnref:105,anyref:110,eqref:109,i31ref:108,structref:107,arrayref:106,contref:104,nocontref:117,stringref:103,ref:100,refnull:99,sub:80,subfinal:79,rec:78},lt={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},Rt={func:0,table:1,memory:2,global:3,tag:4};var et=t=>{let e=0,r=[],i="",s=0,n=0,l=()=>i&&(r.push(i),i=""),a=o=>{r.loc=o;for(let f,c,u;e<t.length;)if(f=t.charCodeAt(e),s===34)i+=t[e++],f===92?i+=t[e++]:f===34&&(l(),s=0);else if(s>59)f===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(l(),s=0)):i+=t[e++];else if(s<0)f===10||f===13?(i+=t[e++],l(),s=0):s===-2&&f===41?(l(),s=0):i+=t[e++];else if(f===34)i!=="$"&&l(),s=34,i+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)l(),s=60,i=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)l(),s=t.indexOf(`
3
+ `,e)<0?-2:-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)l(),u=e,e+=2,i="@",n++,(c=r).push(r=[]),a(u),r=c;else if(f===40)l(),u=e++,n++,(c=r).push(r=[]),a(u),r=c;else{if(f===41)return l(),e++,n--;f<=32?(l(),e++):i+=t[e++]}s<0&&l(),l()};return a(0),s===34&&B("Unclosed quote",e),s>59&&B("Unclosed block comment",e),n>0&&B("Unclosed parenthesis",e),e<t.length&&B("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var ye=t=>typeof t=="string"&&(t[0]===";"||t[1]===";")||Array.isArray(t)&&t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code."),pe=(t,e)=>typeof t=="string"?t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+le(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?At(t):t:Array.isArray(t)?(e=t.filter(r=>!ye(r)).map(pe),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):t;function yt(t){typeof t=="string"?(B.src=t,t=et(t)||[]):B.src="",B.loc=0,t=ye(t)?[]:pe(t)??[];let e=0;if(t[0]==="module"?(e++,H(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return yt(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,p)=>{if(p<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,y,...g]=u;if(!g.some(_=>Array.isArray(_)&&_[0]==="item"))return[u];if(Array.isArray(g.at(-1))&&g.at(-1)[0]!=="item"){let _=g.at(-1);return g.slice(0,-1).filter(b=>b[0]==="item").map(([,b])=>["import",y,b,_])}return g.filter(_=>_[0]==="item").map(([,_,b])=>["import",y,_,b])});let r=[];for(let u in R)(r[R[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let g=B.loc,m=B.src,_;for(;(g=m.indexOf(u,g))>=0;){if(_=m.charCodeAt(g-1),g>0&&(_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95||_===36)){g++;continue}if(_=m.charCodeAt(g+u.length),_>47&&_<58||_>64&&_<91||_>96&&_<123||_===95){g++;continue}break}g>=0&&(B.loc=g),B(`Unexpected token ${u}`)}let[p,...y]=u;if(B.loc=u.loc,p==="@custom")r.custom.push(y);else if(p==="rec")for(let g=0;g<y.length;g++){let[,...m]=y[g];Wt(m,r.type);let _=[];for(;m[0]?.[0]==="descriptor"||m[0]?.[0]==="describes";)_.push(m.shift());(m=ce(m,r)).push(g?!0:[r.type.length,y.length]),_.length&&(m.desc=m.desc?[..._,...m.desc]:_),r.type.push(m)}else if(p==="type"){Wt(y,r.type);let g=[];for(;y[0]?.[0]==="descriptor"||y[0]?.[0]==="describes";)g.push(y.shift());let m=ce(y,r);g.length&&(m.desc=m.desc?[...g,...m.desc]:g),r.type.push(m)}else if(p==="start"||p==="export")r[p].push(y);else return!0}).forEach(u=>{let[p,...y]=u;B.loc=u.loc;let g;p==="import"&&([p,...y]=(g=y).pop());let m=r[p];for(m||B(`Unknown section ${p}`),Wt(y,m);y[0]?.[0]==="export";)r.export.push([y.shift()[1],[p,m?.length]]);if(y[0]?.[0]==="import"&&([,...g]=y.shift()),p==="table"){let _=y[0]==="i64",b=_?1:0;if(y[b+1]?.[0]==="elem"){let[v,[,...A]]=[y[b],y[b+1]];y=_?["i64",A.length,A.length,v]:[A.length,A.length,v],r.elem.push([["table",m.length],["offset",[_?"i64.const":"i32.const",_?0n:0]],v,...A])}}else if(p==="memory"){let _=y[0]==="i64",b=_?1:0;if(y[b]?.[0]==="data"){let v=y.find(I=>Array.isArray(I)&&I[0]==="pagesize")?.[1]??65536,[,...A]=y.splice(b,1)[0],z=""+Math.ceil(A.reduce((I,M)=>I+M.length,0)/v);r.data.push([["memory",m.length],[_?"i64.const":"i32.const",_?0n:0],...A]),y=_?["i64",z,z]:[z,z]}}else if(p==="func"){let[_,b,v]=Nt(y,r);_??=Mt(b,v,r),!g&&r.code.push([[_,b,v],...st(y,r)]),y=[["type",_]]}else if(p==="tag"){let[_,b]=Nt(y,r);_??=Mt(b,[],r),y=[["type",_]]}g&&(r.import.push([...g,[p,...y]]),y=null),m.push(y)});let i=(u,p=!0)=>{let y=r[u].filter(Boolean).map(g=>me[u](g,r)).filter(Boolean);return u===R.custom?y.flatMap(g=>[u,...L(g)]):y.length?[u,...L(p?L(y):y.flat())]:[]},s=()=>{let u=[];for(let p in r.metadata){let y=L(At(`"metadata.code.${p}"`)),g=L(r.metadata[p].map(([m,_])=>[...h(m),...L(_.map(([b,v])=>[...h(b),...L(v)]))]));u.push(0,...L([...y,...g]))}return u},n=i(R.global),l=i(R.elem),a=i(R.code),o=s(),f=i(R.data),c=r.strings.length?[R.strings,...L([0,...L(r.strings.map(u=>L(u)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(R.custom),...i(R.type),...i(R.import),...i(R.func),...i(R.table),...i(R.memory),...i(R.tag),...c,...n,...i(R.export),...i(R.start,!1),...l,...i(R.datacount,!1),...a,...o,...f])}var Z=t=>t?.[0]==="$"||!isNaN(t),H=t=>t?.[0]==="$",Pt=t=>t?.[0]==="a"||t?.[0]==="o";function st(t,e){let r=[];for(t=[...t];t.length;){let i=t.shift();if(typeof i=="string")if(r.push(i),i==="block"||i==="if"||i==="loop")H(t[0])&&r.push(t.shift()),r.push(wt(t,e));else if(i==="else"||i==="end")H(t[0])&&t.shift();else if(i==="select")r.push(Bt(t)[1]);else if(i.endsWith("call_indirect")){let s=Z(t[0])?t.shift():0,[n,l,a]=Nt(t,e);r.push(s,["type",n??Mt(l,a,e)])}else i==="table.init"?r.push(Z(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(Z(t[0])?t.shift():0,Z(t[0])?t.shift():0):i.startsWith("table.")?r.push(Z(t[0])?t.shift():0):i==="memory.init"?(r.push(...Z(t[1])?[t.shift(),t.shift()].reverse():[t.shift(),0]),e.datacount&&(e.datacount[0]=!0)):i==="data.drop"||i==="array.new_data"||i==="array.init_data"?(i==="data.drop"&&r.push(t.shift()),e.datacount&&(e.datacount[0]=!0)):(i.startsWith("memory.")||i.endsWith("load")||i.endsWith("store"))&&Z(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(B.loc=i.loc),s?.startsWith?.("@metadata.code.")){let l=s.slice(15);r.push(["@metadata",l,i[1]]);continue}if(typeof s!="string"||!Array.isArray(ht[s])){r.push(i);continue}let n=i.slice(1);if(s==="block"||s==="loop")r.push(s),H(n[0])&&r.push(n.shift()),r.push(wt(n,e),...st(n,e),"end");else if(s==="if"){let l=[],a=[];n.at(-1)?.[0]==="else"&&(a=st(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=st(n.pop().slice(1),e));let o=[s];H(n[0])&&o.push(n.shift()),o.push(wt(n,e)),r.push(...st(n,e),...o,...l),a.length&&r.push("else",...a),r.push("end")}else if(s==="try_table"){for(r.push(s),H(n[0])&&r.push(n.shift()),r.push(wt(n,e));n[0]?.[0]==="catch"||n[0]?.[0]==="catch_ref"||n[0]?.[0]==="catch_all"||n[0]?.[0]==="catch_all_ref";)r.push(n.shift());r.push(...st(n,e),"end")}else if(s==="ref.test"||s==="ref.cast"){let l=n[0];(!Array.isArray(l)||l[1]==="null"||l[0]!=="ref")&&(s+="_null"),r.push(...st(n.slice(1),e),s,l),t.unshift(...r.splice(r.length-2))}else{let l=[];for(;n.length&&(!Array.isArray(n[0])||n[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(n[0][0]));)l.push(n.shift());r.push(...st(n,e),s,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(i)}return r}var Mt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),jt=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=H(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},Bt=t=>{let e=jt(t,"param"),r=jt(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},Nt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...Bt(t)];let[,r]=t.shift(),[i,s]=Bt(t),n=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!n)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&n[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...n[1]]},wt=(t,e)=>{let[r,i,s]=Nt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??Mt(i,s,e)]},Wt=(t,e)=>{let r=H(t[0])&&t.shift();return r&&(r in e?B(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},ce=([t],e)=>{let r="subfinal",i=[],s,n=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(n.push(a),!1):!0)),[s,...t]=t,s==="func"?(t=Bt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=jt(t,"field"):s==="array"&&([t]=t);let l=[s,t,r,i];return n.length&&(l.desc=n),l},me=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...L(t),...i.flat()]},(t,e)=>{let[r,i,s,n,l]=t;if(l===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...h($(c,e.type))]),o=(f,c)=>f==="func"?[lt.func,...L(c[0].map(u=>Y(u,e))),...L(c[1].map(u=>Y(u,e)))]:f==="array"?[lt.array,...vt(c,e)]:f==="struct"?[lt.struct,...L(c.map(u=>vt(u,e)))]:f==="cont"?[lt.cont,...h($(c[0]??c,e.type))]:[lt[f]];if(l){let[f,c]=l,u=Array.from({length:c},(p,y)=>{let g=e.type[f+y],m=g.slice(0,4);return g.desc&&(m.desc=g.desc),me[R.type](m,e)});return[lt.rec,...L(u)]}else if(s==="sub"||n?.length)return[lt[s],...L(n.map(f=>$(f,e.type))),...a,...o(r,i)];return[...a,...o(r,i)]},([t,e,[r,...i]],s)=>{let n,l=Rt[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(l=32);let[[,o]]=i;n=h($(o,s.type))}else if(r==="tag"){let[[,a]]=i;n=[0,...h($(a,s.type))]}else r==="memory"?n=$t(i):r==="global"?n=vt(i[0],s):r==="table"?n=[...Y(i.pop(),s),...$t(i)]:B(`Unknown kind ${r}`);return[...L(t),...L(e),l,...n]},([[,t]],e)=>h($(t,e.type)),(t,e)=>{let r=$t(t),i=Y(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...ut(s,e)]:[...i,...r]},(t,e)=>$t(t),([t,e],r)=>[...vt(t,r),...ut(e,r)],([t,[e,r]],i)=>[...L(t),Rt[e],...h($(r,i[e]))],([t],e)=>h($(t,e.func)),(t,e)=>{let r=0,i=0,s=0,n=0,l,a,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=$(l,e.table)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&t[1][0]!=="item"&&!t[1][0]?.startsWith("ref"))&&(l=$(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(a=t.shift(),a[0]==="offset"&&([,a]=a),a=ut(a,e)):i||(r=1),W[t[0]]||t[0]?.[0]==="ref"?o=Y(t.shift(),e):t[0]==="func"?o=[W[t.shift()]]:o=[W.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==W.funcref&&(n=1,s=1);let f=s<<2|(r||i?i:!!l||n)<<1|(r||i);return[f,...f===0?a:f===1?[0]:f===2?[...h(l||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...h(l||0),...a,...o]:o,...L(t.map(s?c=>ut(typeof c=="string"?["ref.func",c]:c,e):c=>h($(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[$(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(H(o[0])){let f=o.shift();f in e.local?B(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let n=_e(t,e),l=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([l,e.meta[o]]);let a=e.local.slice(i.length).reduce((o,f)=>(f==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,f]),o),[]);return e.local=e.block=e.meta=null,L([...L(a.map(([o,f])=>[...h(o),...Y(f,e)])),...n])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=$(i,e.memory)):(typeof t[0]=="string"||typeof t[0]=="number")&&(t[1]?.[0]==="offset"||Array.isArray(t[1])&&typeof t[1][0]=="string")&&(i=$(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??B("Bad offset",r)),[...i?[2,...h(i),...ut(r,e)]:r?[0,...ut(r,e)]:[1],...L(t.flatMap(s=>rr(s)??[...s]))]},(t,e)=>h(e.data.length),([[,t]],e)=>[0,...h($(t,e.type))]],Y=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[W.refnull,98,...h($(t[2][1],e.type))]:W[t[2]]?[W[t[2]]]:[W.refnull,...h($(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[W.ref,98,...h($(t[1][1],e.type))]:[W.ref,...h(W[t[t.length-1]]||$(t[t.length-1],e.type))]:[W[t]??B(`Unknown type ${t}`)],vt=(t,e,r=t[0]==="mut"?1:0)=>[...Y(r?t[1]:t,e),r],ge={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...h($(i,e.elem)),...h($(r,e.table))]},block:(t,e)=>{e.block.push(1),H(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?Y(r[1],e):h($(r[1],e.type)):[W.void]},try_table:(t,e)=>{H(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?Y(r[1],e):h($(r[1],e.type)):[W.void],s=[],n=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let l=t.shift(),a=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;a<=1?s.push(a,...h($(l[1],e.tag)),...h(at(l[2],e.block))):s.push(a,...h(at(l[1],e.block))),n++}return e.block.push(1),[...i,...h(n),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...h($(i,e.type)),...h($(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||H(t[0]));)r.push(...h(at(t.shift(),e.block))),i++;return[...h(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?L(r.map(i=>Y(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...h($(r[1],e.type))]:W[r]?[W[r]]:h($(r,e.type))},memarg:(t,e,r)=>ue(t,r,Z(t[0])&&!Pt(t[0])?$(t.shift(),e.memory):0),opt_memory:(t,e)=>h($(Z(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=Y(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=at(t.shift(),e.block),i=Y(t.shift(),e),s=Y(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(s[0]!==W.ref)<<1|i[0]!==W.ref,...h(r),...n(i),...n(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let l=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)l[a]=bt[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(bt[e](t.shift()),l*s);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(kt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&B("invalid lane length"),e},memlane:(t,e,r)=>{let i=H(t[0])||Z(t[0])&&(Pt(t[1])||Z(t[1]))?$(t.shift(),e.memory):0;return[...ue(t,r,i),...h(kt(t.shift()))]},"*":t=>h(t.shift()),labelidx:(t,e)=>h(at(t.shift(),e.block)),laneidx:t=>[kt(t.shift(),255)],funcidx:(t,e)=>h($(t.shift(),e.func)),typeidx:(t,e)=>h($(t.shift(),e.type)),tableidx:(t,e)=>h($(t.shift(),e.table)),memoryidx:(t,e)=>h($(t.shift(),e.memory)),globalidx:(t,e)=>h($(t.shift(),e.global)),localidx:(t,e)=>h($(t.shift(),e.local)),dataidx:(t,e)=>h($(t.shift(),e.data)),elemidx:(t,e)=>h($(t.shift(),e.elem)),tagidx:(t,e)=>h($(t.shift(),e.tag)),"memoryidx?":(t,e)=>h($(Z(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(n=>n.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),h(s)},i32:t=>P(t.shift()),i64:t=>nt(t.shift()),f32:t=>ct(t.shift()),f64:t=>ft(t.shift()),v128:t=>Dt(t.shift()),typeidx_field:(t,e)=>{let r=$(t.shift(),e.type);return[...h(r),...h($(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...h($(t.shift(),e.type)),...h(t.shift())],typeidx_dataidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...h($(t.shift(),e.data)),...h($(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...h($(t.shift(),e.memory)),...h($(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...h($(t.shift(),e.table)),...h($(t.shift(),e.table))],cont_bind:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.type))],switch_cont:(t,e)=>[...h($(t.shift(),e.type)),...h($(t.shift(),e.tag))],resume:(t,e)=>{let r=h($(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...h($(n,e.tag))):i.push(0,...h($(n,e.tag)),...h(at(l,e.block))),s++}return[...r,...h(s),...i]},resume_throw:(t,e)=>{let r=h($(t.shift(),e.type)),i=h($(t.shift(),e.tag)),s=[],n=0;for(;t[0]?.[0]==="on";){let[,l,a]=t.shift();a==="switch"?s.push(1,...h($(l,e.tag))):s.push(0,...h($(l,e.tag)),...h(at(a,e.block))),n++}return[...r,...i,...h(n),...s]},resume_throw_ref:(t,e)=>{let r=h($(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...h($(n,e.tag))):i.push(0,...h($(n,e.tag)),...h(at(l,e.block))),s++}return[...r,...h(s),...i]}},It={};(function t(e,r){for(let i=0,s,n,l;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([n,l]=s.split(" "),ht[n]=r?[r,...h(i)]:[i],l&&(It[n]=ge[l])))})(ht);var _e=(t,e)=>{let r=[],i=[];for(;t?.length;){let s=t.shift();if(s?.[0]==="@metadata"){i.push(s.slice(1));continue}Array.isArray(s)&&(s.loc!=null&&(B.loc=s.loc),B(`Unknown instruction ${s[0]}`));let[...n]=ht[s]||B(`Unknown instruction ${s}`);It[s]&&(s==="select"&&t[0]?.length?n[0]++:It[s]===ge.reftype&&!s.endsWith("_null")&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...It[s](t,e,s)));for(let[l,a]of i)(e.meta[l]??=[]).push([r.length,a]);r.push(...n)}return r.push(11),r},ut=(t,e)=>_e(st([t],e),e),$=(t,e,r)=>(r=H(t)?e[t]:+t,r in e?r:B(`Unknown ${e.name} ${t}`)),at=(t,e,r)=>(r=H(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?B(`Bad label ${t}`):r),tr=t=>{let e,r,i,s;for(;Pt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:B(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&B(`Bad offset ${r}`),(e<=0||e>4294967295)&&B(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&B(`Bad align ${e}`),[e,r]},ue=(t,e,r=0)=>{let[i,s]=tr(t),n=(i??er(e))|(r&&64);return r?[...h(n),...h(r),...h(s??0)]:[...h(n),...h(s??0)]},er=t=>{let e=t.indexOf(".",3)+1,r=t.slice(1,t[0]==="v"?4:3);if(t[e]==="a"&&(e=t.indexOf(".",e)+1),t[0]==="m")return t.includes("64")?3:2;if(t[e]==="r"){let n=t.slice(e,e+6).match(/\d+/);return Math.log2(n?n[0]/8:+r/8)}let i=t[e]==="l"?e+4:e+5,s=t.slice(i).match(/(\d+)(x|_|$)/);return Math.log2(s?s[2]==="x"?8:s[1]/8:+r/8)},rr=t=>{if(!Array.isArray(t))return null;let[e,...r]=t;if(e!=="i8"&&e!=="i16"&&e!=="i32"&&e!=="i64"&&e!=="f32"&&e!=="f64")return null;let i=[],s=new DataView(new ArrayBuffer(8));for(let n of r)e==="i8"?i.push(P.parse(n)&511&255):e==="i16"?(s.setInt16(0,P.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,P.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(n),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...ct(n)):e==="f64"&&i.push(...ft(n));return i},$t=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let n=!isNaN(parseInt(t[1])),l=(s>=0?8:0)|(e?4:0)|(r?2:0)|(n?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:kt,o=s>=0?h(s):[];return n?[l,...h(a(t.shift())),...h(a(t.shift())),...o]:[l,...h(a(t.shift())),...o]},kt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?P.parse(t):typeof t=="number"?t:B(`Bad int ${t}`);return r>e?B(`Value out of range ${t}`):r},L=t=>[...h(t.length),...t.flat()];function he(t,e={}){typeof t=="string"&&(t=et(t));let{indent:r=" ",newline:i=`
4
+ `,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return l(t);return t.filter(a=>s||!n(a)).map(a=>l(a)).join(i);function n(a){return typeof a=="string"&&a[1]===";"}function l(a,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let y=1;for(typeof a[y]=="string"&&a[y][0]==="$"&&(f+=" "+a[y++]),Array.isArray(a[y])&&(a[y][0]==="result"||a[y][0]==="type")&&(f+=" "+l(a[y++],o));Array.isArray(a[y])&&/^catch/.test(a[y][0]);)f+=" "+l(a[y++],o).trim();for(;y<a.length;y++)f+=Array.isArray(a[y])?i+r.repeat(o+1)+l(a[y],o+1):" "+a[y];return`(${f+i+r.repeat(o)})`}let u=!!i&&a.length<4&&!a.some(y=>typeof y=="string"&&y[0]===";"&&y[1]===";"),p=r.repeat(o+1);for(let y=1;y<a.length;y++){let g=a[y]?.valueOf?.()??a[y];if(typeof g=="string"&&g[1]===";"){if(!s)continue;if(g[0]===";")if(i)f+=i+p+g.trimEnd(),c=!0;else{let m=f[f.length-1];m&&m!==" "&&m!=="("&&(f+=" "),f+=g.trimEnd()+`
5
5
  `}else{let m=f[f.length-1];m&&m!==" "&&m!=="("&&(f+=" "),f+=g.trimEnd()}}else if(Array.isArray(g))u&&(u=g.every(m=>!Array.isArray(m))),f+=i+p+l(g,o+1),c=!1;else if(a[0]==="data")u=!1,(i||f[f.length-1]!==")")&&(f+=i||" "),f+=p+g,c=!1;else{let m=f[f.length-1];c&&i?f+=i+p:m===`
6
- `?f+="":(m&&m!==")"&&m!==" "||i||m===")")&&(f+=" "),f+=g,c=!1}}return u?`(${f.replaceAll(i+p+"("," (")})`:`(${f+i+r.repeat(o)})`}}var xe=(t,e)=>{let r=[],i=t[0]==="module"?1:0;for(let s=i;s<t.length;s++)Array.isArray(t[s])&&t[s][0]===e&&r.push({node:t[s],idx:s});return r},St=(t,e,r)=>t.splice(e,0,r),er=0,rt=t=>`$__${t}${er++}`,rr=(t,e)=>{let r=new Set;if(S(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let i=rt("fntbl"),s=[...r],n=Object.fromEntries(s.map((f,c)=>[f,c])),l=xe(t,"func"),a=l.length?l[0].idx:t[0]==="module"?1:0;St(t,a,["table",i,"funcref",["elem",...s]]);let o={};return S(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let u=[],p=[];for(let y of f){if(Array.isArray(y)&&y[0]==="param")for(let g=1;g<y.length;g++)y[g][0]!=="$"&&u.push(y[g]);if(Array.isArray(y)&&y[0]==="result")for(let g=1;g<y.length;g++)p.push(y[g])}o[c]={params:u,results:p}}),U(t,(f,c,u)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&n[f[1]]!==void 0&&(c[u]=["i32.const",n[f[1]]]),f[0]==="call_ref"){let p=f[1],y=f.slice(2);c[u]=["call_indirect",i,["type",p],...y]}if(f[0]==="return_call_ref"){let p=f[1],y=f.slice(2);c[u]=["return_call_indirect",i,["type",p],...y]}}}),t},ir={"i32.extend8_s":["i32",24],"i32.extend16_s":["i32",16],"i64.extend8_s":["i64",56n],"i64.extend16_s":["i64",48n],"i64.extend32_s":["i64",32n]},sr=(t,e)=>(U(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=ir[r[0]];if(!n)return;let[l,a]=n,o=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,a]],[`${l}.const`,a]]}),t),he={"i32.trunc_sat_f32_s":{itype:"i32",ftype:"f32",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f32_u":{itype:"i32",ftype:"f32",signed:!1,min:0,max:4294967295},"i32.trunc_sat_f64_s":{itype:"i32",ftype:"f64",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f64_u":{itype:"i32",ftype:"f64",signed:!1,min:0,max:4294967295},"i64.trunc_sat_f32_s":{itype:"i64",ftype:"f32",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f32_u":{itype:"i64",ftype:"f32",signed:!1,min:0n,max:18446744073709551615n},"i64.trunc_sat_f64_s":{itype:"i64",ftype:"f64",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f64_u":{itype:"i64",ftype:"f64",signed:!1,min:0n,max:18446744073709551615n}},nr=(t,e)=>{let r=new Set;if(S(t,s=>{Array.isArray(s)&&he[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:a,min:o,max:f}=he[s],c=rt(`trunc_${n}_${l}_${a?"s":"u"}`);i[s]=c;let u=`${n}.trunc_${l}_${a?"s":"u"}`,p=n==="i64"?0n:0,y=["func",c,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,p]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${n}.const`,f]],["else",[u,["local.get","$v"]]]]]]]]];t.push(y)}return U(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t},lr=(t,e)=>{let r=new Set,i=new Set;S(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${a}_${o}`)}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0;i.add(a)}}});let s={},n={};for(let l of r){let[a,o]=l.split("_").map(Number),f=rt(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=f;let c=a?["i32.store8",a]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...u,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let l of i){let a=rt(`memset${l===0?"":"_"+l}`);n[l]=a;let o=l?["i32.store8",l]:["i32.store8"];t.push(["func",a,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return U(t,(l,a,o)=>{if(!(!Array.isArray(l)||!a)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,u=l.filter(p=>Array.isArray(p)||typeof p=="string"&&p[0]==="$");a[o]=["call",s[`${f}_${c}`],...u]}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0,c=l.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[o]=["call",n[f],...c]}}}),t},ar=(t,e)=>{let r=!1;return S(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&U(t,(i,s,n)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[n]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[n]=["return",["call_indirect",...i.slice(1)]]))}),t},fr=(t,e)=>(U(t,(r,i,s)=>{if(!(!Array.isArray(r)||!i)&&(r[0]==="ref.i31"&&(i[s]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(i[s]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t),or=(t,e)=>{let r={};S(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l=s.length-1;l>=0;l--){let a=s[l];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[n]={type:a[0].split(".")[0],value:a[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let n=s[0];if(n==="global.get"&&r[s[1]]){let l=r[s[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=i(s[1]),a=i(s[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),a=i(s[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),a=i(s[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}return s};return U(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let a=2;a<s.length;a++)if(Array.isArray(s[a])){let o=i(s[a]);o!==s[a]&&(s[a]=o)}}}),t},cr=(t,e)=>{let r=new Map,i=[];if(S(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let c of a)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)f.push(c[u]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let s=Math.max(...[...r.values()].map(a=>a.length)),n={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(n[c]||(n[c]=[]),n[c].length<f){let u=rt(`ret_${c}_${n[c].length}`);n[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let a of i.reverse())St(t,l,a);return U(t,(a,o,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let p=0;p<a.length;p++)if(Array.isArray(a[p])&&a[p][0]==="result"){a[p]=["result",u[0]];break}}),t},dt={i32:4,i64:8,f32:4,f64:8},ur=(t,e)=>{let r=new Map,i=new Map,s=1;if(S(t,m=>{if(!Array.isArray(m)||m[0]!=="type")return;let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;if(_){for(let b of m)if(Array.isArray(b)){if(b[0]==="struct"){let v=[];for(let A of b)if(Array.isArray(A)&&A[0]==="field"){let z=typeof A[1]=="string"&&A[1][0]==="$"?A[1]:null,I=z?A[2]:A[1],M=Array.isArray(I)&&I[0]==="mut"?I[1]:I;v.push({name:z,type:M})}r.set(_,{kind:"struct",fields:v}),i.set(_,s++)}if(b[0]==="array"){let v=b[1],A=Array.isArray(v)&&v[0]==="mut"?v[1]:v;r.set(_,{kind:"array",elemType:A}),i.set(_,s++)}}}}),!r.size)return t;let n=xe(t,"memory").length>0,l=rt("alloc"),a=rt("heap_ptr"),o=t[0]==="module"?1:0;n||St(t,o,["memory",1]),St(t,o+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",a]],["global.set",a,["i32.add",["global.get",a],["local.get","$size"]]],["local.get","$ptr"]];t.push(f);let c=m=>{let _=4;for(let b of m.fields)_+=dt[b.type]||4;return _},u=(m,_)=>{let b=4;for(let v=0;v<_;v++)b+=dt[m.fields[v].type]||4;return b},p=(m,_)=>{for(let b=0;b<m.fields.length;b++)if(m.fields[b].name===_)return b;return-1},y=0,g=()=>`$__gc_tmp${y++}`;return S(t,m=>{if(!Array.isArray(m)||m[0]!=="func")return;let _=!1,b=!1,v=!1,A=!1;if(S(m,I=>{Array.isArray(I)&&((I[0]==="struct.new"||I[0]==="struct.new_default")&&(_=!0),(I[0]==="array.new"||I[0]==="array.new_default")&&(b=!0,v=!0,A=!0))}),!_&&!b)return;let z=1;for(let I=1;I<m.length;I++){let M=m[I];if(Array.isArray(M)&&(M[0]==="param"||M[0]==="result"||M[0]==="local"||M[0]==="export"||M[0]==="type"))z=I+1;else if(typeof M=="string"&&M[0]==="$")z=I+1;else if(!Array.isArray(M))z=I+1;else break}_&&m.splice(z++,0,["local","$__gc_ptr","i32"]),b&&m.splice(z++,0,["local","$__gc_aptr","i32"]),v&&m.splice(z++,0,["local","$__gc_alen","i32"]),A&&m.splice(z++,0,["local","$__gc_aidx","i32"])}),U(t,(m,_,b)=>{if(!(!Array.isArray(m)||!_)){if(m[0]==="struct.new"||m[0]==="struct.new_default"){let v=m[1],A=r.get(v);if(!A||A.kind!=="struct")return;let z=c(A),I=i.get(v),M=m.slice(2),L="$__gc_ptr",O=[["local.set",L,["call",l,["i32.const",z]]],["i32.store",["local.get",L],["i32.const",I]]];if(m[0]==="struct.new")for(let q=0;q<A.fields.length;q++){let x=A.fields[q],d=u(A,q),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store";O.push([k,["i32.add",["local.get",L],["i32.const",d]],M[q]||[`${x.type}.const`,0]])}else for(let q=0;q<A.fields.length;q++){let x=A.fields[q],d=u(A,q),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store",D=x.type==="i64"?["i64.const",0n]:x.type==="f32"?["f32.const",0]:x.type==="f64"?["f64.const",0]:["i32.const",0];O.push([k,["i32.add",["local.get",L],["i32.const",d]],D])}O.push(["local.get",L]),_[b]=["block",["result","i32"],...O]}if(m[0]==="struct.get"){let v=m[1],A=m[2],z=m[3],I=r.get(v);if(!I||I.kind!=="struct")return;let M=typeof A=="string"&&A[0]==="$"?p(I,A):parseInt(A);if(M<0)return;let L=I.fields[M],O=u(I,M),q=L.type==="i64"?"i64.load":L.type==="f32"?"f32.load":L.type==="f64"?"f64.load":"i32.load";_[b]=[q,["i32.add",z,["i32.const",O]]]}if(m[0]==="struct.set"){let v=m[1],A=m[2],z=m[3],I=m[4],M=r.get(v);if(!M||M.kind!=="struct")return;let L=typeof A=="string"&&A[0]==="$"?p(M,A):parseInt(A);if(L<0)return;let O=M.fields[L],q=u(M,L),x=O.type==="i64"?"i64.store":O.type==="f32"?"f32.store":O.type==="f64"?"f64.store":"i32.store";_[b]=[x,["i32.add",z,["i32.const",q]],I]}if(m[0]==="array.new"||m[0]==="array.new_default"){let v=m[1],A=r.get(v);if(!A||A.kind!=="array")return;let z=i.get(v),I=dt[A.elemType]||4,M=m[0]==="array.new"?m[2]:null,L=m[0]==="array.new"?m[3]:m[2],O="$__gc_aptr",q="$__gc_alen",x="$__gc_aidx",d=A.elemType==="i64"?"i64.store":A.elemType==="f32"?"f32.store":A.elemType==="f64"?"f64.store":"i32.store",k=[["local.set",q,L],["local.set",O,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",q],["i32.const",I]]]]],["i32.store",["local.get",O],["i32.const",z]],["i32.store",["i32.add",["local.get",O],["i32.const",4]],["local.get",q]]];M&&k.push(["local.set",x,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",x],["local.get",q]]],[d,["i32.add",["i32.add",["local.get",O],["i32.const",8]],["i32.mul",["local.get",x],["i32.const",I]]],M],["local.set",x,["i32.add",["local.get",x],["i32.const",1]]],["br","$loop"]]]),k.push(["local.get",O]),_[b]=["block",["result","i32"],...k]}if(m[0]==="array.get"){let v=m[1],A=m[2],z=m[3],I=r.get(v);if(!I||I.kind!=="array")return;let M=dt[I.elemType]||4,L=I.elemType==="i64"?"i64.load":I.elemType==="f32"?"f32.load":I.elemType==="f64"?"f64.load":"i32.load";_[b]=[L,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",z,["i32.const",M]]]]}if(m[0]==="array.set"){let v=m[1],A=m[2],z=m[3],I=m[4],M=r.get(v);if(!M||M.kind!=="array")return;let L=dt[M.elemType]||4,O=M.elemType==="i64"?"i64.store":M.elemType==="f32"?"f32.store":M.elemType==="f64"?"f64.store":"i32.store";_[b]=[O,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",z,["i32.const",L]]],I]}if(m[0]==="array.len"){let v=m[1];_[b]=["i32.load",["i32.add",v,["i32.const",4]]]}}}),t},yr=(t,e)=>{let r=new Map,i=1;return S(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l of s)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,i++)}),r.size&&U(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let a=s[1],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=s[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(s[0]==="ref.cast"){let a=s[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=s[2],u=r.get(o);if(u!==void 0){let p=rt("cast");f?n[l]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["if",["i32.and",["i32.ne",["local.get",p],["i32.const",0]],["i32.ne",["i32.load",["local.get",p]],["i32.const",u]]],["then",["unreachable"]]],["local.get",p]]:n[l]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["if",["i32.or",["i32.eqz",["local.get",p]],["i32.ne",["i32.load",["local.get",p]],["i32.const",u]]],["then",["unreachable"]]],["local.get",p]]}}if(s[0]==="br_on_cast"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let p=r.get(u);if(p!==void 0){let y=rt("brcast");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",a,["i32.and",["i32.ne",["local.get",y],["i32.const",0]],["i32.eq",["i32.load",["local.get",y]],["i32.const",p]]]],["local.get",y]]}}if(s[0]==="br_on_cast_fail"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let p=r.get(u);if(p!==void 0){let y=rt("brfail");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",a,["i32.or",["i32.eqz",["local.get",y]],["i32.ne",["i32.load",["local.get",y]],["i32.const",p]]]],["local.get",y]]}}}}),t},zt=[["funcref",["ref.func","call_ref","return_call_ref"],rr],["sign_ext",["i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s"],sr],["nontrapping",["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u"],nr],["bulk_memory",["memory.copy","memory.fill"],lr],["return_call",["return_call","return_call_indirect"],ar],["i31ref",["ref.i31","i31.get_s","i31.get_u"],fr],["extended_const",["global.get"],or],["multi_value",[],cr],["gc",["struct.new","struct.get","struct.set","array.new","array.get","array.set","array.len","struct.new_default","array.new_default","array.new_fixed","array.copy"],ur],["ref_cast",["ref.test","ref.cast","br_on_cast","br_on_cast_fail"],yr]],Ti=Object.fromEntries(zt.map(t=>[t[0],t[1]])),pr=t=>{if(t===!1)return{};if(t!==!0&&typeof t!="string")return{...t};let e=typeof t=="string"?new Set(t.split(/\s+/).filter(Boolean)):null,r={};for(let i of zt)r[i[0]]=e?e.has("all")||e.has(i[0]):!0;return r},mr=t=>{let e=new Set;return S(t,r=>{if(typeof r=="string")for(let i of zt)i[1].some(n=>r===n||r.startsWith(n+" "))&&e.add(i[0])}),S(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&S(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),S(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e};function jt(t,e=!0){typeof t=="string"&&(t=et(t)),t=G(t),e=pr(e);let r=mr(t),i={uid:0};for(let s of zt){let n=s[2];r.has(s[0])&&e[s[0]]!==!1&&(t=n(t,i))}return t}var de=t=>{try{return yt(t).length}catch{return 1/0}},E=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!E(t[r],e[r]))return!1;return!0},Ot=t=>{let e=1;for(;e<t.length;){let s=t[e];if(Array.isArray(s)&&(s[0]==="then"||s[0]==="else"||s[0]==="result"||s[0]==="param")){e++;continue}break}let r=null,i=null;for(let s=e+1;s<t.length;s++){let n=t[s];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(i=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:i}},gr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,n=new Map,l=new Map,a=(x,d,k,D=!1)=>{let Q=typeof d[1]=="string"&&d[1][0]==="$",w=Q?d[1]:k,N=!D&&d.some(J=>Array.isArray(J)&&J[0]==="export"),F={node:d,idx:k,used:N,isImport:D};return x.set(w,F),Q&&x.set(k,F),l.set(d,F),F},o=0,f=0,c=0,u=0,p=0,y=[],g=[],m=[],_=[];for(let x of t.slice(1)){if(!Array.isArray(x))continue;let d=x[0];if(d==="type")a(i,x,c++);else if(d==="func")a(e,x,o++);else if(d==="global")a(r,x,f++);else if(d==="table")a(s,x,u++);else if(d==="memory")a(n,x,p++);else if(d==="import")for(let k of x)Array.isArray(k)&&(k[0]==="func"?a(e,k,o++,!0):k[0]==="global"?a(r,k,f++,!0):k[0]==="table"?a(s,k,u++,!0):k[0]==="memory"&&a(n,k,p++,!0));else d==="export"?m.push(x):d==="start"?_.push(x):d==="elem"?y.push(x):d==="data"&&g.push(x)}let b=[],v=x=>{x&&!x.scanned&&b.push(x)},A=x=>{let d=e.get(x);d&&(d.used||(d.used=!0),v(d))},z=x=>{let d=r.get(x);d&&(d.used=!0)},I=x=>{let d=s.get(x);d&&(d.used=!0)},M=x=>{typeof x=="string"&&x[0]!=="$"&&(x=+x);let d=n.get(x);d&&(d.used=!0)},L=x=>{let d=i.get(x);d&&(d.used=!0)};for(let x of m)for(let d of x){if(!Array.isArray(d))continue;let[k,D]=d;k==="func"?A(D):k==="global"?z(D):k==="table"?I(D):k==="memory"&&M(D)}for(let x of _){let d=x[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),A(d)}for(let x of y)S(x,d=>{Array.isArray(d)&&d[0]==="ref.func"?A(d[1]):typeof d=="string"&&d[0]==="$"&&A(d)});for(let x of g){let d=x[1];Array.isArray(d)&&d[0]==="memory"?M(d[1]):typeof d=="string"&&d[0]==="$"?M(d):Array.isArray(d)&&M(0)}for(let x of[e,r,s,n])for(let d of x.values())d.used&&v(d);if(!(m.length>0||_.length>0||y.length>0||b.length>0)){for(let x of[e,r,s,n])for(let d of x.values())d.used=!0;return t}for(;b.length;){let x=b.pop();x.scanned||(x.scanned=!0,!x.isImport&&S(x.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&A(d);return}let[k,D]=d;if(k==="call"||k==="return_call"||k==="ref.func")A(D);else if(k==="global.get"||k==="global.set")z(D);else if(k==="type")L(D);else if(k==="call_indirect"||k==="return_call_indirect")for(let Q of d)typeof Q=="string"&&Q[0]==="$"&&I(Q);typeof k=="string"&&(k.startsWith("memory.")||k.includes(".load")||k.includes(".store"))&&M(0)}))}let q=["module"];for(let x of t.slice(1)){if(!Array.isArray(x)){q.push(x);continue}let d=x[0];if(d==="func"||d==="global"||d==="type")l.get(x)?.used&&q.push(x);else if(d==="import"){let k=!1;for(let D of x){if(!Array.isArray(D))continue;if(l.get(D)?.used){k=!0;break}}k&&q.push(x)}else q.push(x)}return q},Ae=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),ke=new ArrayBuffer(8),Yt=new Float64Array(ke),Xt=new BigInt64Array(ke),Me=new ArrayBuffer(4),Zt=new Float32Array(Me),Kt=new Int32Array(Me),_r=t=>(Yt[0]=t,Xt[0]),hr=t=>(Xt[0]=BigInt.asIntN(64,t),Yt[0]),xr=t=>(Zt[0]=t,Kt[0]),dr=t=>(Kt[0]=t|0,Zt[0]),pt=t=>(e,r)=>t(e,r)?1:0,Tt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,mt=t=>(e,r)=>t(e,r)?1:0,Et=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,Ar={"i32.add":(t,e)=>t+e|0,"i32.sub":(t,e)=>t-e|0,"i32.mul":(t,e)=>Math.imul(t,e),"i32.div_s":(t,e)=>e!==0?t/e|0:null,"i32.div_u":(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32.rem_s":(t,e)=>e!==0?t%e|0:null,"i32.rem_u":(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32.and":(t,e)=>t&e,"i32.or":(t,e)=>t|e,"i32.xor":(t,e)=>t^e,"i32.shl":(t,e)=>t<<(e&31),"i32.shr_s":(t,e)=>t>>(e&31),"i32.shr_u":(t,e)=>t>>>(e&31),"i32.rotl":(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32.rotr":(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32.eq":pt((t,e)=>t===e),"i32.ne":pt((t,e)=>t!==e),"i32.lt_s":pt((t,e)=>t<e),"i32.lt_u":Tt((t,e)=>t<e),"i32.gt_s":pt((t,e)=>t>e),"i32.gt_u":Tt((t,e)=>t>e),"i32.le_s":pt((t,e)=>t<=e),"i32.le_u":Tt((t,e)=>t<=e),"i32.ge_s":pt((t,e)=>t>=e),"i32.ge_u":Tt((t,e)=>t>=e),"i32.eqz":t=>t===0?1:0,"i32.clz":t=>Math.clz32(t),"i32.ctz":t=>t===0?32:31-Math.clz32(t&-t),"i32.popcnt":t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32.wrap_i64":t=>Number(BigInt.asIntN(32,t)),"i32.extend8_s":t=>t<<24>>24,"i32.extend16_s":t=>t<<16>>16,"i64.add":(t,e)=>BigInt.asIntN(64,t+e),"i64.sub":(t,e)=>BigInt.asIntN(64,t-e),"i64.mul":(t,e)=>BigInt.asIntN(64,t*e),"i64.div_s":(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64.div_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64.rem_s":(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64.rem_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64.and":(t,e)=>BigInt.asIntN(64,t&e),"i64.or":(t,e)=>BigInt.asIntN(64,t|e),"i64.xor":(t,e)=>BigInt.asIntN(64,t^e),"i64.shl":(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64.shr_s":(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64.shr_u":(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64.eq":mt((t,e)=>t===e),"i64.ne":mt((t,e)=>t!==e),"i64.lt_s":mt((t,e)=>t<e),"i64.lt_u":Et((t,e)=>t<e),"i64.gt_s":mt((t,e)=>t>e),"i64.gt_u":Et((t,e)=>t>e),"i64.le_s":mt((t,e)=>t<=e),"i64.le_u":Et((t,e)=>t<=e),"i64.ge_s":mt((t,e)=>t>=e),"i64.ge_u":Et((t,e)=>t>=e),"i64.eqz":t=>t===0n?1:0,"i64.extend_i32_s":t=>BigInt(t),"i64.extend_i32_u":t=>BigInt(t>>>0),"i64.extend8_s":t=>BigInt.asIntN(64,BigInt.asIntN(8,t)),"i64.extend16_s":t=>BigInt.asIntN(64,BigInt.asIntN(16,t)),"i64.extend32_s":t=>BigInt.asIntN(64,BigInt.asIntN(32,t)),"f32.add":(t,e)=>Math.fround(t+e),"f32.sub":(t,e)=>Math.fround(t-e),"f32.mul":(t,e)=>Math.fround(t*e),"f32.div":(t,e)=>Math.fround(t/e),"f32.neg":t=>Math.fround(-t),"f32.abs":t=>Math.fround(Math.abs(t)),"f32.sqrt":t=>Math.fround(Math.sqrt(t)),"f32.ceil":t=>Math.fround(Math.ceil(t)),"f32.floor":t=>Math.fround(Math.floor(t)),"f32.trunc":t=>Math.fround(Math.trunc(t)),"f32.nearest":t=>Math.fround(Ae(t)),"f64.add":(t,e)=>t+e,"f64.sub":(t,e)=>t-e,"f64.mul":(t,e)=>t*e,"f64.div":(t,e)=>t/e,"f64.neg":t=>-t,"f64.abs":Math.abs,"f64.sqrt":Math.sqrt,"f64.ceil":Math.ceil,"f64.floor":Math.floor,"f64.trunc":Math.trunc,"f64.nearest":Ae,"i32.reinterpret_f32":xr,"f32.reinterpret_i32":dr,"i64.reinterpret_f64":_r,"f64.reinterpret_i64":hr,"f32.convert_i32_s":t=>Math.fround(t|0),"f32.convert_i32_u":t=>Math.fround(t>>>0),"f32.convert_i64_s":t=>Math.fround(Number(BigInt.asIntN(64,t))),"f32.convert_i64_u":t=>Math.fround(Number(BigInt.asUintN(64,t))),"f64.convert_i32_s":t=>t|0,"f64.convert_i32_u":t=>t>>>0,"f64.convert_i64_s":t=>Number(BigInt.asIntN(64,t)),"f64.convert_i64_u":t=>Number(BigInt.asUintN(64,t)),"f32.demote_f64":t=>Math.fround(t),"f64.promote_f32":t=>Math.fround(t)},br=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n;return Xt[0]=BigInt.asIntN(64,i|0x7ff0000000000000n|(t[0]==="-"?1n<<63n:0n)),Yt[0]},wr=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?parseInt(r):4194304;return Kt[0]=i|2139095040|(t[0]==="-"?2147483648:0)|0,Zt[0]},T=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;if(e==="i32.const")return{type:"i32",value:(typeof r=="string"?P.parse(r):r)|0};if(e==="i64.const")return{type:"i64",value:typeof r=="string"?nt.parse(r):BigInt(r)};if(e==="f32.const"){let i=wr(r);return{type:"f32",value:i!==null?i:Math.fround(Number(r))}}if(e==="f64.const"){let i=br(r);return{type:"f64",value:i!==null?i:Number(r)}}return null},be=(t,e)=>t==="i32"?["i32.const",e|0]:t==="i64"?["i64.const",e]:t==="f32"?["f32.const",Math.fround(e)]:t==="f64"?["f64.const",e]:null,vr=t=>U(t,e=>{if(!Array.isArray(e))return;let r=Ar[e[0]];if(r){if(r.length===1&&e.length===2){let i=T(e[1]);if(!i)return;let s=r(i.value);return s===null?void 0:be(xt(e[0]),s)}if(r.length===2&&e.length===3){let i=T(e[1]),s=T(e[2]);if(!i||!s)return;let n=r(i.value,s.value);return n===null?void 0:be(xt(e[0]),n)}}}),it=t=>(e,r)=>{let i=T(e),s=T(r);return i?.value===t?r:s?.value===t?e:null},K=t=>(e,r)=>T(r)?.value===t?e:null,$r={"i32.add":it(0),"i64.add":it(0n),"i32.sub":K(0),"i64.sub":K(0n),"i32.mul":it(1),"i64.mul":it(1n),"i32.div_s":K(1),"i32.div_u":K(1),"i64.div_s":K(1n),"i64.div_u":K(1n),"i32.and":it(-1),"i64.and":it(-1n),"i32.or":it(0),"i64.or":it(0n),"i32.xor":it(0),"i64.xor":it(0n),"i32.shl":K(0),"i32.shr_s":K(0),"i32.shr_u":K(0),"i64.shl":K(0n),"i64.shr_s":K(0n),"i64.shr_u":K(0n)},Ir=t=>U(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=$r[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),kr=t=>U(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=T(s);if(n&&n.value>0&&!(n.value&n.value-1)){let a=Math.log2(n.value);if(Number.isInteger(a))return["i32.shl",i,["i32.const",a]]}let l=T(i);if(l&&l.value>0&&!(l.value&l.value-1)){let a=Math.log2(l.value);if(Number.isInteger(a))return["i32.shl",s,["i32.const",a]]}}if(r==="i64.mul"){let n=T(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let a=BigInt(n.value.toString(2).length-1);return["i64.shl",i,["i64.const",a]]}let l=T(i);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let a=BigInt(l.value.toString(2).length-1);return["i64.shl",s,["i64.const",a]]}}if(r==="i32.div_u"){let n=T(s);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",i,["i32.const",l]]}}if(r==="i64.div_u"){let n=T(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",l]]}}if(r==="i32.rem_u"){let n=T(s);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",i,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=T(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",i,["i64.const",n.value-1n]]}}),Mr=t=>U(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ot(e),l=T(i);if(!l)return;let a=l.value!==0&&l.value!==0n?s:n;if(a&&a.length>1){let o=a.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=T(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=T(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),we=new Set(["unreachable","return","br","br_table"]),Br=t=>(S(t,e=>{if(!Array.isArray(e))return;let r=e[0];if((r==="func"||r==="block"||r==="loop")&&ve(e),r==="if")for(let i=1;i<e.length;i++)Array.isArray(e[i])&&(e[i][0]==="then"||e[i][0]==="else")&&ve(e[i])}),t),ve=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let n=s[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=i),we.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),we.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},Nr=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=[],i=new Map,s=new Set;for(let n=1;n<e.length;n++){let l=e[n];Array.isArray(l)&&(l[0]==="local"&&(r.push({node:l,idx:n}),typeof l[1]=="string"&&l[1][0]==="$"&&i.set(l[1],l[2])),l[0]==="param"&&typeof l[1]=="string"&&l[1][0]==="$"&&(i.set(l[1],l[2]),s.add(l[1])))}S(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let a=n[1];typeof a=="string"&&s.add(a)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:a}=r[n],o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;o&&!s.has(o)&&e.splice(l,1)}}),t),Sr=new Set(["call","call_indirect","return_call","return_call_indirect","table.set","table.grow","table.fill","table.copy","table.init","struct.set","struct.new","array.set","array.new","array.new_fixed","array.new_data","array.new_elem","array.init_data","array.init_elem","ref.i31","global.set","local.set","local.tee","unreachable","return","br","br_if","br_table","br_on_null","br_on_non_null","br_on_cast","br_on_cast_fail","throw","rethrow","throw_ref","try_table","data.drop","elem.drop"]),zr=[".store","memory.",".atomic."],gt=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||Sr.has(e))return!1;for(let r of zr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!gt(t[r]))return!1;return!0},Tr=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return S(t,i=>{!Array.isArray(i)||i.length<2||typeof i[1]!="string"||(i[0]==="local.get"?r(i[1]).gets++:i[0]==="local.set"?r(i[1]).sets++:i[0]==="local.tee"&&r(i[1]).tees++)}),e},Er=t=>{let e=T(t);if(!e)return!1;if(e.type==="i32"){let r=e.value|0;return r>=-64&&r<=63}if(e.type==="i64"){let r=typeof e.value=="bigint"?e.value:BigInt(e.value);return r>=-64n&&r<=63n}return!1},Be=t=>t.pure&&t.singleUse||Er(t.val),Gt=(t,e)=>{for(let[r,i]of t){let s=!1;S(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},Ne=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.includes(".load")||e==="memory.copy"||e==="memory.size"))return!0;for(let r=1;r<t.length;r++)if(Ne(t[r]))return!0;return!1},Ht=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.endsWith(".store")||e==="memory.copy"||e==="memory.fill"||e==="memory.init"||e.includes(".atomic.")&&!e.endsWith(".load")))return!0;for(let r=1;r<t.length;r++)if(Ht(t[r]))return!0;return!1},Vt=(t,e)=>{if(!Array.isArray(t))return t;let r=t[0];if(r==="local.get"&&t.length===2){let s=typeof t[1]=="string"&&e.get(t[1]);return s&&Be(s)?G(s.val):t}let i=e;if(r==="block"||r==="loop"||r==="if"){let s=null;S(t,n=>{Array.isArray(n)&&(n[0]==="local.set"||n[0]==="local.tee")&&typeof n[1]=="string"&&e.has(n[1])&&(s||(s=new Map(e)),s.delete(n[1]))}),s&&(i=s)}for(let s=1;s<t.length;s++){let n=Vt(t[s],i);n!==t[s]&&(t[s]=n),s+1<t.length&&Array.isArray(t[s])&&S(t[s],l=>{Array.isArray(l)&&(l[0]==="local.set"||l[0]==="local.tee")&&typeof l[1]=="string"&&(i===e&&(i=new Map(e)),i.delete(l[1]),Gt(i,l[1]))})}return t},Ur=(t,e,r)=>{let i=!1,s=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let a=t[l];if(!Array.isArray(a))continue;let o=a[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if((o==="local.set"||o==="local.tee")&&a.length===3&&typeof a[1]=="string"){let f=Vt(a[2],n);f!==a[2]&&(a[2]=f,i=!0);let c=s(a[1]);if(Gt(n,a[1]),Ht(a[2]))for(let[u,p]of n)p.readsMem&&n.delete(u);n.set(a[1],{val:a[2],pure:gt(a[2]),readsMem:Ne(a[2]),singleUse:c.gets<=1&&c.sets<=1&&c.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[f,c]of n)T(c.val)||n.delete(f);if(o==="local.get"&&a.length===2&&typeof a[1]=="string"){let f=n.get(a[1]);if(f&&Be(f)){let c=G(f.val);a.length=0,a.push(...Array.isArray(c)?c:[c]),i=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let f=G(a);if(Vt(a,n),E(f,a)||(i=!0),S(a,c=>{Array.isArray(c)&&(c[0]==="local.set"||c[0]==="local.tee")&&typeof c[1]=="string"&&(n.delete(c[1]),Gt(n,c[1]))}),Ht(a))for(let[c,u]of n)u.readsMem&&n.delete(c)}}}return i},qr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let f=G(n[2]);t.splice(s,2,...Array.isArray(f)?[f]:[f]),i=!0,s--}return i},Fr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(s,2,["local.tee",a,G(n[2])]),i=!0)}return i},Or=(t,e,r)=>{let i=!1,s=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let a=typeof l[1]=="string"?l[1]:null;if(!a||e.has(a))continue;let o=s(a);l[0]==="local.set"&&o.gets===0&&o.tees===0?l.length===3?gt(l[2])&&(t.splice(n,1),i=!0):l.length===2&&(t[n]=["drop"],i=!0):l[0]==="local"&&a[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0&&(t.splice(n,1),i=!0)}return i},Se=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),ze=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Set;for(let s of e)Array.isArray(s)&&s[0]==="param"&&typeof s[1]=="string"&&r.add(s[1]);let i=[];U(e,s=>{Se(s)&&i.push(s)});for(let s=0;s<6;s++){let n=Tr(e),l=!1;for(let a of i)Ur(a,r,n)&&(l=!0),qr(a,r,n)&&(l=!0),Fr(a,r,n)&&(l=!0),Or(a,r,n)&&(l=!0);if(!l)break}}),t),Lr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map;for(let r of t.slice(1)){if(!Array.isArray(r)||r[0]!=="func")continue;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i)continue;let s=[],n=[],l=!1,a=!1;for(let o=1;o<r.length;o++){let f=r[o];if(Array.isArray(f))if(f[0]==="param")if(typeof f[1]=="string"&&f[1][0]==="$")s.push({name:f[1],type:f[2]});else{s=null;break}else f[0]==="local"?l=!0:f[0]==="export"?a=!0:f[0]!=="result"&&f[0]!=="type"&&n.push(f)}if(s&&!l&&!a&&s.length<=4&&n.length===1){let o=new Set(s.map(u=>u.name)),f=!1,c=!1;S(n[0],u=>{Array.isArray(u)&&((u[0]==="local.set"||u[0]==="local.tee")&&o.has(u[1])&&(f=!0),(u[0]==="return"||u[0]==="return_call"||u[0]==="return_call_indirect")&&(c=!0))}),!f&&!c&&e.set(i,{body:n[0],params:s})}}return e.size===0||U(t,r=>{if(!Array.isArray(r)||r[0]!=="call")return;let i=r[1];if(!e.has(i))return;let{body:s,params:n}=e.get(i),l=r.slice(2);return n.length===0?G(s):U(G(s),o=>{if(!Array.isArray(o)||o[0]!=="local.get")return;let f=o[1],c=n.findIndex(u=>u.name===f);if(c!==-1&&l[c])return G(l[c])})}),t},Cr=0,Dr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set(["export","type","param","result","local"]),r=f=>{let c=2;for(;c<f.length&&(typeof f[c]=="string"||Array.isArray(f[c])&&e.has(f[c][0]));)c++;return c},i=f=>f==="br"||f==="br_if"||f==="br_table",s=f=>{if(!Array.isArray(f))return!1;let c=f[0];if(c==="return_call"||c==="return_call_indirect"||c==="return_call_ref"||c==="try"||c==="try_table"||c==="delegate"||c==="rethrow")return!0;if(i(c)){for(let u=1;u<f.length;u++)if(typeof f[u]=="number"||typeof f[u]=="string"&&/^\d+$/.test(f[u]))return!0}for(let u=1;u<f.length;u++)if(s(f[u]))return!0;return!1},n=(f,c)=>{if(!Array.isArray(f))return!1;if((f[0]==="call"||f[0]==="return_call")&&f[1]===c)return!0;for(let u=1;u<f.length;u++)if(n(f[u],c))return!0;return!1},l=f=>f==="i32"?["i32.const",0]:f==="i64"?["i64.const",0n]:f==="f32"?["f32.const",0]:f==="f64"?["f64.const",0]:f==="v128"?["v128.const","i64x2",0n,0n]:null,a=(f,c)=>{let u=!1,p=!1,y=0,g=m=>{if(u||!Array.isArray(m))return;let _=m[0],b=_==="local.set"||_==="local.tee";if((b||_==="local.get")&&m[1]===c){if(b)for(let A=2;A<m.length&&!u;A++)g(m[A]);if(u)return;u=!0,(_==="local.get"||y>0)&&(p=!0);return}let v=_==="if";for(let A=1;A<m.length&&!u;A++){let z=m[A],I=v&&Array.isArray(z)&&(z[0]==="then"||z[0]==="else");I&&y++,g(z),I&&y--}};for(let m of f){if(u)break;g(m)}return u?p:!1},o=(f,c)=>{if(!Array.isArray(f))return;let u=f[0];if(u==="export"&&Array.isArray(f[2])&&f[2][0]==="func"&&typeof f[2][1]=="string")c.add(f[2][1]);else if(u==="start"&&typeof f[1]=="string")c.add(f[1]);else if(u==="ref.func"&&typeof f[1]=="string")c.add(f[1]);else if(u==="elem")for(let p of f)typeof p=="string"&&p[0]==="$"&&c.add(p);for(let p of f)o(p,c)};for(let f=0;f<16;f++){let c=t.filter(w=>Array.isArray(w)&&w[0]==="func"),u=new Map;for(let w of c)typeof w[1]=="string"&&u.set(w[1],w);let p=new Map,y=new Set,g=w=>{if(!Array.isArray(w))return;let N=w[0];N==="call"&&typeof w[1]=="string"?p.set(w[1],(p.get(w[1])||0)+1):N==="return_call"&&typeof w[1]=="string"&&y.add(w[1]);for(let F=1;F<w.length;F++)g(w[F])};g(t);let m=new Set;for(let w of t)(!Array.isArray(w)||w[0]!=="func")&&o(w,m);let _=null;for(let[w,N]of u){if(m.has(w)||y.has(w)||p.get(w)!==1||n(N,w))continue;let F=!0,J=0;for(let V=2;V<N.length;V++){let j=N[V];if(typeof j!="string"){if(!Array.isArray(j)){F=!1;break}if(j[0]==="param"||j[0]==="local"){if(typeof j[1]!="string"||j[1][0]!=="$"){F=!1;break}if(j[0]==="local"&&!l(j[2])){F=!1;break}}else if(j[0]==="result")J+=j.length-1;else if(j[0]==="export"){F=!1;break}else{if(j[0]==="type")continue;break}}}if(!F||J>1)continue;let tt=!1;for(let V=r(N);V<N.length;V++)if(s(N[V])){tt=!0;break}if(!tt){_=w;break}}if(!_)break;let b=u.get(_),v=[],A=[],z=null;for(let w=2;w<b.length;w++){let N=b[w];if(!(typeof N=="string"||!Array.isArray(N)))if(N[0]==="param")v.push({name:N[1],type:N[2]});else if(N[0]==="result")N.length>1&&(z=N[1]);else if(N[0]==="local")A.push({name:N[1],type:N[2]});else{if(N[0]==="export"||N[0]==="type")continue;break}}let I=b.slice(r(b)),M=++Cr,L=`$__inl${M}`,O=new Map;for(let w of v)O.set(w.name,`$__inl${M}_${w.name.slice(1)}`);for(let w of A)O.set(w.name,`$__inl${M}_${w.name.slice(1)}`);let q=w=>w==="block"||w==="loop"||w==="if",x=new Map,d=w=>{if(Array.isArray(w)){q(w[0])&&typeof w[1]=="string"&&w[1][0]==="$"&&!x.has(w[1])&&x.set(w[1],`$__inl${M}L_${w[1].slice(1)}`);for(let N=1;N<w.length;N++)d(w[N])}};for(let w of I)d(w);let k=w=>{if(!Array.isArray(w))return w;let N=w[0];return(N==="local.get"||N==="local.set"||N==="local.tee")&&typeof w[1]=="string"&&O.has(w[1])?[N,O.get(w[1]),...w.slice(2).map(k)]:N==="return"?["br",L,...w.slice(1).map(k)]:q(N)&&typeof w[1]=="string"&&x.has(w[1])?[N,x.get(w[1]),...w.slice(2).map(k)]:i(N)?[N,...w.slice(1).map(F=>typeof F=="string"&&x.has(F)?x.get(F):k(F))]:w.map((F,J)=>J===0?F:k(F))},D=!1;for(let w of c){if(w===b||D)continue;let N=r(w);for(let F=N;F<w.length;F++){let J=U(w[F],tt=>{if(D||!Array.isArray(tt)||tt[0]!=="call"||tt[1]!==_)return;let V=tt.slice(2);if(V.length!==v.length)return;let j=v.map((ot,Oe)=>["local.set",O.get(ot.name),V[Oe]]),ee=A.filter(ot=>a(I,ot.name)).map(ot=>["local.set",O.get(ot.name),l(ot.type)]),re=I.map(k);return D=!0,z?["block",L,["result",z],...j,...ee,...re]:["block",L,...j,...ee,...re]});if(J!==w[F]&&(w[F]=J),D){let tt=[...v,...A].map(V=>["local",O.get(V.name),V.type]);tt.length&&w.splice(r(w),0,...tt);break}}if(D)break}if(!D)break;let Q=t.indexOf(b);Q>=0&&t.splice(Q,1)}return t},Ut=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],a=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(a=!0),!n){if(l==="br"||l==="br_if"||l==="br_on_null"||l==="br_on_non_null"||l==="br_on_cast"||l==="br_on_cast_fail"){if(s[1]===e){r=!0;return}}else if(l==="br_table"){for(let o=1;o<s.length&&typeof s[o]=="string";o++)if(s[o]===e){r=!0;return}}else if(l==="catch"||l==="catch_ref"){if(s[2]===e){r=!0;return}}else if((l==="catch_all"||l==="catch_all_ref")&&s[1]===e){r=!0;return}}for(let o=1;o<s.length;o++)i(s[o],a)};for(let s of t)i(s,!1);return r},Rr=t=>(U(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2);let s=!1;for(;r<e.length;){let a=e[r];if(Array.isArray(a)&&(a[0]==="param"||a[0]==="type")){r++;continue}if(Array.isArray(a)&&a[0]==="result"){s=!0,r++;continue}break}let n=e.slice(r);if(!s||n.length!==1)return;let l=n[0];if(Array.isArray(l)&&!(i&&Ut(n,i))){e.length=0;for(let a of l)e.push(a)}}),S(t,e=>{if(!Se(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)){r++;continue}{let a=i[0],o=a==="local.set"||a==="global.set"?2:a==="drop"?1:-1;if(o>=0&&i.length===o+1){let f=i[o];if(Array.isArray(f)&&f[0]==="block"){let c=1,u=null;typeof f[1]=="string"&&f[1][0]==="$"&&(u=f[1],c=2);let p=!1;for(;c<f.length;){let g=f[c];if(Array.isArray(g)&&(g[0]==="param"||g[0]==="type")){c++;continue}if(Array.isArray(g)&&g[0]==="result"){p=!0,c++;continue}break}let y=p?f.slice(c):null;if(y&&y.length>=2&&!(u&&Ut(y,u))){let g=y[y.length-1],m=y.slice(0,-1);i[o]=g,e.splice(r,1,...m,i);continue}}}}if(i[0]!=="block"){r++;continue}let s=1,n=null;for(typeof i[1]=="string"&&i[1][0]==="$"&&(n=i[1],s=2);s<i.length;){let a=i[s];if(Array.isArray(a)&&(a[0]==="param"||a[0]==="result"||a[0]==="type")){s++;continue}break}let l=i.slice(s);if(n&&Ut(l,n)){r++;continue}e.splice(r,1,...l),r+=l.length}}),t),Wr=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let p of e)Array.isArray(p)&&p[0]==="local"&&typeof p[1]=="string"&&p[1][0]==="$"&&typeof p[2]=="string"&&r.set(p[1],p[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,a=0,o=p=>{if(l||!Array.isArray(p))return;let y=p[0],g=y==="loop";g&&s.push({start:n,end:n});let m=y==="local.set"||y==="local.tee";if(m||y==="local.get"){let _=p[1];if(typeof _!="string"||_[0]!=="$"){l=!0;return}if(m)for(let v=2;v<p.length;v++)o(p[v]);let b=n++;if(r.has(_)){let v=i.get(_);v||(v={start:b,end:b,firstOp:y,firstCond:a>0,loops:new Set},i.set(_,v)),b>v.end&&(v.end=b);for(let A of s)v.loops.add(A)}}else{n++;let _=y==="if";for(let b=1;b<p.length;b++){let v=p[b],A=_&&Array.isArray(v)&&(v[0]==="then"||v[0]==="else");A&&a++,o(v),A&&a--}}if(g){let _=s.pop();_.end=n}};if(o(e),l)return;for(let p of i.values())for(let y of p.loops)y.start<p.start&&(p.start=y.start),y.end>p.end&&(p.end=y.end);let f=[...i.entries()].sort((p,y)=>p[1].start-y[1].start),c=new Map,u=[];for(let[p,y]of f){let g=y.firstOp==="local.get"||y.firstCond,m=r.get(p),_=g?null:u.find(b=>b.type===m&&b.end<y.start);_?(c.set(p,_.primary),y.end>_.end&&(_.end=y.end)):u.push({primary:p,type:m,end:y.end})}c.size!==0&&S(e,p=>{Array.isArray(p)&&(p[0]==="local.get"||p[0]==="local.set"||p[0]==="local.tee")&&c.has(p[1])&&(p[1]=c.get(p[1]))})}),t),Pr=t=>U(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&gt(e[1]))return["nop"];if(r==="select"&&e.length>=4&&E(e[1],e[2]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ot(e),l=!s||s.length<=1,a=!n||n.length<=1;if(l&&a)return gt(i)?["nop"]:["drop",i];if(n&&a&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let i=[r];for(let s=1;s<e.length;s++){let n=e[s];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[s+1],a=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&gt(n)&&a){s++;continue}i.push(n)}if(i.length!==e.length)return i}}),jr={"i32.sub":(t,e)=>E(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>E(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>E(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>E(t,e)?["i64.const",0n]:null,"i32.eq":(t,e)=>E(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>E(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>E(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>E(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>E(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>E(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>E(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>E(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>E(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>E(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>E(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>E(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>E(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>E(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>E(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>E(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>E(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>E(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>E(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>E(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=T(t),i=T(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=T(t),i=T(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{if(E(t,e))return t;let r=T(t),i=T(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{if(E(t,e))return t;let r=T(t),i=T(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{if(E(t,e))return t;let r=T(t),i=T(e);return r?.value===-1||i?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{if(E(t,e))return t;let r=T(t),i=T(e);return r?.value===-1n||i?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Gr=t=>U(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=jr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Hr=t=>{let e=typeof t=="bigint"?t:BigInt(Math.trunc(Number(t)||0)),r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},Vr=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Hr(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},Yr=2,Xr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Set;for(let n of t.slice(1)){if(!Array.isArray(n))continue;if(n[0]==="export"&&Array.isArray(n[2])&&n[2][0]==="global"&&typeof n[2][1]=="string"){r.add(n[2][1]);continue}if(n[0]!=="global")continue;let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!l)continue;n.some(f=>Array.isArray(f)&&f[0]==="export")&&r.add(l);let a=n[2];if(Array.isArray(a)&&a[0]==="mut"||Array.isArray(a)&&a[0]==="import")continue;let o=n[3];T(o)&&e.set(l,o)}if(e.size===0)return t;let i=new Map;S(t,n=>{if(!Array.isArray(n))return;let l=n[1];typeof l!="string"||l[0]!=="$"||(n[0]==="global.set"?e.delete(l):n[0]==="global.get"&&i.set(l,(i.get(l)||0)+1))});let s=new Set;for(let[n,l]of e){let a=i.get(n)||0;if(a===0)continue;let o=Vr(l),f=o+2,c=a*Yr+f;a*o+(r.has(n)?f:0)<=c&&s.add(n)}if(s.size===0)return t;U(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return G(e.get(n[1]))});for(let n=t.length-1;n>=1;n--){let l=t[n];Array.isArray(l)&&l[0]==="global"&&typeof l[1]=="string"&&s.has(l[1])&&!r.has(l[1])&&t.splice(n,1)}return t},Zr=t=>U(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let i=r.endsWith("store"),s=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(s=+e[l].slice(7)),l++;let a=i?e.length-2:e.length-1,o=i?e.length-1:-1;if(a<l)return;let f=e[a];if(!Array.isArray(f)||f[0]!=="i32.add"||f.length!==3)return;let c=f[1],u=f[2],p=T(c),y=T(u),g=null,m=null;if(p&&p.type==="i32"?(m=p.value,g=u):y&&y.type==="i32"&&(m=y.value,g=c),g===null||m===null)return;let _=s+m,b=[r];n!==null&&b.push(n),b.push(`offset=${_}`);let v=null;for(let A=l;A<a;A++)typeof e[A]=="string"&&e[A].startsWith("align=")&&(v=e[A]);return v&&b.push(v),b.push(g),i&&b.push(e[o]),b}),Kr=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let i=1,s=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(s=e[1],i=2),!s)return;let n=-1;for(let a=e.length-1;a>=i;a--){let o=e[a];if(!Array.isArray(o)){o!=="nop"&&o!=="end"&&(n=a);continue}let f=o[0];if(!(f==="param"||f==="result"||f==="local"||f==="type"||f==="export")){n=a;break}}if(n<0)return;let l=e[n];Array.isArray(l)&&l[0]==="br"&&l[1]===s&&e.splice(n,1,...l.slice(2))}),t),Qr=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2),!i)return;for(;r<e.length;){let g=e[r];if(Array.isArray(g)&&g[0]==="type"){r++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}if(e.length-r!==1)return;let s=e[r];if(!Array.isArray(s)||s[0]!=="loop")return;let n=1,l=null;typeof s[1]=="string"&&s[1][0]==="$"&&(l=s[1],n=2);let a=[];for(;n<s.length;){let g=s[n];if(Array.isArray(g)&&g[0]==="type"){a.push(g),n++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}let o=s.slice(n);if(o.length<2)return;let f=o[0],c=o[o.length-1];if(!Array.isArray(f)||f[0]!=="br_if"||f[1]!==i||f.length!==3||!Array.isArray(c)||c[0]!=="br"||c[1]!==l||c.length!==2)return;let u=o.slice(1,-1);if(Ut(u,i))return;let p=f[2];Array.isArray(p)&&p[0]==="i32.eqz"&&p.length===2?p=p[1]:p=["i32.eqz",p];let y=["loop"];l&&y.push(l);for(let g of a)y.push(g);y.push(["if",p,["then",...u,c]]),e.length=0;for(let g of y)e.push(g)}),t),Jr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return S(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),U(t,r=>{if(!Array.isArray(r)||r[0]!=="global")return;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i||e.has(i))return;let s=typeof r[1]=="string"&&r[1][0]==="$",n=s?r[2]:r[1];if(Array.isArray(n)&&n[0]==="mut"){let l=[...r];return l[s?2:1]=n[1],l}})},ti=t=>U(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=Ot(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let a=i[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],r]}if(n&&!l&&s.length===2){let a=s[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],["i32.eqz",r]]}}),ei=t=>U(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=Ot(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(p=>Array.isArray(p)&&p[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let p=1;p<l&&E(r[r.length-p],i[i.length-p]);p++)n++;if(n===0)return;let a=r.slice(r.length-n),o=r.slice(0,r.length-n),f=i.slice(0,i.length-n),c=["block"];for(let p=1;p<e.length;p++){let y=e[p];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")&&c.push(y)}let u=["if"];for(let p=1;p<e.length;p++){let y=e[p];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")||u.push(y)}return u.push(o.length>1?o:["then"]),u.push(f.length>1?f:["else"]),c.push(u,...a),c}),Te=(t,e)=>{let r=[],i=[t];for(;i.length;){let s=i.pop();if(Array.isArray(s)){i.push("|");for(let n=s.length-1;n>=0;n--)i.push(s[n]);i.push("[")}else typeof s=="string"?r.push(e.has(s)?"$__L":s):typeof s=="bigint"?r.push(s.toString()+"n"):typeof s=="number"?r.push(s.toString()):s===null?r.push("null"):s===!0?r.push("t"):s===!1?r.push("f"):r.push(String(s))}return r.join(",")},ri=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&n.add(i[1]),S(i,a=>{if(!Array.isArray(a)||typeof a[1]!="string"||a[1][0]!=="$")return;let o=a[0];(o==="param"||o==="local"||o==="block"||o==="loop"||o==="if")&&n.add(a[1])});let l=Te(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||U(t,i=>{if(!Array.isArray(i))return;let s=i[0];if((s==="call"||s==="return_call")&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(s==="ref.func"&&r.has(i[1]))return["ref.func",r.get(i[1])];if(s==="elem"){let n=i[i.length-1];if(Array.isArray(n))return[...i.slice(0,-1),n.map(l=>r.get(l)||l)]}if(s==="call_indirect"&&i.length>=3){let n=i[1];if(typeof n=="string"&&r.has(n))return["call_indirect",r.get(n),...i.slice(2)]}}),t},ii=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=Te(i,new Set([s]));e.has(n)?r.set(s,e.get(n)):e.set(n,s)}if(r.size===0)return t;for(let i=t.length-1;i>=0;i--){let s=t[i];if(Array.isArray(s)&&s[0]==="type"){let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;n&&r.has(n)&&t.splice(i,1)}}return U(t,i=>{if(!Array.isArray(i))return;let s=i[0];if(s==="func")for(let n=1;n<i.length;n++){let l=i[n];Array.isArray(l)&&l[0]==="type"&&typeof l[1]=="string"&&r.has(l[1])&&(i[n]=["type",r.get(l[1])])}if(s==="import")for(let n=1;n<i.length;n++){let l=i[n];if(Array.isArray(l))for(let a=1;a<l.length;a++){let o=l[a];Array.isArray(o)&&o[0]==="type"&&typeof o[1]=="string"&&r.has(o[1])&&(l[a]=["type",r.get(o[1])])}}if(s==="call_indirect"||s==="return_call_indirect"){if(typeof i[1]=="string"&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&r.has(i[1][1]))return[s,["type",r.get(i[1][1])],...i.slice(2)]}}),t},qt=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let i=0;i<e.length;i++)if(e[i]==="\\"){let s=e[++i];s==="x"||s==="X"?(r.push(parseInt(e.slice(i+1,i+3),16)),i+=2):/[0-9a-fA-F]/.test(s)&&/[0-9a-fA-F]/.test(e[i+1])?(r.push(parseInt(e.slice(i,i+2),16)),i++):s==="n"?r.push(10):s==="t"?r.push(9):s==="r"?r.push(13):s==="\\"?r.push(92):s==='"'?r.push(34):r.push(s.charCodeAt(0))}else r.push(e.charCodeAt(i));return new Uint8Array(r)},Ee=t=>{let e='"';for(let r=0;r<t.length;r++){let i=t[r];i>=32&&i<127&&i!==34&&i!==92?e+=String.fromCharCode(i):e+="\\"+i.toString(16).padStart(2,"0")}return e+'"'},si=t=>{let e=[];for(let i of t)if(typeof i=="string")e.push(...qt(i));else if(Array.isArray(i)&&i[0]==="i8")for(let s=1;s<i.length;s++)e.push(Number(i[s])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[Ee(new Uint8Array(e.slice(0,r)))]},ni=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let i=t[e][1];e++;let s=t[e];return Array.isArray(s)&&(s[0]==="i32.const"||s[0]==="i64.const")?{memidx:i,offset:Number(s[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},$e=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let i=e;i<t.length;i++){let s=t[i];if(typeof s=="string")r+=qt(s).length;else if(Array.isArray(s)&&s[0]==="i8")r+=s.length-1;else return null}return r},li=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let i=1;typeof e[i]=="string"&&e[i][0]==="$"&&i++,Array.isArray(e[i])&&e[i][0]==="memory"&&i++,Array.isArray(e[i])&&typeof e[i][0]=="string"&&!e[i][0].startsWith('"')&&i++;let s=t.slice(r),n=e.slice(i);if(s.length===1&&n.length===1&&typeof s[0]=="string"&&typeof n[0]=="string"){let l=qt(s[0]),a=qt(n[0]),o=new Uint8Array(l.length+a.length);return o.set(l),o.set(a,l.length),t.length=r,t.push(Ee(o)),!0}return t.length=r,t.push(...s,...n),!0},ai=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;for(let i of t){if(!Array.isArray(i)||i[0]!=="data")continue;let s=1;typeof i[1]=="string"&&i[1][0]==="$"&&(s=2),s<i.length&&Array.isArray(i[s])&&typeof i[s][0]=="string"&&!i[s][0].startsWith('"')&&s++;let n=i.slice(s);if(n.length===0)continue;let l=si(n);(l.length!==n.length||l.length>0&&l[0]!==n[0])&&(i.length=s,i.push(...l))}let e=[];for(let i=0;i<t.length;i++){let s=t[i];if(Array.isArray(s)&&s[0]==="data"){let n=ni(s);if(n){let l=$e(s);l!==null&&e.push({...n,node:s,index:i,len:l})}}}e.sort((i,s)=>{let n=String(i.memidx),l=String(s.memidx);return n!==l?n.localeCompare(l):i.offset-s.offset});let r=new Set;for(let i=0;i<e.length-1;i++){let s=e[i],n=e[i+1];r.has(s.index)||String(s.memidx)!==String(n.memidx)||s.offset+s.len===n.offset&&li(s.node,n.node)&&(r.add(n.index),s.len=$e(s.node))}return r.size>0&&(t=t.filter((i,s)=>!r.has(s))),t},Ie=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let i="",s=e++;do i=String.fromCharCode(97+s%26)+i,s=Math.floor(s/26)-1;while(s>=0);t.set(r,i||"a")}return t.get(r)}},fi=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=Ie(),r=Ie();for(let i of t)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+e(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+r(i[2].slice(1,-1))+'"'));return t},oi=t=>{let e=!0;return S(t,r=>{if(!e||!Array.isArray(r))return;let i=r[0];if(i==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((i==="call"||i==="return_call"||i==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="elem")for(let s of r){if(typeof s=="string"&&s[0]!=="$"&&/^\d/.test(s)){e=!1;break}if(Array.isArray(s)&&s[0]==="ref.func"&&(typeof s[1]!="string"||s[1][0]!=="$")){e=!1;break}}}),e},ci=t=>{if(!Array.isArray(t)||t[0]!=="module"||!oi(t))return t;let e=new Map;S(t,n=>{Array.isArray(n)&&(n[0]==="call"||n[0]==="return_call")&&e.set(n[1],(e.get(n[1])||0)+1)});let r=[],i=[],s=[];for(let n of t.slice(1)){if(!Array.isArray(n)){s.push(n);continue}n[0]==="import"?r.push(n):n[0]==="func"?i.push(n):s.push(n)}return i.sort((n,l)=>(e.get(l[1])||0)-(e.get(n[1])||0)),["module",...r,...i,...s]},Ft=[["stripmut",Jr,!0,"strip mut from never-written globals"],["globals",Xr,!0,"propagate immutable global constants"],["fold",vr,!0,"constant folding"],["identity",Ir,!0,"remove identity ops (x + 0 \u2192 x)"],["peephole",Gr,!0,"x-x\u21920, x&0\u21920, etc."],["strength",kr,!0,"strength reduction (x * 2 \u2192 x << 1)"],["branch",Mr,!0,"simplify constant branches"],["propagate",ze,!0,"forward-propagate single-use locals & tiny consts (never inflates)"],["inlineOnce",Dr,!0,"inline single-call functions into their lone caller (never duplicates)"],["inline",Lr,!1,"inline tiny functions \u2014 can duplicate bodies"],["offset",Zr,!0,"fold add+const into load/store offset"],["unbranch",Kr,!0,"remove redundant br at end of own block"],["loopify",Qr,!0,"collapse block+loop+brif while-idiom into loop+if"],["brif",ti,!0,"if-then-br \u2192 br_if"],["foldarms",ei,!1,"merge identical trailing if arms \u2014 can add block wrapper"],["deadcode",Br,!0,"eliminate dead code after unreachable/br/return"],["vacuum",Pr,!0,"remove nops, drop-of-pure, empty branches"],["mergeBlocks",Rr,!0,"unwrap `(block $L \u2026)` whose label is never targeted"],["coalesce",Wr,!0,"share local slots between same-type non-overlapping locals"],["locals",Nr,!0,"remove unused locals"],["dedupe",ri,!0,"eliminate duplicate functions"],["dedupTypes",ii,!0,"merge identical type definitions"],["packData",ai,!0,"trim trailing zeros, merge adjacent data segments"],["reorder",ci,!1,"put hot functions first \u2014 no AST reduction"],["treeshake",gr,!0,"remove unused funcs/globals/types/tables"],["minifyImports",fi,!1,"shorten import names \u2014 enable only when you control the host"]],Ci=Object.fromEntries(Ft.map(t=>[t[0],t[2]])),ui=t=>{if(t===!1)return{};if(t!==!0&&typeof t!="string"){let i={...t};for(let s of Ft)i[s[0]]===void 0&&(i[s[0]]=s[2]);return i}let e=typeof t=="string"?new Set(t.split(/\s+/).filter(Boolean)):null,r={};for(let i of Ft)r[i[0]]=e?e.has("all")||e.has(i[0]):i[2];return r};function Qt(t,e=!0){typeof t=="string"&&(t=et(t));let r=e===!0;e=ui(e);let i=e.log?(l,a)=>e.log(l,a):()=>{},s=e.verbose||e.log;t=G(t);let n=null;for(let l=0;l<3;l++){n=G(t);let a=de(t);for(let[u,p]of Ft)e[u]&&(t=p(t));e.propagate&&(e.inlineOnce||e.inline)&&(t=ze(t));let f=de(t)-a;if((s||f!==0)&&i(` round ${l+1}: ${f>0?"+":""}${f} bytes`,f),f>(r?0:16)){s&&i(` \u26A0 round ${l+1} inflated by ${f} bytes, reverting`,f),t=n;break}if(E(n,t))break}return t}var Ue="\uE000",yi=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t,s=xt(r);return s||(r==="local.get"&&e.locals?.[i[0]]?e.locals[i[0]]:r==="call"&&e.funcs?.[i[0]]?e.funcs[i[0]].result?.[0]:null)};function Jt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=Jt(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function pi(t,e){let r=[],i=new Map;return Jt(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let n=s[1];if(!i.has(n)){let a=[];for(let c=2;c<s.length;c++){let u=yi(s[c]);u&&a.push(u)}let o=r.length,f=n.name||`$fn${o}`;i.set(n,{idx:o,name:f.startsWith("$")?f:"$"+f,params:a,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function mi(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function te(t,e,r){let{parse:i,compile:s,optimize:n,polyfill:l}=t,a={};if(!Array.isArray(e)&&r.length&&typeof r[r.length-1]=="object"&&r[r.length-1]!==null&&!r[r.length-1].byteLength&&(a=r.pop()),Array.isArray(e)&&e.raw){let o=e[0];for(let g=0;g<r.length;g++)o+=Ue+e[g+1];let f=i(o),c=[],u=0;f=Jt(f,g=>{if(g===Ue){let m=r[u++];if(typeof m=="function")return c.push(m),m;if(typeof m=="string"&&(m[0]==="("||/^\s*\(/.test(m))){let _=i(m);return Array.isArray(_)&&Array.isArray(_[0])&&(_._splice=!0),_}return m?.byteLength!==void 0?[...m]:typeof m=="bigint"?m.toString():m}return g});let p=null;if(c.length){let g=pi(f,c);if(g.length){let m=mi(g);f[0]==="module"?f.splice(1,0,...m):typeof f[0]=="string"?f=[...m,f]:f.unshift(...m),p={env:{}};for(let _ of g)p.env[_.name.slice(1)]=_.fn}}a.polyfill&&(f=l(f,a.polyfill)),a.optimize&&(f=n(f,a.optimize));let y=s(f);return p&&(y._imports=p),y}if(a.polyfill||a.optimize){let o=typeof e=="string"?i(e):e;return a.polyfill&&(o=l(o,a.polyfill)),a.optimize&&(o=n(o,a.optimize)),s(o)}return s(e)}function qe(t,e,r){let i=te(t,e,r),s=new WebAssembly.Module(i);return new WebAssembly.Instance(s,i._imports).exports}var Fe={parse:et,compile:yt,optimize:Qt,polyfill:jt};function Xi(t,...e){return te(Fe,t,e)}function gi(t,...e){return qe(Fe,t,e)}var Zi=gi;export{Xi as compile,Zi as default,Qt as optimize,et as parse,jt as polyfill,_e as print,gi as watr};
6
+ `?f+="":(m&&m!==")"&&m!==" "||i||m===")")&&(f+=" "),f+=g,c=!1}}return u?`(${f.replaceAll(i+p+"("," (")})`:`(${f+i+r.repeat(o)})`}}var de=(t,e)=>{let r=[],i=t[0]==="module"?1:0;for(let s=i;s<t.length;s++)Array.isArray(t[s])&&t[s][0]===e&&r.push({node:t[s],idx:s});return r},St=(t,e,r)=>t.splice(e,0,r),ir=0,rt=t=>`$__${t}${ir++}`,sr=(t,e)=>{let r=new Set;if(S(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let i=rt("fntbl"),s=[...r],n=Object.fromEntries(s.map((f,c)=>[f,c])),l=de(t,"func"),a=l.length?l[0].idx:t[0]==="module"?1:0;St(t,a,["table",i,"funcref",["elem",...s]]);let o={};return S(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let u=[],p=[];for(let y of f){if(Array.isArray(y)&&y[0]==="param")for(let g=1;g<y.length;g++)y[g][0]!=="$"&&u.push(y[g]);if(Array.isArray(y)&&y[0]==="result")for(let g=1;g<y.length;g++)p.push(y[g])}o[c]={params:u,results:p}}),U(t,(f,c,u)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&n[f[1]]!==void 0&&(c[u]=["i32.const",n[f[1]]]),f[0]==="call_ref"){let p=f[1],y=f.slice(2);c[u]=["call_indirect",i,["type",p],...y]}if(f[0]==="return_call_ref"){let p=f[1],y=f.slice(2);c[u]=["return_call_indirect",i,["type",p],...y]}}}),t},nr={"i32.extend8_s":["i32",24],"i32.extend16_s":["i32",16],"i64.extend8_s":["i64",56n],"i64.extend16_s":["i64",48n],"i64.extend32_s":["i64",32n]},lr=(t,e)=>(U(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=nr[r[0]];if(!n)return;let[l,a]=n,o=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...o,[`${l}.const`,a]],[`${l}.const`,a]]}),t),xe={"i32.trunc_sat_f32_s":{itype:"i32",ftype:"f32",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f32_u":{itype:"i32",ftype:"f32",signed:!1,min:0,max:4294967295},"i32.trunc_sat_f64_s":{itype:"i32",ftype:"f64",signed:!0,min:-2147483648,max:2147483647},"i32.trunc_sat_f64_u":{itype:"i32",ftype:"f64",signed:!1,min:0,max:4294967295},"i64.trunc_sat_f32_s":{itype:"i64",ftype:"f32",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f32_u":{itype:"i64",ftype:"f32",signed:!1,min:0n,max:18446744073709551615n},"i64.trunc_sat_f64_s":{itype:"i64",ftype:"f64",signed:!0,min:-9223372036854775808n,max:9223372036854775807n},"i64.trunc_sat_f64_u":{itype:"i64",ftype:"f64",signed:!1,min:0n,max:18446744073709551615n}},ar=(t,e)=>{let r=new Set;if(S(t,s=>{Array.isArray(s)&&xe[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:a,min:o,max:f}=xe[s],c=rt(`trunc_${n}_${l}_${a?"s":"u"}`);i[s]=c;let u=`${n}.trunc_${l}_${a?"s":"u"}`,p=n==="i64"?0n:0,y=["func",c,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,p]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${n}.const`,o]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${n}.const`,f]],["else",[u,["local.get","$v"]]]]]]]]];t.push(y)}return U(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t},fr=(t,e)=>{let r=new Set,i=new Set;S(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,o=typeof l[2]=="number"?l[2]:0;r.add(`${a}_${o}`)}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0;i.add(a)}}});let s={},n={};for(let l of r){let[a,o]=l.split("_").map(Number),f=rt(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=f;let c=a?["i32.store8",a]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...u,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let l of i){let a=rt(`memset${l===0?"":"_"+l}`);n[l]=a;let o=l?["i32.store8",l]:["i32.store8"];t.push(["func",a,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return U(t,(l,a,o)=>{if(!(!Array.isArray(l)||!a)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0,u=l.filter(p=>Array.isArray(p)||typeof p=="string"&&p[0]==="$");a[o]=["call",s[`${f}_${c}`],...u]}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0,c=l.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[o]=["call",n[f],...c]}}}),t},or=(t,e)=>{let r=!1;return S(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&U(t,(i,s,n)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[n]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[n]=["return",["call_indirect",...i.slice(1)]]))}),t},cr=(t,e)=>(U(t,(r,i,s)=>{if(!(!Array.isArray(r)||!i)&&(r[0]==="ref.i31"&&(i[s]=["i32.and",...r.slice(1),["i32.const",2147483647]]),r[0]==="i31.get_u"&&(i[s]=r.length>1?r[1]:["drop"]),r[0]==="i31.get_s")){let n=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...n,["i32.const",1]],["i32.const",1]]}}),t),ur=(t,e)=>{let r={};S(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l=s.length-1;l>=0;l--){let a=s[l];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[n]={type:a[0].split(".")[0],value:a[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let n=s[0];if(n==="global.get"&&r[s[1]]){let l=r[s[1]];return[`${l.type}.const`,l.value]}if(n==="i32.add"||n==="i64.add"){let l=i(s[1]),a=i(s[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),a=i(s[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),a=i(s[2]);if(l&&a&&l[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=n.split(".")[0],f=o==="i64"?BigInt(l[1]):Number(l[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}return s};return U(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let a=2;a<s.length;a++)if(Array.isArray(s[a])){let o=i(s[a]);o!==s[a]&&(s[a]=o)}}}),t},yr=(t,e)=>{let r=new Map,i=[];if(S(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let c of a)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)f.push(c[u]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let s=Math.max(...[...r.values()].map(a=>a.length)),n={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(n[c]||(n[c]=[]),n[c].length<f){let u=rt(`ret_${c}_${n[c].length}`);n[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let a of i.reverse())St(t,l,a);return U(t,(a,o,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let p=0;p<a.length;p++)if(Array.isArray(a[p])&&a[p][0]==="result"){a[p]=["result",u[0]];break}}),t},dt={i32:4,i64:8,f32:4,f64:8},pr=(t,e)=>{let r=new Map,i=new Map,s=1;if(S(t,m=>{if(!Array.isArray(m)||m[0]!=="type")return;let _=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;if(_){for(let b of m)if(Array.isArray(b)){if(b[0]==="struct"){let v=[];for(let A of b)if(Array.isArray(A)&&A[0]==="field"){let z=typeof A[1]=="string"&&A[1][0]==="$"?A[1]:null,I=z?A[2]:A[1],M=Array.isArray(I)&&I[0]==="mut"?I[1]:I;v.push({name:z,type:M})}r.set(_,{kind:"struct",fields:v}),i.set(_,s++)}if(b[0]==="array"){let v=b[1],A=Array.isArray(v)&&v[0]==="mut"?v[1]:v;r.set(_,{kind:"array",elemType:A}),i.set(_,s++)}}}}),!r.size)return t;let n=de(t,"memory").length>0,l=rt("alloc"),a=rt("heap_ptr"),o=t[0]==="module"?1:0;n||St(t,o,["memory",1]),St(t,o+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",a]],["global.set",a,["i32.add",["global.get",a],["local.get","$size"]]],["local.get","$ptr"]];t.push(f);let c=m=>{let _=4;for(let b of m.fields)_+=dt[b.type]||4;return _},u=(m,_)=>{let b=4;for(let v=0;v<_;v++)b+=dt[m.fields[v].type]||4;return b},p=(m,_)=>{for(let b=0;b<m.fields.length;b++)if(m.fields[b].name===_)return b;return-1},y=0,g=()=>`$__gc_tmp${y++}`;return S(t,m=>{if(!Array.isArray(m)||m[0]!=="func")return;let _=!1,b=!1,v=!1,A=!1;if(S(m,I=>{Array.isArray(I)&&((I[0]==="struct.new"||I[0]==="struct.new_default")&&(_=!0),(I[0]==="array.new"||I[0]==="array.new_default")&&(b=!0,v=!0,A=!0))}),!_&&!b)return;let z=1;for(let I=1;I<m.length;I++){let M=m[I];if(Array.isArray(M)&&(M[0]==="param"||M[0]==="result"||M[0]==="local"||M[0]==="export"||M[0]==="type"))z=I+1;else if(typeof M=="string"&&M[0]==="$")z=I+1;else if(!Array.isArray(M))z=I+1;else break}_&&m.splice(z++,0,["local","$__gc_ptr","i32"]),b&&m.splice(z++,0,["local","$__gc_aptr","i32"]),v&&m.splice(z++,0,["local","$__gc_alen","i32"]),A&&m.splice(z++,0,["local","$__gc_aidx","i32"])}),U(t,(m,_,b)=>{if(!(!Array.isArray(m)||!_)){if(m[0]==="struct.new"||m[0]==="struct.new_default"){let v=m[1],A=r.get(v);if(!A||A.kind!=="struct")return;let z=c(A),I=i.get(v),M=m.slice(2),C="$__gc_ptr",O=[["local.set",C,["call",l,["i32.const",z]]],["i32.store",["local.get",C],["i32.const",I]]];if(m[0]==="struct.new")for(let q=0;q<A.fields.length;q++){let x=A.fields[q],d=u(A,q),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store";O.push([k,["i32.add",["local.get",C],["i32.const",d]],M[q]||[`${x.type}.const`,0]])}else for(let q=0;q<A.fields.length;q++){let x=A.fields[q],d=u(A,q),k=x.type==="i64"?"i64.store":x.type==="f32"?"f32.store":x.type==="f64"?"f64.store":"i32.store",D=x.type==="i64"?["i64.const",0n]:x.type==="f32"?["f32.const",0]:x.type==="f64"?["f64.const",0]:["i32.const",0];O.push([k,["i32.add",["local.get",C],["i32.const",d]],D])}O.push(["local.get",C]),_[b]=["block",["result","i32"],...O]}if(m[0]==="struct.get"){let v=m[1],A=m[2],z=m[3],I=r.get(v);if(!I||I.kind!=="struct")return;let M=typeof A=="string"&&A[0]==="$"?p(I,A):parseInt(A);if(M<0)return;let C=I.fields[M],O=u(I,M),q=C.type==="i64"?"i64.load":C.type==="f32"?"f32.load":C.type==="f64"?"f64.load":"i32.load";_[b]=[q,["i32.add",z,["i32.const",O]]]}if(m[0]==="struct.set"){let v=m[1],A=m[2],z=m[3],I=m[4],M=r.get(v);if(!M||M.kind!=="struct")return;let C=typeof A=="string"&&A[0]==="$"?p(M,A):parseInt(A);if(C<0)return;let O=M.fields[C],q=u(M,C),x=O.type==="i64"?"i64.store":O.type==="f32"?"f32.store":O.type==="f64"?"f64.store":"i32.store";_[b]=[x,["i32.add",z,["i32.const",q]],I]}if(m[0]==="array.new"||m[0]==="array.new_default"){let v=m[1],A=r.get(v);if(!A||A.kind!=="array")return;let z=i.get(v),I=dt[A.elemType]||4,M=m[0]==="array.new"?m[2]:null,C=m[0]==="array.new"?m[3]:m[2],O="$__gc_aptr",q="$__gc_alen",x="$__gc_aidx",d=A.elemType==="i64"?"i64.store":A.elemType==="f32"?"f32.store":A.elemType==="f64"?"f64.store":"i32.store",k=[["local.set",q,C],["local.set",O,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",q],["i32.const",I]]]]],["i32.store",["local.get",O],["i32.const",z]],["i32.store",["i32.add",["local.get",O],["i32.const",4]],["local.get",q]]];M&&k.push(["local.set",x,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",x],["local.get",q]]],[d,["i32.add",["i32.add",["local.get",O],["i32.const",8]],["i32.mul",["local.get",x],["i32.const",I]]],M],["local.set",x,["i32.add",["local.get",x],["i32.const",1]]],["br","$loop"]]]),k.push(["local.get",O]),_[b]=["block",["result","i32"],...k]}if(m[0]==="array.get"){let v=m[1],A=m[2],z=m[3],I=r.get(v);if(!I||I.kind!=="array")return;let M=dt[I.elemType]||4,C=I.elemType==="i64"?"i64.load":I.elemType==="f32"?"f32.load":I.elemType==="f64"?"f64.load":"i32.load";_[b]=[C,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",z,["i32.const",M]]]]}if(m[0]==="array.set"){let v=m[1],A=m[2],z=m[3],I=m[4],M=r.get(v);if(!M||M.kind!=="array")return;let C=dt[M.elemType]||4,O=M.elemType==="i64"?"i64.store":M.elemType==="f32"?"f32.store":M.elemType==="f64"?"f64.store":"i32.store";_[b]=[O,["i32.add",["i32.add",A,["i32.const",8]],["i32.mul",z,["i32.const",C]]],I]}if(m[0]==="array.len"){let v=m[1];_[b]=["i32.load",["i32.add",v,["i32.const",4]]]}}}),t},mr=(t,e)=>{let r=new Map,i=1;return S(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(n)for(let l of s)Array.isArray(l)&&(l[0]==="struct"||l[0]==="array")&&r.set(n,i++)}),r.size&&U(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let a=s[1],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=s[2],c=r.get(o);c!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(s[0]==="ref.cast"){let a=s[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=s[2],u=r.get(o);if(u!==void 0){let p=rt("cast");f?n[l]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["if",["i32.and",["i32.ne",["local.get",p],["i32.const",0]],["i32.ne",["i32.load",["local.get",p]],["i32.const",u]]],["then",["unreachable"]]],["local.get",p]]:n[l]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["if",["i32.or",["i32.eqz",["local.get",p]],["i32.ne",["i32.load",["local.get",p]],["i32.const",u]]],["then",["unreachable"]]],["local.get",p]]}}if(s[0]==="br_on_cast"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let p=r.get(u);if(p!==void 0){let y=rt("brcast");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",a,["i32.and",["i32.ne",["local.get",y],["i32.const",0]],["i32.eq",["i32.load",["local.get",y]],["i32.const",p]]]],["local.get",y]]}}if(s[0]==="br_on_cast_fail"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let p=r.get(u);if(p!==void 0){let y=rt("brfail");n[l]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["br_if",a,["i32.or",["i32.eqz",["local.get",y]],["i32.ne",["i32.load",["local.get",y]],["i32.const",p]]]],["local.get",y]]}}}}),t},zt=[["funcref",["ref.func","call_ref","return_call_ref"],sr],["sign_ext",["i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s"],lr],["nontrapping",["i32.trunc_sat_f32_s","i32.trunc_sat_f32_u","i32.trunc_sat_f64_s","i32.trunc_sat_f64_u","i64.trunc_sat_f32_s","i64.trunc_sat_f32_u","i64.trunc_sat_f64_s","i64.trunc_sat_f64_u"],ar],["bulk_memory",["memory.copy","memory.fill"],fr],["return_call",["return_call","return_call_indirect"],or],["i31ref",["ref.i31","i31.get_s","i31.get_u"],cr],["extended_const",["global.get"],ur],["multi_value",[],yr],["gc",["struct.new","struct.get","struct.set","array.new","array.get","array.set","array.len","struct.new_default","array.new_default","array.new_fixed","array.copy"],pr],["ref_cast",["ref.test","ref.cast","br_on_cast","br_on_cast_fail"],mr]],Ui=Object.fromEntries(zt.map(t=>[t[0],t[1]])),gr=t=>{if(t===!1)return{};if(t!==!0&&typeof t!="string")return{...t};let e=typeof t=="string"?new Set(t.split(/\s+/).filter(Boolean)):null,r={};for(let i of zt)r[i[0]]=e?e.has("all")||e.has(i[0]):!0;return r},_r=t=>{let e=new Set;return S(t,r=>{if(typeof r=="string")for(let i of zt)i[1].some(n=>r===n||r.startsWith(n+" "))&&e.add(i[0])}),S(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&S(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),S(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e};function Gt(t,e=!0){typeof t=="string"&&(t=et(t)),t=G(t),e=gr(e);let r=_r(t),i={uid:0};for(let s of zt){let n=s[2];r.has(s[0])&&e[s[0]]!==!1&&(t=n(t,i))}return t}var Ae=t=>{try{return yt(t).length}catch{return 1/0}},T=(t,e)=>{if(t===e)return!0;if(typeof t!=typeof e)return!1;if(typeof t=="bigint")return t===e;if(!Array.isArray(t)||!Array.isArray(e)||t.length!==e.length)return!1;for(let r=0;r<t.length;r++)if(!T(t[r],e[r]))return!1;return!0},Ct=t=>{let e=1;for(;e<t.length;){let s=t[e];if(Array.isArray(s)&&(s[0]==="then"||s[0]==="else"||s[0]==="result"||s[0]==="param")){e++;continue}break}let r=null,i=null;for(let s=e+1;s<t.length;s++){let n=t[s];Array.isArray(n)&&(n[0]==="then"?r=n:n[0]==="else"&&(i=n))}return{condIdx:e,cond:t[e],thenBranch:r,elseBranch:i}},hr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,n=new Map,l=new Map,a=(x,d,k,D=!1)=>{let Q=typeof d[1]=="string"&&d[1][0]==="$",w=Q?d[1]:k,N=!D&&d.some(J=>Array.isArray(J)&&J[0]==="export"),F={node:d,idx:k,used:N,isImport:D};return x.set(w,F),Q&&x.set(k,F),l.set(d,F),F},o=0,f=0,c=0,u=0,p=0,y=[],g=[],m=[],_=[];for(let x of t.slice(1)){if(!Array.isArray(x))continue;let d=x[0];if(d==="type")a(i,x,c++);else if(d==="func")a(e,x,o++);else if(d==="global")a(r,x,f++);else if(d==="table")a(s,x,u++);else if(d==="memory")a(n,x,p++);else if(d==="import")for(let k of x)Array.isArray(k)&&(k[0]==="func"?a(e,k,o++,!0):k[0]==="global"?a(r,k,f++,!0):k[0]==="table"?a(s,k,u++,!0):k[0]==="memory"&&a(n,k,p++,!0));else d==="export"?m.push(x):d==="start"?_.push(x):d==="elem"?y.push(x):d==="data"&&g.push(x)}let b=[],v=x=>{x&&!x.scanned&&b.push(x)},A=x=>{let d=e.get(x);d&&(d.used||(d.used=!0),v(d))},z=x=>{let d=r.get(x);d&&(d.used=!0)},I=x=>{let d=s.get(x);d&&(d.used=!0)},M=x=>{typeof x=="string"&&x[0]!=="$"&&(x=+x);let d=n.get(x);d&&(d.used=!0)},C=x=>{let d=i.get(x);d&&(d.used=!0)};for(let x of m)for(let d of x){if(!Array.isArray(d))continue;let[k,D]=d;k==="func"?A(D):k==="global"?z(D):k==="table"?I(D):k==="memory"&&M(D)}for(let x of _){let d=x[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),A(d)}for(let x of y)S(x,d=>{Array.isArray(d)&&d[0]==="ref.func"?A(d[1]):typeof d=="string"&&d[0]==="$"&&A(d)});for(let x of g){let d=x[1];Array.isArray(d)&&d[0]==="memory"?M(d[1]):typeof d=="string"&&d[0]==="$"?M(d):Array.isArray(d)&&M(0)}for(let x of[e,r,s,n])for(let d of x.values())d.used&&v(d);if(!(m.length>0||_.length>0||y.length>0||b.length>0)){for(let x of[e,r,s,n])for(let d of x.values())d.used=!0;return t}for(;b.length;){let x=b.pop();x.scanned||(x.scanned=!0,!x.isImport&&S(x.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&A(d);return}let[k,D]=d;if(k==="call"||k==="return_call"||k==="ref.func")A(D);else if(k==="global.get"||k==="global.set")z(D);else if(k==="type")C(D);else if(k==="call_indirect"||k==="return_call_indirect")for(let Q of d)typeof Q=="string"&&Q[0]==="$"&&I(Q);typeof k=="string"&&(k.startsWith("memory.")||k.includes(".load")||k.includes(".store"))&&M(0)}))}let q=["module"];for(let x of t.slice(1)){if(!Array.isArray(x)){q.push(x);continue}let d=x[0];if(d==="func"||d==="global"||d==="type")l.get(x)?.used&&q.push(x);else if(d==="import"){let k=!1;for(let D of x){if(!Array.isArray(D))continue;if(l.get(D)?.used){k=!0;break}}k&&q.push(x)}else q.push(x)}return q},be=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),Me=new ArrayBuffer(8),Yt=new Float64Array(Me),Xt=new BigInt64Array(Me),Be=new ArrayBuffer(4),Zt=new Float32Array(Be),Kt=new Int32Array(Be),xr=t=>(Yt[0]=t,Xt[0]),dr=t=>(Xt[0]=BigInt.asIntN(64,t),Yt[0]),Ar=t=>(Zt[0]=t,Kt[0]),br=t=>(Kt[0]=t|0,Zt[0]),pt=t=>(e,r)=>t(e,r)?1:0,Tt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,mt=t=>(e,r)=>t(e,r)?1:0,Et=t=>(e,r)=>t(BigInt.asUintN(64,e),BigInt.asUintN(64,r))?1:0,wr={"i32.add":(t,e)=>t+e|0,"i32.sub":(t,e)=>t-e|0,"i32.mul":(t,e)=>Math.imul(t,e),"i32.div_s":(t,e)=>e!==0?t/e|0:null,"i32.div_u":(t,e)=>e!==0?(t>>>0)/(e>>>0)|0:null,"i32.rem_s":(t,e)=>e!==0?t%e|0:null,"i32.rem_u":(t,e)=>e!==0?(t>>>0)%(e>>>0)|0:null,"i32.and":(t,e)=>t&e,"i32.or":(t,e)=>t|e,"i32.xor":(t,e)=>t^e,"i32.shl":(t,e)=>t<<(e&31),"i32.shr_s":(t,e)=>t>>(e&31),"i32.shr_u":(t,e)=>t>>>(e&31),"i32.rotl":(t,e)=>(e&=31,t<<e|t>>>32-e|0),"i32.rotr":(t,e)=>(e&=31,t>>>e|t<<32-e|0),"i32.eq":pt((t,e)=>t===e),"i32.ne":pt((t,e)=>t!==e),"i32.lt_s":pt((t,e)=>t<e),"i32.lt_u":Tt((t,e)=>t<e),"i32.gt_s":pt((t,e)=>t>e),"i32.gt_u":Tt((t,e)=>t>e),"i32.le_s":pt((t,e)=>t<=e),"i32.le_u":Tt((t,e)=>t<=e),"i32.ge_s":pt((t,e)=>t>=e),"i32.ge_u":Tt((t,e)=>t>=e),"i32.eqz":t=>t===0?1:0,"i32.clz":t=>Math.clz32(t),"i32.ctz":t=>t===0?32:31-Math.clz32(t&-t),"i32.popcnt":t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32.wrap_i64":t=>Number(BigInt.asIntN(32,t)),"i32.extend8_s":t=>t<<24>>24,"i32.extend16_s":t=>t<<16>>16,"i64.add":(t,e)=>BigInt.asIntN(64,t+e),"i64.sub":(t,e)=>BigInt.asIntN(64,t-e),"i64.mul":(t,e)=>BigInt.asIntN(64,t*e),"i64.div_s":(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64.div_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64.rem_s":(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64.rem_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64.and":(t,e)=>BigInt.asIntN(64,t&e),"i64.or":(t,e)=>BigInt.asIntN(64,t|e),"i64.xor":(t,e)=>BigInt.asIntN(64,t^e),"i64.shl":(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64.shr_s":(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64.shr_u":(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64.eq":mt((t,e)=>t===e),"i64.ne":mt((t,e)=>t!==e),"i64.lt_s":mt((t,e)=>t<e),"i64.lt_u":Et((t,e)=>t<e),"i64.gt_s":mt((t,e)=>t>e),"i64.gt_u":Et((t,e)=>t>e),"i64.le_s":mt((t,e)=>t<=e),"i64.le_u":Et((t,e)=>t<=e),"i64.ge_s":mt((t,e)=>t>=e),"i64.ge_u":Et((t,e)=>t>=e),"i64.eqz":t=>t===0n?1:0,"i64.extend_i32_s":t=>BigInt(t),"i64.extend_i32_u":t=>BigInt(t>>>0),"i64.extend8_s":t=>BigInt.asIntN(64,BigInt.asIntN(8,t)),"i64.extend16_s":t=>BigInt.asIntN(64,BigInt.asIntN(16,t)),"i64.extend32_s":t=>BigInt.asIntN(64,BigInt.asIntN(32,t)),"f32.add":(t,e)=>Math.fround(t+e),"f32.sub":(t,e)=>Math.fround(t-e),"f32.mul":(t,e)=>Math.fround(t*e),"f32.div":(t,e)=>Math.fround(t/e),"f32.neg":t=>Math.fround(-t),"f32.abs":t=>Math.fround(Math.abs(t)),"f32.sqrt":t=>Math.fround(Math.sqrt(t)),"f32.ceil":t=>Math.fround(Math.ceil(t)),"f32.floor":t=>Math.fround(Math.floor(t)),"f32.trunc":t=>Math.fround(Math.trunc(t)),"f32.nearest":t=>Math.fround(be(t)),"f64.add":(t,e)=>t+e,"f64.sub":(t,e)=>t-e,"f64.mul":(t,e)=>t*e,"f64.div":(t,e)=>t/e,"f64.neg":t=>-t,"f64.abs":Math.abs,"f64.sqrt":Math.sqrt,"f64.ceil":Math.ceil,"f64.floor":Math.floor,"f64.trunc":Math.trunc,"f64.nearest":be,"i32.reinterpret_f32":Ar,"f32.reinterpret_i32":br,"i64.reinterpret_f64":xr,"f64.reinterpret_i64":dr,"f32.convert_i32_s":t=>Math.fround(t|0),"f32.convert_i32_u":t=>Math.fround(t>>>0),"f32.convert_i64_s":t=>Math.fround(Number(BigInt.asIntN(64,t))),"f32.convert_i64_u":t=>Math.fround(Number(BigInt.asUintN(64,t))),"f64.convert_i32_s":t=>t|0,"f64.convert_i32_u":t=>t>>>0,"f64.convert_i64_s":t=>Number(BigInt.asIntN(64,t)),"f64.convert_i64_u":t=>Number(BigInt.asUintN(64,t)),"f32.demote_f64":t=>Math.fround(t),"f64.promote_f32":t=>Math.fround(t)},vr=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n;return Xt[0]=BigInt.asIntN(64,i|0x7ff0000000000000n|(t[0]==="-"?1n<<63n:0n)),Yt[0]},$r=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),i=t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?parseInt(r):4194304;return Kt[0]=i|2139095040|(t[0]==="-"?2147483648:0)|0,Zt[0]},E=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;if(e==="i32.const")return{type:"i32",value:(typeof r=="string"?P.parse(r):r)|0};if(e==="i64.const")return{type:"i64",value:typeof r=="string"?nt.parse(r):BigInt(r)};if(e==="f32.const"){let i=$r(r);return{type:"f32",value:i!==null?i:Math.fround(Number(r))}}if(e==="f64.const"){let i=vr(r);return{type:"f64",value:i!==null?i:Number(r)}}return null},we=(t,e)=>t==="i32"?["i32.const",e|0]:t==="i64"?["i64.const",e]:t==="f32"?["f32.const",Math.fround(e)]:t==="f64"?["f64.const",e]:null,Ir=t=>U(t,e=>{if(!Array.isArray(e))return;let r=wr[e[0]];if(r){if(r.length===1&&e.length===2){let i=E(e[1]);if(!i)return;let s=r(i.value);return s===null?void 0:we(xt(e[0]),s)}if(r.length===2&&e.length===3){let i=E(e[1]),s=E(e[2]);if(!i||!s)return;let n=r(i.value,s.value);return n===null?void 0:we(xt(e[0]),n)}}}),it=t=>(e,r)=>{let i=E(e),s=E(r);return i?.value===t?r:s?.value===t?e:null},K=t=>(e,r)=>E(r)?.value===t?e:null,kr={"i32.add":it(0),"i64.add":it(0n),"i32.sub":K(0),"i64.sub":K(0n),"i32.mul":it(1),"i64.mul":it(1n),"i32.div_s":K(1),"i32.div_u":K(1),"i64.div_s":K(1n),"i64.div_u":K(1n),"i32.and":it(-1),"i64.and":it(-1n),"i32.or":it(0),"i64.or":it(0n),"i32.xor":it(0),"i64.xor":it(0n),"i32.shl":K(0),"i32.shr_s":K(0),"i32.shr_u":K(0),"i64.shl":K(0n),"i64.shr_s":K(0n),"i64.shr_u":K(0n)},Mr=t=>U(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=kr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Br=t=>U(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=E(s);if(n&&n.value>0&&!(n.value&n.value-1)){let a=Math.log2(n.value);if(Number.isInteger(a))return["i32.shl",i,["i32.const",a]]}let l=E(i);if(l&&l.value>0&&!(l.value&l.value-1)){let a=Math.log2(l.value);if(Number.isInteger(a))return["i32.shl",s,["i32.const",a]]}}if(r==="i64.mul"){let n=E(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let a=BigInt(n.value.toString(2).length-1);return["i64.shl",i,["i64.const",a]]}let l=E(i);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let a=BigInt(l.value.toString(2).length-1);return["i64.shl",s,["i64.const",a]]}}if(r==="i32.div_u"){let n=E(s);if(n&&n.value>0&&!(n.value&n.value-1)){let l=Math.log2(n.value);if(Number.isInteger(l))return["i32.shr_u",i,["i32.const",l]]}}if(r==="i64.div_u"){let n=E(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let l=BigInt(n.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",l]]}}if(r==="i32.rem_u"){let n=E(s);if(n&&n.value>0&&!(n.value&n.value-1))return["i32.and",i,["i32.const",n.value-1]]}if(r==="i64.rem_u"){let n=E(s);if(n&&n.value>0n&&(n.value&n.value-1n)===0n)return["i64.and",i,["i64.const",n.value-1n]]}}),Nr=t=>U(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ct(e),l=E(i);if(!l)return;let a=l.value!==0&&l.value!==0n?s:n;if(a&&a.length>1){let o=a.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=E(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=E(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),ve=new Set(["unreachable","return","br","br_table"]),Sr=t=>(S(t,e=>{if(!Array.isArray(e))return;let r=e[0];if((r==="func"||r==="block"||r==="loop")&&$e(e),r==="if")for(let i=1;i<e.length;i++)Array.isArray(e[i])&&(e[i][0]==="then"||e[i][0]==="else")&&$e(e[i])}),t),$e=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let n=s[0];if(n==="param"||n==="result"||n==="local"||n==="type"||n==="export")continue;e&&r===-1&&(r=i),ve.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),ve.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},zr=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=[],i=new Map,s=new Set;for(let n=1;n<e.length;n++){let l=e[n];Array.isArray(l)&&(l[0]==="local"&&(r.push({node:l,idx:n}),typeof l[1]=="string"&&l[1][0]==="$"&&i.set(l[1],l[2])),l[0]==="param"&&typeof l[1]=="string"&&l[1][0]==="$"&&(i.set(l[1],l[2]),s.add(l[1])))}S(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let a=n[1];typeof a=="string"&&s.add(a)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:a}=r[n],o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;o&&!s.has(o)&&e.splice(l,1)}}),t),Tr=new Set(["call","call_indirect","return_call","return_call_indirect","table.set","table.grow","table.fill","table.copy","table.init","struct.set","struct.new","array.set","array.new","array.new_fixed","array.new_data","array.new_elem","array.init_data","array.init_elem","ref.i31","global.set","local.set","local.tee","unreachable","return","br","br_if","br_table","br_on_null","br_on_non_null","br_on_cast","br_on_cast_fail","throw","rethrow","throw_ref","try_table","data.drop","elem.drop"]),Er=[".store","memory.",".atomic."],gt=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||Tr.has(e))return!1;for(let r of Er)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!gt(t[r]))return!1;return!0},Ur=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return S(t,i=>{!Array.isArray(i)||i.length<2||typeof i[1]!="string"||(i[0]==="local.get"?r(i[1]).gets++:i[0]==="local.set"?r(i[1]).sets++:i[0]==="local.tee"&&r(i[1]).tees++)}),e},qr=t=>{let e=E(t);if(!e)return!1;if(e.type==="i32"){let r=e.value|0;return r>=-64&&r<=63}if(e.type==="i64"){let r=typeof e.value=="bigint"?e.value:BigInt(e.value);return r>=-64n&&r<=63n}return!1},Ne=t=>t.pure&&t.singleUse||qr(t.val),Ut=(t,e)=>{for(let[r,i]of t){let s=!1;S(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},Se=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.includes(".load")||e==="memory.copy"||e==="memory.size"))return!0;for(let r=1;r<t.length;r++)if(Se(t[r]))return!0;return!1},ze=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e==="global.get"||e==="table.get"||e==="table.size"||e==="call"||e==="call_indirect"||e==="return_call"||e==="return_call_indirect"||e.includes(".load")||e==="memory.copy"||e==="memory.size"))return!0;for(let r=1;r<t.length;r++)if(ze(t[r]))return!0;return!1},Ht=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(typeof e=="string"&&(e.endsWith(".store")||e==="memory.copy"||e==="memory.fill"||e==="memory.init"||e.includes(".atomic.")&&!e.endsWith(".load")))return!0;for(let r=1;r<t.length;r++)if(Ht(t[r]))return!0;return!1},Vt=(t,e)=>{if(!Array.isArray(t))return t;let r=t[0];if(r==="local.get"&&t.length===2){let s=typeof t[1]=="string"&&e.get(t[1]);return s&&Ne(s)?G(s.val):t}let i=e;if(r==="block"||r==="loop"||r==="if"){let s=null;S(t,n=>{Array.isArray(n)&&(n[0]==="local.set"||n[0]==="local.tee")&&typeof n[1]=="string"&&e.has(n[1])&&(s||(s=new Map(e)),s.delete(n[1]))}),s&&(i=s)}for(let s=1;s<t.length;s++){let n=Vt(t[s],i);n!==t[s]&&(t[s]=n),s+1<t.length&&Array.isArray(t[s])&&S(t[s],l=>{Array.isArray(l)&&(l[0]==="local.set"||l[0]==="local.tee")&&typeof l[1]=="string"&&(i===e&&(i=new Map(e)),i.delete(l[1]),Ut(i,l[1]))})}return t},Fr=(t,e,r)=>{let i=!1,s=l=>r.get(l)||{gets:0,sets:0,tees:0},n=new Map;for(let l=1;l<t.length;l++){let a=t[l];if(!Array.isArray(a))continue;let o=a[0];if(!(o==="param"||o==="result"||o==="local"||o==="type"||o==="export")){if((o==="local.set"||o==="local.tee")&&a.length===3&&typeof a[1]=="string"){let f=Vt(a[2],n);f!==a[2]&&(a[2]=f,i=!0),S(a[2],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&typeof u[1]=="string"&&(n.delete(u[1]),Ut(n,u[1]))});let c=s(a[1]);if(Ut(n,a[1]),Ht(a[2]))for(let[u,p]of n)p.readsMem&&n.delete(u);n.set(a[1],{val:a[2],pure:gt(a[2]),readsMem:Se(a[2]),singleUse:c.gets<=1&&c.sets<=1&&c.tees===0});continue}if((o==="block"||o==="loop"||o==="if")&&n.clear(),o==="call"||o==="call_indirect"||o==="return_call"||o==="return_call_indirect")for(let[f,c]of n)ze(c.val)&&n.delete(f);if(o==="local.get"&&a.length===2&&typeof a[1]=="string"){let f=n.get(a[1]);if(f&&Ne(f)){let c=G(f.val);a.length=0,a.push(...Array.isArray(c)?c:[c]),i=!0;continue}}if(o!=="block"&&o!=="loop"&&o!=="if"){let f=G(a);if(Vt(a,n),T(f,a)||(i=!0),S(a,c=>{Array.isArray(c)&&(c[0]==="local.set"||c[0]==="local.tee")&&typeof c[1]=="string"&&(n.delete(c[1]),Ut(n,c[1]))}),Ht(a))for(let[c,u]of n)u.readsMem&&n.delete(c)}}}return i},Or=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};if(o.sets!==1||o.gets!==1||o.tees!==0)continue;let f=G(n[2]);t.splice(s,2,...Array.isArray(f)?[f]:[f]),i=!0,s--}return i},Cr=(t,e,r)=>{let i=!1;for(let s=1;s<t.length-1;s++){let n=t[s],l=t[s+1];if(!Array.isArray(n)||n[0]!=="local.set"||n.length!==3||!Array.isArray(l)||l[0]!=="local.get"||l.length!==2)continue;let a=n[1];if(l[1]!==a||e.has(a))continue;let o=r.get(a)||{gets:0,sets:0,tees:0};o.sets+o.gets+o.tees<=2||(t.splice(s,2,["local.tee",a,G(n[2])]),i=!0)}return i},Lr=(t,e,r)=>{let i=!1,s=n=>r.get(n)||{gets:0,sets:0,tees:0};for(let n=t.length-1;n>=1;n--){let l=t[n];if(!Array.isArray(l))continue;let a=typeof l[1]=="string"?l[1]:null;if(!a||e.has(a))continue;let o=s(a);l[0]==="local.set"&&o.gets===0&&o.tees===0?l.length===3?gt(l[2])&&(t.splice(n,1),i=!0):l.length===2&&(t[n]=["drop"],i=!0):l[0]==="local"&&a[0]==="$"&&o.gets===0&&o.sets===0&&o.tees===0&&(t.splice(n,1),i=!0)}return i},Te=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),Ee=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Set;for(let s of e)Array.isArray(s)&&s[0]==="param"&&typeof s[1]=="string"&&r.add(s[1]);let i=[];U(e,s=>{Te(s)&&i.push(s)});for(let s=0;s<6;s++){let n=Ur(e),l=!1;for(let a of i)Fr(a,r,n)&&(l=!0),Or(a,r,n)&&(l=!0),Cr(a,r,n)&&(l=!0),Lr(a,r,n)&&(l=!0);if(!l)break}}),t),Dr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map;for(let r of t.slice(1)){if(!Array.isArray(r)||r[0]!=="func")continue;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i)continue;let s=[],n=[],l=!1,a=!1;for(let o=1;o<r.length;o++){let f=r[o];if(Array.isArray(f))if(f[0]==="param")if(typeof f[1]=="string"&&f[1][0]==="$")s.push({name:f[1],type:f[2]});else{s=null;break}else f[0]==="local"?l=!0:f[0]==="export"?a=!0:f[0]!=="result"&&f[0]!=="type"&&n.push(f)}if(s&&!l&&!a&&s.length<=4&&n.length===1){let o=new Set(s.map(u=>u.name)),f=!1,c=!1;S(n[0],u=>{Array.isArray(u)&&((u[0]==="local.set"||u[0]==="local.tee")&&o.has(u[1])&&(f=!0),(u[0]==="return"||u[0]==="return_call"||u[0]==="return_call_indirect")&&(c=!0))}),!f&&!c&&e.set(i,{body:n[0],params:s})}}return e.size===0||U(t,r=>{if(!Array.isArray(r)||r[0]!=="call")return;let i=r[1];if(!e.has(i))return;let{body:s,params:n}=e.get(i),l=r.slice(2);return n.length===0?G(s):U(G(s),o=>{if(!Array.isArray(o)||o[0]!=="local.get")return;let f=o[1],c=n.findIndex(u=>u.name===f);if(c!==-1&&l[c])return G(l[c])})}),t},Rr=0,Wr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set(["export","type","param","result","local"]),r=f=>{let c=2;for(;c<f.length&&(typeof f[c]=="string"||Array.isArray(f[c])&&e.has(f[c][0]));)c++;return c},i=f=>f==="br"||f==="br_if"||f==="br_table",s=f=>{if(!Array.isArray(f))return!1;let c=f[0];if(c==="return_call"||c==="return_call_indirect"||c==="return_call_ref"||c==="try"||c==="try_table"||c==="delegate"||c==="rethrow")return!0;if(i(c)){for(let u=1;u<f.length;u++)if(typeof f[u]=="number"||typeof f[u]=="string"&&/^\d+$/.test(f[u]))return!0}for(let u=1;u<f.length;u++)if(s(f[u]))return!0;return!1},n=(f,c)=>{if(!Array.isArray(f))return!1;if((f[0]==="call"||f[0]==="return_call")&&f[1]===c)return!0;for(let u=1;u<f.length;u++)if(n(f[u],c))return!0;return!1},l=f=>f==="i32"?["i32.const",0]:f==="i64"?["i64.const",0n]:f==="f32"?["f32.const",0]:f==="f64"?["f64.const",0]:f==="v128"?["v128.const","i64x2",0n,0n]:null,a=(f,c)=>{let u=!1,p=!1,y=0,g=m=>{if(u||!Array.isArray(m))return;let _=m[0],b=_==="local.set"||_==="local.tee";if((b||_==="local.get")&&m[1]===c){if(b)for(let A=2;A<m.length&&!u;A++)g(m[A]);if(u)return;u=!0,(_==="local.get"||y>0)&&(p=!0);return}let v=_==="if";for(let A=1;A<m.length&&!u;A++){let z=m[A],I=v&&Array.isArray(z)&&(z[0]==="then"||z[0]==="else");I&&y++,g(z),I&&y--}};for(let m of f){if(u)break;g(m)}return u?p:!1},o=(f,c)=>{if(!Array.isArray(f))return;let u=f[0];if(u==="export"&&Array.isArray(f[2])&&f[2][0]==="func"&&typeof f[2][1]=="string")c.add(f[2][1]);else if(u==="start"&&typeof f[1]=="string")c.add(f[1]);else if(u==="ref.func"&&typeof f[1]=="string")c.add(f[1]);else if(u==="elem")for(let p of f)typeof p=="string"&&p[0]==="$"&&c.add(p);for(let p of f)o(p,c)};for(let f=0;f<16;f++){let c=t.filter(w=>Array.isArray(w)&&w[0]==="func"),u=new Map;for(let w of c)typeof w[1]=="string"&&u.set(w[1],w);let p=new Map,y=new Set,g=w=>{if(!Array.isArray(w))return;let N=w[0];N==="call"&&typeof w[1]=="string"?p.set(w[1],(p.get(w[1])||0)+1):N==="return_call"&&typeof w[1]=="string"&&y.add(w[1]);for(let F=1;F<w.length;F++)g(w[F])};g(t);let m=new Set;for(let w of t)(!Array.isArray(w)||w[0]!=="func")&&o(w,m);let _=null;for(let[w,N]of u){if(m.has(w)||y.has(w)||p.get(w)!==1||n(N,w))continue;let F=!0,J=0;for(let V=2;V<N.length;V++){let j=N[V];if(typeof j!="string"){if(!Array.isArray(j)){F=!1;break}if(j[0]==="param"||j[0]==="local"){if(typeof j[1]!="string"||j[1][0]!=="$"){F=!1;break}if(j[0]==="local"&&!l(j[2])){F=!1;break}}else if(j[0]==="result")J+=j.length-1;else if(j[0]==="export"){F=!1;break}else{if(j[0]==="type")continue;break}}}if(!F||J>1)continue;let tt=!1;for(let V=r(N);V<N.length;V++)if(s(N[V])){tt=!0;break}if(!tt){_=w;break}}if(!_)break;let b=u.get(_),v=[],A=[],z=null;for(let w=2;w<b.length;w++){let N=b[w];if(!(typeof N=="string"||!Array.isArray(N)))if(N[0]==="param")v.push({name:N[1],type:N[2]});else if(N[0]==="result")N.length>1&&(z=N[1]);else if(N[0]==="local")A.push({name:N[1],type:N[2]});else{if(N[0]==="export"||N[0]==="type")continue;break}}let I=b.slice(r(b)),M=++Rr,C=`$__inl${M}`,O=new Map;for(let w of v)O.set(w.name,`$__inl${M}_${w.name.slice(1)}`);for(let w of A)O.set(w.name,`$__inl${M}_${w.name.slice(1)}`);let q=w=>w==="block"||w==="loop"||w==="if",x=new Map,d=w=>{if(Array.isArray(w)){q(w[0])&&typeof w[1]=="string"&&w[1][0]==="$"&&!x.has(w[1])&&x.set(w[1],`$__inl${M}L_${w[1].slice(1)}`);for(let N=1;N<w.length;N++)d(w[N])}};for(let w of I)d(w);let k=w=>{if(!Array.isArray(w))return w;let N=w[0];return(N==="local.get"||N==="local.set"||N==="local.tee")&&typeof w[1]=="string"&&O.has(w[1])?[N,O.get(w[1]),...w.slice(2).map(k)]:N==="return"?["br",C,...w.slice(1).map(k)]:q(N)&&typeof w[1]=="string"&&x.has(w[1])?[N,x.get(w[1]),...w.slice(2).map(k)]:i(N)?[N,...w.slice(1).map(F=>typeof F=="string"&&x.has(F)?x.get(F):k(F))]:w.map((F,J)=>J===0?F:k(F))},D=!1;for(let w of c){if(w===b||D)continue;let N=r(w);for(let F=N;F<w.length;F++){let J=U(w[F],tt=>{if(D||!Array.isArray(tt)||tt[0]!=="call"||tt[1]!==_)return;let V=tt.slice(2);if(V.length!==v.length)return;let j=v.map((ot,Le)=>["local.set",O.get(ot.name),V[Le]]),ee=A.filter(ot=>a(I,ot.name)).map(ot=>["local.set",O.get(ot.name),l(ot.type)]),re=I.map(k);return D=!0,z?["block",C,["result",z],...j,...ee,...re]:["block",C,...j,...ee,...re]});if(J!==w[F]&&(w[F]=J),D){let tt=[...v,...A].map(V=>["local",O.get(V.name),V.type]);tt.length&&w.splice(r(w),0,...tt);break}}if(D)break}if(!D)break;let Q=t.indexOf(b);Q>=0&&t.splice(Q,1)}return t},qt=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],a=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(a=!0),!n){if(l==="br"||l==="br_if"||l==="br_on_null"||l==="br_on_non_null"||l==="br_on_cast"||l==="br_on_cast_fail"){if(s[1]===e){r=!0;return}}else if(l==="br_table"){for(let o=1;o<s.length&&typeof s[o]=="string";o++)if(s[o]===e){r=!0;return}}else if(l==="catch"||l==="catch_ref"){if(s[2]===e){r=!0;return}}else if((l==="catch_all"||l==="catch_all_ref")&&s[1]===e){r=!0;return}}for(let o=1;o<s.length;o++)i(s[o],a)};for(let s of t)i(s,!1);return r},Pr=t=>(U(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2);let s=!1;for(;r<e.length;){let a=e[r];if(Array.isArray(a)&&(a[0]==="param"||a[0]==="type")){r++;continue}if(Array.isArray(a)&&a[0]==="result"){s=!0,r++;continue}break}let n=e.slice(r);if(!s||n.length!==1)return;let l=n[0];if(Array.isArray(l)&&!(i&&qt(n,i))){e.length=0;for(let a of l)e.push(a)}}),S(t,e=>{if(!Te(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)){r++;continue}{let a=i[0],o=a==="local.set"||a==="global.set"?2:a==="drop"?1:-1;if(o>=0&&i.length===o+1){let f=i[o];if(Array.isArray(f)&&f[0]==="block"){let c=1,u=null;typeof f[1]=="string"&&f[1][0]==="$"&&(u=f[1],c=2);let p=!1;for(;c<f.length;){let g=f[c];if(Array.isArray(g)&&(g[0]==="param"||g[0]==="type")){c++;continue}if(Array.isArray(g)&&g[0]==="result"){p=!0,c++;continue}break}let y=p?f.slice(c):null;if(y&&y.length>=2&&!(u&&qt(y,u))){let g=y[y.length-1],m=y.slice(0,-1);i[o]=g,e.splice(r,1,...m,i);continue}}}}if(i[0]!=="block"){r++;continue}let s=1,n=null;for(typeof i[1]=="string"&&i[1][0]==="$"&&(n=i[1],s=2);s<i.length;){let a=i[s];if(Array.isArray(a)&&(a[0]==="param"||a[0]==="result"||a[0]==="type")){s++;continue}break}let l=i.slice(s);if(n&&qt(l,n)){r++;continue}e.splice(r,1,...l),r+=l.length}}),t),jr=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let p of e)Array.isArray(p)&&p[0]==="local"&&typeof p[1]=="string"&&p[1][0]==="$"&&typeof p[2]=="string"&&r.set(p[1],p[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,a=0,o=p=>{if(l||!Array.isArray(p))return;let y=p[0],g=y==="loop";g&&s.push({start:n,end:n});let m=y==="local.set"||y==="local.tee";if(m||y==="local.get"){let _=p[1];if(typeof _!="string"||_[0]!=="$"){l=!0;return}if(m)for(let v=2;v<p.length;v++)o(p[v]);let b=n++;if(r.has(_)){let v=i.get(_);v||(v={start:b,end:b,firstOp:y,firstCond:a>0,loops:new Set},i.set(_,v)),b>v.end&&(v.end=b);for(let A of s)v.loops.add(A)}}else{n++;let _=y==="if";for(let b=1;b<p.length;b++){let v=p[b],A=_&&Array.isArray(v)&&(v[0]==="then"||v[0]==="else");A&&a++,o(v),A&&a--}}if(g){let _=s.pop();_.end=n}};if(o(e),l)return;for(let p of i.values())for(let y of p.loops)y.start<p.start&&(p.start=y.start),y.end>p.end&&(p.end=y.end);let f=[...i.entries()].sort((p,y)=>p[1].start-y[1].start),c=new Map,u=[];for(let[p,y]of f){let g=y.firstOp==="local.get"||y.firstCond,m=r.get(p),_=g?null:u.find(b=>b.type===m&&b.end<y.start);_?(c.set(p,_.primary),y.end>_.end&&(_.end=y.end)):u.push({primary:p,type:m,end:y.end})}c.size!==0&&S(e,p=>{Array.isArray(p)&&(p[0]==="local.get"||p[0]==="local.set"||p[0]==="local.tee")&&c.has(p[1])&&(p[1]=c.get(p[1]))})}),t),Gr=t=>U(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2&&gt(e[1]))return["nop"];if(r==="select"&&e.length>=4&&T(e[1],e[2]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=Ct(e),l=!s||s.length<=1,a=!n||n.length<=1;if(l&&a)return gt(i)?["nop"]:["drop",i];if(n&&a&&!l)return e.filter(o=>o!==n)}if(r==="func"||r==="block"||r==="loop"||r==="then"||r==="else"){let i=[r];for(let s=1;s<e.length;s++){let n=e[s];if(n==="nop"||Array.isArray(n)&&n[0]==="nop")continue;let l=e[s+1],a=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&gt(n)&&a){s++;continue}i.push(n)}if(i.length!==e.length)return i}}),Hr={"i32.sub":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.sub":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.xor":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.xor":(t,e)=>T(t,e)?["i64.const",0n]:null,"i32.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.eq":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.ne":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i32.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.lt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.lt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_s":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.gt_u":(t,e)=>T(t,e)?["i32.const",0]:null,"i64.le_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.le_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_s":(t,e)=>T(t,e)?["i32.const",1]:null,"i64.ge_u":(t,e)=>T(t,e)?["i32.const",1]:null,"i32.mul":(t,e)=>{let r=E(t),i=E(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.mul":(t,e)=>{let r=E(t),i=E(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.and":(t,e)=>{if(T(t,e))return t;let r=E(t),i=E(e);return r?.value===0||i?.value===0?["i32.const",0]:null},"i64.and":(t,e)=>{if(T(t,e))return t;let r=E(t),i=E(e);return r?.value===0n||i?.value===0n?["i64.const",0n]:null},"i32.or":(t,e)=>{if(T(t,e))return t;let r=E(t),i=E(e);return r?.value===-1||i?.value===-1?["i32.const",-1]:null},"i64.or":(t,e)=>{if(T(t,e))return t;let r=E(t),i=E(e);return r?.value===-1n||i?.value===-1n?["i64.const",-1n]:null},"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Vr=t=>U(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Hr[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Yr=t=>{let e=typeof t=="bigint"?t:BigInt(Math.trunc(Number(t)||0)),r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},Xr=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Yr(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},Zr=2,Kr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Set;for(let n of t.slice(1)){if(!Array.isArray(n))continue;if(n[0]==="export"&&Array.isArray(n[2])&&n[2][0]==="global"&&typeof n[2][1]=="string"){r.add(n[2][1]);continue}if(n[0]!=="global")continue;let l=typeof n[1]=="string"&&n[1][0]==="$"?n[1]:null;if(!l)continue;n.some(f=>Array.isArray(f)&&f[0]==="export")&&r.add(l);let a=n[2];if(Array.isArray(a)&&a[0]==="mut"||Array.isArray(a)&&a[0]==="import")continue;let o=n[3];E(o)&&e.set(l,o)}if(e.size===0)return t;let i=new Map;S(t,n=>{if(!Array.isArray(n))return;let l=n[1];typeof l!="string"||l[0]!=="$"||(n[0]==="global.set"?e.delete(l):n[0]==="global.get"&&i.set(l,(i.get(l)||0)+1))});let s=new Set;for(let[n,l]of e){let a=i.get(n)||0;if(a===0)continue;let o=Xr(l),f=o+2,c=a*Zr+f;a*o+(r.has(n)?f:0)<=c&&s.add(n)}if(s.size===0)return t;U(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return G(e.get(n[1]))});for(let n=t.length-1;n>=1;n--){let l=t[n];Array.isArray(l)&&l[0]==="global"&&typeof l[1]=="string"&&s.has(l[1])&&!r.has(l[1])&&t.splice(n,1)}return t},Qr=t=>U(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(typeof r!="string"||!r.endsWith("load")&&!r.endsWith("store"))return;let i=r.endsWith("store"),s=0,n=null,l=1;for(typeof e[1]=="string"&&(e[1][0]==="$"||!isNaN(e[1]))&&(n=e[1],l=2);l<e.length&&typeof e[l]=="string"&&(e[l].startsWith("offset=")||e[l].startsWith("align="));)e[l].startsWith("offset=")&&(s=+e[l].slice(7)),l++;let a=i?e.length-2:e.length-1,o=i?e.length-1:-1;if(a<l)return;let f=e[a];if(!Array.isArray(f)||f[0]!=="i32.add"||f.length!==3)return;let c=f[1],u=f[2],p=E(c),y=E(u),g=null,m=null;if(p&&p.type==="i32"?(m=p.value,g=u):y&&y.type==="i32"&&(m=y.value,g=c),g===null||m===null)return;let _=s+m,b=[r];n!==null&&b.push(n),b.push(`offset=${_}`);let v=null;for(let A=l;A<a;A++)typeof e[A]=="string"&&e[A].startsWith("align=")&&(v=e[A]);return v&&b.push(v),b.push(g),i&&b.push(e[o]),b}),Jr=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let i=1,s=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(s=e[1],i=2),!s)return;let n=-1;for(let a=e.length-1;a>=i;a--){let o=e[a];if(!Array.isArray(o)){o!=="nop"&&o!=="end"&&(n=a);continue}let f=o[0];if(!(f==="param"||f==="result"||f==="local"||f==="type"||f==="export")){n=a;break}}if(n<0)return;let l=e[n];Array.isArray(l)&&l[0]==="br"&&l[1]===s&&e.splice(n,1,...l.slice(2))}),t),ti=t=>(S(t,e=>{if(!Array.isArray(e)||e[0]!=="block")return;let r=1,i=null;if(typeof e[1]=="string"&&e[1][0]==="$"&&(i=e[1],r=2),!i)return;for(;r<e.length;){let g=e[r];if(Array.isArray(g)&&g[0]==="type"){r++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}if(e.length-r!==1)return;let s=e[r];if(!Array.isArray(s)||s[0]!=="loop")return;let n=1,l=null;typeof s[1]=="string"&&s[1][0]==="$"&&(l=s[1],n=2);let a=[];for(;n<s.length;){let g=s[n];if(Array.isArray(g)&&g[0]==="type"){a.push(g),n++;continue}if(Array.isArray(g)&&(g[0]==="param"||g[0]==="result"))return;break}let o=s.slice(n);if(o.length<2)return;let f=o[0],c=o[o.length-1];if(!Array.isArray(f)||f[0]!=="br_if"||f[1]!==i||f.length!==3||!Array.isArray(c)||c[0]!=="br"||c[1]!==l||c.length!==2)return;let u=o.slice(1,-1);if(qt(u,i))return;let p=f[2];Array.isArray(p)&&p[0]==="i32.eqz"&&p.length===2?p=p[1]:p=["i32.eqz",p];let y=["loop"];l&&y.push(l);for(let g of a)y.push(g);y.push(["if",p,["then",...u,c]]),e.length=0;for(let g of y)e.push(g)}),t),ei=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return S(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),U(t,r=>{if(!Array.isArray(r)||r[0]!=="global")return;let i=typeof r[1]=="string"&&r[1][0]==="$"?r[1]:null;if(!i||e.has(i))return;let s=typeof r[1]=="string"&&r[1][0]==="$",n=s?r[2]:r[1];if(Array.isArray(n)&&n[0]==="mut"){let l=[...r];return l[s?2:1]=n[1],l}})},ri=t=>U(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=Ct(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let a=i[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],r]}if(n&&!l&&s.length===2){let a=s[1];if(Array.isArray(a)&&a[0]==="br"&&a.length===2)return["br_if",a[1],["i32.eqz",r]]}}),ii=t=>U(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=Ct(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(p=>Array.isArray(p)&&p[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let p=1;p<l&&T(r[r.length-p],i[i.length-p]);p++)n++;if(n===0)return;let a=r.slice(r.length-n),o=r.slice(0,r.length-n),f=i.slice(0,i.length-n),c=["block"];for(let p=1;p<e.length;p++){let y=e[p];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")&&c.push(y)}let u=["if"];for(let p=1;p<e.length;p++){let y=e[p];if(Array.isArray(y)&&(y[0]==="then"||y[0]==="else"))break;Array.isArray(y)&&(y[0]==="result"||y[0]==="type")||u.push(y)}return u.push(o.length>1?o:["then"]),u.push(f.length>1?f:["else"]),c.push(u,...a),c}),Ue=(t,e)=>{let r=[],i=[t];for(;i.length;){let s=i.pop();if(Array.isArray(s)){i.push("|");for(let n=s.length-1;n>=0;n--)i.push(s[n]);i.push("[")}else typeof s=="string"?r.push(e.has(s)?"$__L":s):typeof s=="bigint"?r.push(s.toString()+"n"):typeof s=="number"?r.push(s.toString()):s===null?r.push("null"):s===!0?r.push("t"):s===!1?r.push("f"):r.push(String(s))}return r.join(",")},si=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="func")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=new Set;typeof i[1]=="string"&&i[1][0]==="$"&&n.add(i[1]),S(i,a=>{if(!Array.isArray(a)||typeof a[1]!="string"||a[1][0]!=="$")return;let o=a[0];(o==="param"||o==="local"||o==="block"||o==="loop"||o==="if")&&n.add(a[1])});let l=Ue(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||U(t,i=>{if(!Array.isArray(i))return;let s=i[0];if((s==="call"||s==="return_call")&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(s==="ref.func"&&r.has(i[1]))return["ref.func",r.get(i[1])];if(s==="elem"){let n=i[i.length-1];if(Array.isArray(n))return[...i.slice(0,-1),n.map(l=>r.get(l)||l)]}if(s==="call_indirect"&&i.length>=3){let n=i[1];if(typeof n=="string"&&r.has(n))return["call_indirect",r.get(n),...i.slice(2)]}}),t},ni=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map;for(let i of t.slice(1)){if(!Array.isArray(i)||i[0]!=="type")continue;let s=typeof i[1]=="string"&&i[1][0]==="$"?i[1]:null;if(!s)continue;let n=Ue(i,new Set([s]));e.has(n)?r.set(s,e.get(n)):e.set(n,s)}if(r.size===0)return t;for(let i=t.length-1;i>=0;i--){let s=t[i];if(Array.isArray(s)&&s[0]==="type"){let n=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;n&&r.has(n)&&t.splice(i,1)}}return U(t,i=>{if(!Array.isArray(i))return;let s=i[0];if(s==="func")for(let n=1;n<i.length;n++){let l=i[n];Array.isArray(l)&&l[0]==="type"&&typeof l[1]=="string"&&r.has(l[1])&&(i[n]=["type",r.get(l[1])])}if(s==="import")for(let n=1;n<i.length;n++){let l=i[n];if(Array.isArray(l))for(let a=1;a<l.length;a++){let o=l[a];Array.isArray(o)&&o[0]==="type"&&typeof o[1]=="string"&&r.has(o[1])&&(l[a]=["type",r.get(o[1])])}}if(s==="call_indirect"||s==="return_call_indirect"){if(typeof i[1]=="string"&&r.has(i[1]))return[s,r.get(i[1]),...i.slice(2)];if(Array.isArray(i[1])&&i[1][0]==="type"&&typeof i[1][1]=="string"&&r.has(i[1][1]))return[s,["type",r.get(i[1][1])],...i.slice(2)]}}),t},Ft=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return new Uint8Array;let e=t.slice(1,-1),r=[];for(let i=0;i<e.length;i++)if(e[i]==="\\"){let s=e[++i];s==="x"||s==="X"?(r.push(parseInt(e.slice(i+1,i+3),16)),i+=2):/[0-9a-fA-F]/.test(s)&&/[0-9a-fA-F]/.test(e[i+1])?(r.push(parseInt(e.slice(i,i+2),16)),i++):s==="n"?r.push(10):s==="t"?r.push(9):s==="r"?r.push(13):s==="\\"?r.push(92):s==='"'?r.push(34):r.push(s.charCodeAt(0))}else r.push(e.charCodeAt(i));return new Uint8Array(r)},qe=t=>{let e='"';for(let r=0;r<t.length;r++){let i=t[r];i>=32&&i<127&&i!==34&&i!==92?e+=String.fromCharCode(i):e+="\\"+i.toString(16).padStart(2,"0")}return e+'"'},li=t=>{let e=[];for(let i of t)if(typeof i=="string")e.push(...Ft(i));else if(Array.isArray(i)&&i[0]==="i8")for(let s=1;s<i.length;s++)e.push(Number(i[s])&255);else return t;let r=e.length;for(;r>0&&e[r-1]===0;)r--;return r===e.length?t:r===0?[]:[qe(new Uint8Array(e.slice(0,r)))]},ai=t=>{let e=1;if(typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"){let i=t[e][1];e++;let s=t[e];return Array.isArray(s)&&(s[0]==="i32.const"||s[0]==="i64.const")?{memidx:i,offset:Number(s[1])}:null}let r=t[e];return Array.isArray(r)&&(r[0]==="i32.const"||r[0]==="i64.const")?{memidx:0,offset:Number(r[1])}:null},Ie=t=>{let e=1;typeof t[e]=="string"&&t[e][0]==="$"&&e++,Array.isArray(t[e])&&t[e][0]==="memory"&&e++,Array.isArray(t[e])&&typeof t[e][0]=="string"&&!t[e][0].startsWith('"')&&e++;let r=0;for(let i=e;i<t.length;i++){let s=t[i];if(typeof s=="string")r+=Ft(s).length;else if(Array.isArray(s)&&s[0]==="i8")r+=s.length-1;else return null}return r},fi=(t,e)=>{let r=1;typeof t[r]=="string"&&t[r][0]==="$"&&r++,Array.isArray(t[r])&&t[r][0]==="memory"&&r++,Array.isArray(t[r])&&typeof t[r][0]=="string"&&!t[r][0].startsWith('"')&&r++;let i=1;typeof e[i]=="string"&&e[i][0]==="$"&&i++,Array.isArray(e[i])&&e[i][0]==="memory"&&i++,Array.isArray(e[i])&&typeof e[i][0]=="string"&&!e[i][0].startsWith('"')&&i++;let s=t.slice(r),n=e.slice(i);if(s.length===1&&n.length===1&&typeof s[0]=="string"&&typeof n[0]=="string"){let l=Ft(s[0]),a=Ft(n[0]),o=new Uint8Array(l.length+a.length);return o.set(l),o.set(a,l.length),t.length=r,t.push(qe(o)),!0}return t.length=r,t.push(...s,...n),!0},oi=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;for(let i of t){if(!Array.isArray(i)||i[0]!=="data")continue;let s=1;typeof i[1]=="string"&&i[1][0]==="$"&&(s=2),s<i.length&&Array.isArray(i[s])&&typeof i[s][0]=="string"&&!i[s][0].startsWith('"')&&s++;let n=i.slice(s);if(n.length===0)continue;let l=li(n);(l.length!==n.length||l.length>0&&l[0]!==n[0])&&(i.length=s,i.push(...l))}let e=[];for(let i=0;i<t.length;i++){let s=t[i];if(Array.isArray(s)&&s[0]==="data"){let n=ai(s);if(n){let l=Ie(s);l!==null&&e.push({...n,node:s,index:i,len:l})}}}e.sort((i,s)=>{let n=String(i.memidx),l=String(s.memidx);return n!==l?n.localeCompare(l):i.offset-s.offset});let r=new Set;for(let i=0;i<e.length-1;i++){let s=e[i],n=e[i+1];r.has(s.index)||String(s.memidx)!==String(n.memidx)||s.offset+s.len===n.offset&&fi(s.node,n.node)&&(r.add(n.index),s.len=Ie(s.node))}return r.size>0&&(t=t.filter((i,s)=>!r.has(s))),t},ke=()=>{let t=new Map,e=0;return r=>{if(!t.has(r)){let i="",s=e++;do i=String.fromCharCode(97+s%26)+i,s=Math.floor(s/26)-1;while(s>=0);t.set(r,i||"a")}return t.get(r)}},ci=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=ke(),r=ke();for(let i of t)!Array.isArray(i)||i[0]!=="import"||(typeof i[1]=="string"&&i[1][0]==='"'&&(i[1]='"'+e(i[1].slice(1,-1))+'"'),typeof i[2]=="string"&&i[2][0]==='"'&&(i[2]='"'+r(i[2].slice(1,-1))+'"'));return t},ui=t=>{let e=!0;return S(t,r=>{if(!e||!Array.isArray(r))return;let i=r[0];if(i==="func"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if((i==="call"||i==="return_call"||i==="ref.func")&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="start"&&(typeof r[1]!="string"||r[1][0]!=="$"))e=!1;else if(i==="elem")for(let s of r){if(typeof s=="string"&&s[0]!=="$"&&/^\d/.test(s)){e=!1;break}if(Array.isArray(s)&&s[0]==="ref.func"&&(typeof s[1]!="string"||s[1][0]!=="$")){e=!1;break}}}),e},yi=t=>{if(!Array.isArray(t)||t[0]!=="module"||!ui(t))return t;let e=new Map;S(t,n=>{Array.isArray(n)&&(n[0]==="call"||n[0]==="return_call")&&e.set(n[1],(e.get(n[1])||0)+1)});let r=[],i=[],s=[];for(let n of t.slice(1)){if(!Array.isArray(n)){s.push(n);continue}n[0]==="import"?r.push(n):n[0]==="func"?i.push(n):s.push(n)}return i.sort((n,l)=>(e.get(l[1])||0)-(e.get(n[1])||0)),["module",...r,...i,...s]},Ot=[["stripmut",ei,!0,"strip mut from never-written globals"],["globals",Kr,!0,"propagate immutable global constants"],["fold",Ir,!0,"constant folding"],["identity",Mr,!0,"remove identity ops (x + 0 \u2192 x)"],["peephole",Vr,!0,"x-x\u21920, x&0\u21920, etc."],["strength",Br,!0,"strength reduction (x * 2 \u2192 x << 1)"],["branch",Nr,!0,"simplify constant branches"],["propagate",Ee,!0,"forward-propagate single-use locals & tiny consts (never inflates)"],["inlineOnce",Wr,!0,"inline single-call functions into their lone caller (never duplicates)"],["inline",Dr,!1,"inline tiny functions \u2014 can duplicate bodies"],["offset",Qr,!0,"fold add+const into load/store offset"],["unbranch",Jr,!0,"remove redundant br at end of own block"],["loopify",ti,!0,"collapse block+loop+brif while-idiom into loop+if"],["brif",ri,!0,"if-then-br \u2192 br_if"],["foldarms",ii,!1,"merge identical trailing if arms \u2014 can add block wrapper"],["deadcode",Sr,!0,"eliminate dead code after unreachable/br/return"],["vacuum",Gr,!0,"remove nops, drop-of-pure, empty branches"],["mergeBlocks",Pr,!0,"unwrap `(block $L \u2026)` whose label is never targeted"],["coalesce",jr,!0,"share local slots between same-type non-overlapping locals"],["locals",zr,!0,"remove unused locals"],["dedupe",si,!0,"eliminate duplicate functions"],["dedupTypes",ni,!0,"merge identical type definitions"],["packData",oi,!0,"trim trailing zeros, merge adjacent data segments"],["reorder",yi,!1,"put hot functions first \u2014 no AST reduction"],["treeshake",hr,!0,"remove unused funcs/globals/types/tables"],["minifyImports",ci,!1,"shorten import names \u2014 enable only when you control the host"]],Ri=Object.fromEntries(Ot.map(t=>[t[0],t[2]])),pi=t=>{if(t===!1)return{};if(t!==!0&&typeof t!="string"){let i={...t};for(let s of Ot)i[s[0]]===void 0&&(i[s[0]]=s[2]);return i}let e=typeof t=="string"?new Set(t.split(/\s+/).filter(Boolean)):null,r={};for(let i of Ot)r[i[0]]=e?e.has("all")||e.has(i[0]):i[2];return r};function Qt(t,e=!0){typeof t=="string"&&(t=et(t));let r=e===!0;e=pi(e);let i=e.log?(l,a)=>e.log(l,a):()=>{},s=e.verbose||e.log;t=G(t);let n=null;for(let l=0;l<3;l++){n=G(t);let a=Ae(t);for(let[u,p]of Ot)e[u]&&(t=p(t));e.propagate&&(e.inlineOnce||e.inline)&&(t=Ee(t));let f=Ae(t)-a;if((s||f!==0)&&i(` round ${l+1}: ${f>0?"+":""}${f} bytes`,f),f>(r?0:16)){s&&i(` \u26A0 round ${l+1} inflated by ${f} bytes, reverting`,f),t=n;break}if(T(n,t))break}return t}var Fe="\uE000",mi=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t,s=xt(r);return s||(r==="local.get"&&e.locals?.[i[0]]?e.locals[i[0]]:r==="call"&&e.funcs?.[i[0]]?e.funcs[i[0]].result?.[0]:null)};function Jt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=Jt(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function gi(t,e){let r=[],i=new Map;return Jt(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let n=s[1];if(!i.has(n)){let a=[];for(let c=2;c<s.length;c++){let u=mi(s[c]);u&&a.push(u)}let o=r.length,f=n.name||`$fn${o}`;i.set(n,{idx:o,name:f.startsWith("$")?f:"$"+f,params:a,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function _i(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function te(t,e,r){let{parse:i,compile:s,optimize:n,polyfill:l}=t,a={};if(!Array.isArray(e)&&r.length&&typeof r[r.length-1]=="object"&&r[r.length-1]!==null&&!r[r.length-1].byteLength&&(a=r.pop()),Array.isArray(e)&&e.raw){let o=e[0];for(let g=0;g<r.length;g++)o+=Fe+e[g+1];let f=i(o),c=[],u=0;f=Jt(f,g=>{if(g===Fe){let m=r[u++];if(typeof m=="function")return c.push(m),m;if(typeof m=="string"&&(m[0]==="("||/^\s*\(/.test(m))){let _=i(m);return Array.isArray(_)&&Array.isArray(_[0])&&(_._splice=!0),_}return m?.byteLength!==void 0?[...m]:typeof m=="bigint"?m.toString():m}return g});let p=null;if(c.length){let g=gi(f,c);if(g.length){let m=_i(g);f[0]==="module"?f.splice(1,0,...m):typeof f[0]=="string"?f=[...m,f]:f.unshift(...m),p={env:{}};for(let _ of g)p.env[_.name.slice(1)]=_.fn}}a.polyfill&&(f=l(f,a.polyfill)),a.optimize&&(f=n(f,a.optimize));let y=s(f);return p&&(y._imports=p),y}if(a.polyfill||a.optimize){let o=typeof e=="string"?i(e):e;return a.polyfill&&(o=l(o,a.polyfill)),a.optimize&&(o=n(o,a.optimize)),s(o)}return s(e)}function Oe(t,e,r){let i=te(t,e,r),s=new WebAssembly.Module(i);return new WebAssembly.Instance(s,i._imports).exports}var Ce={parse:et,compile:yt,optimize:Qt,polyfill:Gt};function Ki(t,...e){return te(Ce,t,e)}function hi(t,...e){return Oe(Ce,t,e)}var Qi=hi;export{Ki as compile,Qi as default,Qt as optimize,et as parse,Gt as polyfill,he as print,hi as watr};
package/dist/watr.wasm CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "watr",
3
- "version": "4.6.8",
3
+ "version": "4.6.9",
4
4
  "description": "Light & fast WAT compiler – WebAssembly Text to binary, parse, print, transform",
5
5
  "main": "watr.js",
6
6
  "bin": {
package/src/compile.js CHANGED
@@ -13,20 +13,28 @@ import { err, unescape, str } from './util.js'
13
13
  * @param {Array} [result] - Internal accumulator
14
14
  * @returns {any} Cleaned node
15
15
  */
16
- const cleanup = (node, result) => !Array.isArray(node) ? (
17
- typeof node !== 'string' ? node :
18
- // skip comments: ;; ... or (; ... ;)
19
- node[0] === ';' || node[1] === ';' ? null :
20
- // normalize quoted ids: $"name" -> $name (if no escapes), else $unescaped
21
- node[0] === '$' && node[1] === '"' ? (node.includes('\\') ? '$' + unescape(node.slice(1)) : '$' + node.slice(2, -1)) :
22
- // convert string literals to byte arrays with valueOf
23
- node[0] === '"' ? str(node) :
24
- node
25
- ) :
26
- // remove annotations like (@name ...) except @custom and @metadata.code.*
27
- node[0]?.[0] === '@' && node[0] !== '@custom' && !node[0]?.startsWith?.('@metadata.code.') ? null :
28
- // unwrap single-element array containing module (after removing comments), preserve .loc
29
- (result = node.map(cleanup).filter(n => n != null), result.loc = node.loc, result.length === 1 && result[0]?.[0] === 'module' ? result[0] : result)
16
+ // Comments (;; … or (; … ;)) and non-custom (@…) annotations carry no semantic
17
+ // load past parse strip them. Predicate stays separate from `cleanup` so
18
+ // neither has to invent a "drop me" sentinel and risk colliding with a
19
+ // legitimate `null`/`undefined` immediate in the AST.
20
+ const isDroppable = (n) =>
21
+ (typeof n === 'string' && (n[0] === ';' || n[1] === ';')) ||
22
+ (Array.isArray(n) && n[0]?.[0] === '@' && n[0] !== '@custom' && !n[0]?.startsWith?.('@metadata.code.'))
23
+
24
+ const cleanup = (node, result) => {
25
+ if (typeof node === 'string') return (
26
+ // normalize quoted ids: $"name" -> $name (if no escapes), else $unescaped
27
+ node[0] === '$' && node[1] === '"' ? (node.includes('\\') ? '$' + unescape(node.slice(1)) : '$' + node.slice(2, -1)) :
28
+ // convert string literals to byte arrays with valueOf
29
+ node[0] === '"' ? str(node) :
30
+ node
31
+ )
32
+ if (!Array.isArray(node)) return node
33
+ result = node.filter(c => !isDroppable(c)).map(cleanup)
34
+ result.loc = node.loc
35
+ // unwrap single-element array containing module (after dropping comments), preserve .loc
36
+ return result.length === 1 && result[0]?.[0] === 'module' ? result[0] : result
37
+ }
30
38
 
31
39
 
32
40
  /**
@@ -41,7 +49,7 @@ export default function compile(nodes) {
41
49
  else err.src = '' // clear source if AST passed directly
42
50
  err.loc = 0
43
51
 
44
- nodes = cleanup(nodes) || []
52
+ nodes = isDroppable(nodes) ? [] : (cleanup(nodes) ?? [])
45
53
 
46
54
  let idx = 0
47
55
 
package/src/optimize.js CHANGED
@@ -868,6 +868,23 @@ const readsMemory = (node) => {
868
868
  return false
869
869
  }
870
870
 
871
+ /** True if `node` references state a `call` could mutate.
872
+ * Calls cannot touch caller locals (those live in the function frame), so
873
+ * pure expressions over locals + constants survive any intervening call; only
874
+ * memory loads, global reads, and table reads (or further calls) can be stale
875
+ * after one. */
876
+ const readsCallableState = (node) => {
877
+ if (!Array.isArray(node)) return false
878
+ const op = node[0]
879
+ if (typeof op === 'string') {
880
+ if (op === 'global.get' || op === 'table.get' || op === 'table.size') return true
881
+ if (op === 'call' || op === 'call_indirect' || op === 'return_call' || op === 'return_call_indirect') return true
882
+ if (op.includes('.load') || op === 'memory.copy' || op === 'memory.size') return true
883
+ }
884
+ for (let i = 1; i < node.length; i++) if (readsCallableState(node[i])) return true
885
+ return false
886
+ }
887
+
871
888
  /** True if `node` recursively contains an op that may write linear memory. */
872
889
  const writesMemory = (node) => {
873
890
  if (!Array.isArray(node)) return false
@@ -959,6 +976,15 @@ const forwardPropagate = (funcNode, params, useCounts) => {
959
976
  // back so the bare-RHS pattern actually propagates.
960
977
  const sr = substGets(instr[2], known)
961
978
  if (sr !== instr[2]) { instr[2] = sr; changed = true }
979
+ // Nested `local.set`/`local.tee` inside the RHS already ran when the next
980
+ // statement begins — drop tracked values that read those locals, else a
981
+ // later `local.get` substitutes a stale expression (e.g. `$ptr`'s
982
+ // `(local.get $ai0)` after a nested `(local.tee $ai0 …)` overwrites it).
983
+ walk(instr[2], n => {
984
+ if (!Array.isArray(n)) return
985
+ if ((n[0] === 'local.set' || n[0] === 'local.tee') && typeof n[1] === 'string')
986
+ { known.delete(n[1]); purgeRefs(known, n[1]) }
987
+ })
962
988
  const uses = getUseCount(instr[1])
963
989
  purgeRefs(known, instr[1]) // entries that read this local just went stale
964
990
  // Any tracked value whose RHS reads memory must be invalidated by the
@@ -977,9 +1003,11 @@ const forwardPropagate = (funcNode, params, useCounts) => {
977
1003
 
978
1004
  // Invalidate at control-flow boundaries
979
1005
  if (op === 'block' || op === 'loop' || op === 'if') known.clear()
980
- // Calls only invalidate non-constant tracked values
1006
+ // Calls invalidate tracked values that read state a callee can mutate
1007
+ // (memory, globals, tables, nested calls). Pure expressions over locals
1008
+ // and constants survive — callees can't reach caller locals.
981
1009
  if (op === 'call' || op === 'call_indirect' || op === 'return_call' || op === 'return_call_indirect')
982
- for (const [key, tracked] of known) if (!getConst(tracked.val)) known.delete(key)
1010
+ for (const [key, tracked] of known) if (readsCallableState(tracked.val)) known.delete(key)
983
1011
 
984
1012
  // Substitute: standalone local.get (walkPost can't replace root)
985
1013
  if (op === 'local.get' && instr.length === 2 && typeof instr[1] === 'string') {
package/src/print.js CHANGED
@@ -58,7 +58,7 @@ export default function print(tree, options = {}) {
58
58
  let curIndent = indent.repeat(level + 1)
59
59
 
60
60
  for (let i = 1; i < node.length; i++) {
61
- const sub = node[i].valueOf() // "\00abc\ff" strings are stored as arrays but have ._ with original value
61
+ const sub = node[i]?.valueOf?.() ?? node[i] // "\00abc\ff" strings are stored as arrays but have ._ with original value
62
62
 
63
63
  // comments - skip if not enabled
64
64
  if (typeof sub === 'string' && sub[1] === ';') {
@@ -1 +1 @@
1
- {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AA+BA;;;;;GAKG;AACH,uCAHW,MAAM,QAAM,GACV,UAAU,CA8NtB"}
1
+ {"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../src/compile.js"],"names":[],"mappings":"AAuCA;;;;;GAKG;AACH,uCAHW,MAAM,QAAM,GACV,UAAU,CA8NtB"}
@@ -1 +1 @@
1
- {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AA00FA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SAyD/B;AA13FD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AA8CD;;;;;GAKG;AACH,6CAgJC;AAuMD;;;;GAIG;AACH,wCAuBC;AAoMD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AA7QD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CAuCC;AAoeD,yCAoCC;AAID;;;;GAIG;AACH,0CAgGC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8CAmOC;AAyzCD;;;;;;;;GAQG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAc/B;AAvBD,qEAAqE;AACrE,uBAA8D;AAljC9D;;;;;GAKG;AACH,0CAgDC;AAwED;;;;GAIG;AACH,4CAQC;AA4BD;;;;;;;;;;;GAWG;AACH,2CAyDC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAyCC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAiDC;AAID;;;;;GAKG;AACH,4CAqBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAiDC;AAoCD;;;;;GAKG;AACH,0CA8DC;AAiWD,uCAyBC;AAtXD;;;;;GAKG;AACH,8CAyEC;AAoID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AA9qCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}
1
+ {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AAs2FA;;;;;;;;;;;GAWG;AACH,sCATW,QAAM,MAAM,SACZ,OAAO,GAAC,MAAM,MAAO,SAyD/B;AAt5FD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AA8CD;;;;;GAKG;AACH,6CAgJC;AAuMD;;;;GAIG;AACH,wCAuBC;AAoMD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AA7QD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CA6DC;AAID;;;;GAIG;AACH,0CAuCC;AAggBD,yCAoCC;AAID;;;;GAIG;AACH,0CAgGC;AAMD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,8CAmOC;AAyzCD;;;;;;;;GAQG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAc/B;AAvBD,qEAAqE;AACrE,uBAA8D;AAljC9D;;;;;GAKG;AACH,0CAgDC;AAwED;;;;GAIG;AACH,4CAQC;AA4BD;;;;;;;;;;;GAWG;AACH,2CAyDC;AAID,2EAA2E;AAC3E,sCAgEC;AAID;;;;GAIG;AACH,4CAyCC;AAID;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,2CAiDC;AAID;;;;;GAKG;AACH,4CAqBC;AAID;;;;;;GAMG;AACH,wCAmBC;AAID;;;;;GAKG;AACH,4CAiDC;AAoCD;;;;;GAKG;AACH,0CA8DC;AAiWD,uCAyBC;AAtXD;;;;;GAKG;AACH,8CAyEC;AAoID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AA9qCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}