watr 4.7.0 → 4.7.1

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
@@ -4500,7 +4500,7 @@ var buildInline = (params, locals, inlResult, cBody, args) => {
4500
4500
  };
4501
4501
  var INLINE_MAX_NODES = 90;
4502
4502
  var isV128SimdHelper = (params, inlResult) => inlResult === "v128" && params.length > 0 && params.every((p) => p.type === "v128");
4503
- var inline = (ast, { simdOnly = false } = {}) => {
4503
+ var inline = (ast, { simdOnly = false, pin = EMPTY_SET } = {}) => {
4504
4504
  if (!Array.isArray(ast) || ast[0] !== "module") return ast;
4505
4505
  const skip = /* @__PURE__ */ new Set();
4506
4506
  for (let round = 0; round < MAX_INLINE_ROUNDS; round++) {
@@ -4520,7 +4520,7 @@ var inline = (ast, { simdOnly = false } = {}) => {
4520
4520
  for (const n of ast) if (!Array.isArray(n) || n[0] !== "func") inlCollectPinned(n, pinned);
4521
4521
  let calleeName = null, parsed = null;
4522
4522
  for (const [name2, fn] of funcByName) {
4523
- if (skip.has(name2) || pinned.has(name2) || otherRef.has(name2) || SIMD_PROTECTED.has(name2)) continue;
4523
+ if (skip.has(name2) || pinned.has(name2) || otherRef.has(name2) || pin.has(name2)) continue;
4524
4524
  if (!(callRefs.get(name2) >= 1)) continue;
4525
4525
  if (inlBodySize(fn) > INLINE_MAX_NODES) continue;
4526
4526
  if (inlCallsSelf(fn, name2)) continue;
@@ -4789,8 +4789,7 @@ var devirt = (ast) => {
4789
4789
  }
4790
4790
  return ast;
4791
4791
  };
4792
- var SIMD_PROTECTED = /* @__PURE__ */ new Set(["$math.sin_core", "$math.cos_core", "$math.sin", "$math.cos", "$math.pow", "$math.atan2", "$math.hypot", "$math.log"]);
4793
- var inlineOnce = (ast) => {
4792
+ var inlineOnce = (ast, { pin = EMPTY_SET } = {}) => {
4794
4793
  if (!Array.isArray(ast) || ast[0] !== "module") return ast;
4795
4794
  const bodyStart = inlBodyStart, callsSelf = inlCallsSelf, unsafe = inlUnsafe, isBranch = inlIsBranch;
4796
4795
  const zeroFor = inlZeroFor, needsReset = inlNeedsReset;
@@ -4812,7 +4811,7 @@ var inlineOnce = (ast) => {
4812
4811
  for (const [name2, fn] of funcByName) {
4813
4812
  if (pinned.has(name2) || otherRef.has(name2)) continue;
4814
4813
  if (callRefs.get(name2) !== 1) continue;
4815
- if (SIMD_PROTECTED.has(name2)) continue;
4814
+ if (pin.has(name2)) continue;
4816
4815
  if (callsSelf(fn, name2)) continue;
4817
4816
  let ok = true, nResult = 0;
4818
4817
  for (let i = 2; i < fn.length; i++) {
@@ -5999,13 +5998,14 @@ function optimize(ast, opts = true) {
5999
5998
  if (typeof ast === "string") ast = parse_default(ast);
6000
5999
  const strictGuard = opts === true;
6001
6000
  opts = normalize3(opts);
6001
+ opts.pin = opts.pin instanceof Set ? opts.pin : new Set(opts.pin || []);
6002
6002
  const log = opts.log ? (msg, delta) => opts.log(msg, delta) : () => {
6003
6003
  };
6004
6004
  const verbose = opts.verbose || opts.log;
6005
6005
  ast = clone2(ast);
6006
6006
  const runInline = (a) => {
6007
6007
  if (!opts.inline) return a;
6008
- a = inline(a, { simdOnly: opts.inline === "simd" });
6008
+ a = inline(a, { simdOnly: opts.inline === "simd", pin: opts.pin });
6009
6009
  if (opts.propagate) a = propagate(a);
6010
6010
  if (opts.mergeBlocks) a = mergeBlocks(a);
6011
6011
  if (opts.vacuum) a = vacuum(a);
@@ -6019,7 +6019,7 @@ function optimize(ast, opts = true) {
6019
6019
  if (!((opts.inlineOnce || opts.inline) && mayInline(ast))) {
6020
6020
  for (let round = 0; round < 3; round++) {
6021
6021
  const beforeRound2 = clone2(ast);
6022
- for (const [key, fn] of PASSES) if (opts[key] && key !== "inlineOnce" && key !== "inline" && key !== "devirt") ast = fn(ast);
6022
+ for (const [key, fn] of PASSES) if (opts[key] && key !== "inlineOnce" && key !== "inline" && key !== "devirt") ast = fn(ast, opts);
6023
6023
  if (equal(beforeRound2, ast)) break;
6024
6024
  if (verbose) log(` round ${round + 1} applied`);
6025
6025
  }
@@ -6029,7 +6029,7 @@ function optimize(ast, opts = true) {
6029
6029
  let sizeBefore = binarySize(ast);
6030
6030
  for (let round = 0; round < 3; round++) {
6031
6031
  beforeRound = clone2(ast);
6032
- for (const [key, fn] of PASSES) if (opts[key] && key !== "devirt" && key !== "inline") ast = fn(ast);
6032
+ for (const [key, fn] of PASSES) if (opts[key] && key !== "devirt" && key !== "inline") ast = fn(ast, opts);
6033
6033
  if (opts.propagate && (opts.inlineOnce || opts.inline)) ast = propagate(ast);
6034
6034
  if (equal(beforeRound, ast)) break;
6035
6035
  const sizeAfter = binarySize(ast);
package/dist/watr.min.js CHANGED
@@ -1,6 +1,6 @@
1
- var dr=Object.defineProperty;var Ar=(t,e)=>{for(var r in e)dr(t,r,{get:e[r],enumerable:!0})};var Et={};Ar(Et,{f32:()=>dt,f64:()=>_t,i16:()=>Ir,i32:()=>Y,i64:()=>xt,i8:()=>vr,uleb:()=>I,uleb5:()=>$r,v128:()=>te});var T=(t,e=T.loc)=>{if(e!=null&&T.src){let r=1,i=1;for(let s=0;s<e&&s<T.src.length;s++)T.src[s]===`
2
- `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)},Ie=/^_|_$|[^\da-f]_|_[^\da-f]/i,ke=/^[+-]?(?:0x[\da-f]+|\d+)$/i,br=new TextEncoder,wr=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),ve={n:10,r:13,t:9,'"':34,"'":39,"\\":92},Tt=t=>{let e=[],r=1,i,s,n="",l=()=>(n&&e.push(...br.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++):ve[t[r]]?i=ve[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},Se=t=>wr.decode(new Uint8Array(Tt(t))),Qt=t=>Array.isArray(t)?t.map(Qt):t,G=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)G(t[s],e,t,s)},tt=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++)tt(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 I=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):Y.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),I(t,e))};function $r(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 Y(t,e=[]){for(typeof t=="string"&&(t=Y.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 Ne=t=>!Ie.test(t)&&ke.test(t=t.replaceAll("_",""))?t:T(`Bad int ${t}`),vr=Y,Ir=Y;Y.parse=t=>(t=parseInt(Ne(t)),(t<-2147483648||t>4294967295)&&T("i32 constant out of range"),t);function xt(t,e=[]){for(typeof t=="string"?t=xt.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 kt=new ArrayBuffer(8),et=new Uint8Array(kt),kr=new Int32Array(kt),Sr=new Float32Array(kt),Mr=new Float64Array(kt),Jt=new BigInt64Array(kt);xt.parse=t=>{t=Ne(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)&&T("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)&&T("i64 constant out of range")}let s=BigInt(r);return e&&(s=0n-s),Jt[0]=s,Jt[0]};var Br=2147483648,Nr=2139095040,Me=4194304;function dt(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"?Me:Y.parse(i)}else e=Me;e=(e|Nr)>>>0,t[0]==="-"&&(e=(e|Br)>>>0),kr[0]=e|0}else e=typeof t=="string"?dt.parse(t):t,Sr[0]=e;return[et[0],et[1],et[2],et[3]]}var zr=0x8000000000000000n,Tr=0x7ff0000000000000n,Be=0x8000000000000n;function _t(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"?Be:xt.parse(i)}else e=Be;e|=Tr,t[0]==="-"&&(e|=zr),Jt[0]=e}else e=typeof t=="string"?_t.parse(t):t,Mr[0]=e;return[et[0],et[1],et[2],et[3],et[4],et[5],et[6],et[7]]}_t.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("."),f=l.length??0,c=0;for(let m=n.length-1;m>=2;m--){let _=parseInt(n[m],16);c+=_*16**(n.length-1-m)}let a=l?parseInt("0x"+l)/16**f:0;s=parseInt(s,10);let y=r*(c+a)*2**s;return y=Math.max(-e,Math.min(e,y)),y}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};dt.parse=t=>_t.parse(t,34028234663852886e22);var te=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 St=["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"]],ze=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},D={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},P={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},pt={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},ee={func:0,table:1,memory:2,global:3,tag:4};var lt=t=>{let e=0,r=[],i="",s=0,n=0,l=()=>i&&(r.push(i),i=""),f=c=>{r.loc=c;for(let a,y,m;e<t.length;)if(a=t.charCodeAt(e),s===34)i+=t[e++],a===92?i+=t[e++]:a===34&&(l(),s=0);else if(s>59)a===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):a===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(l(),s=0)):i+=t[e++];else if(s<0)a===10||a===13?(i+=t[e++],l(),s=0):s===-2&&a===41?(l(),s=0):i+=t[e++];else if(a===34)i!=="$"&&l(),s=34,i+=t[e++];else if(a===40&&t.charCodeAt(e+1)===59)l(),s=60,i=t[e++]+t[e++];else if(a===59&&t.charCodeAt(e+1)===59)l(),s=t.indexOf(`
3
- `,e)<0?-2:-1,i=t[e++]+t[e++];else if(a===40&&t.charCodeAt(e+1)===64)l(),m=e,e+=2,i="@",n++,(y=r).push(r=[]),f(m),r=y;else if(a===40)l(),m=e++,n++,(y=r).push(r=[]),f(m),r=y;else{if(a===41)return l(),e++,n--;a<=32?(l(),e++):i+=t[e++]}s<0&&l(),l()};return f(0),s===34&&T("Unclosed quote",e),s>59&&T("Unclosed block comment",e),n>0&&T("Unclosed parenthesis",e),e<t.length&&T("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Oe=t=>typeof t=="string"&&(t[0]===";"||t[1]===";")||Array.isArray(t)&&t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code."),qe=(t,e)=>typeof t=="string"?t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+Se(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?Tt(t):t:Array.isArray(t)?(e=t.filter(r=>!Oe(r)).map(qe),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):t;function bt(t){typeof t=="string"?(T.src=t,t=lt(t)||[]):T.src="",T.loc=0,t=Oe(t)?[]:qe(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 bt(t.slice(++e).map(h=>h.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((h,$)=>{if($<e||!Array.isArray(h)||h[0]!=="import")return[h];let[,o,...u]=h;if(!u.some(p=>Array.isArray(p)&&p[0]==="item"))return[h];if(Array.isArray(u.at(-1))&&u.at(-1)[0]!=="item"){let p=u.at(-1);return u.slice(0,-1).filter(A=>A[0]==="item").map(([,A])=>["import",o,A,p])}return u.filter(p=>p[0]==="item").map(([,p,A])=>["import",o,p,A])});let r=[];for(let h in D)(r[D[h]]=r[h]=[]).name=h;r.metadata={},t.slice(e).filter(h=>{if(!Array.isArray(h)){let u=T.loc,g=T.src,p;for(;(u=g.indexOf(h,u))>=0;){if(p=g.charCodeAt(u-1),u>0&&(p>47&&p<58||p>64&&p<91||p>96&&p<123||p===95||p===36)){u++;continue}if(p=g.charCodeAt(u+h.length),p>47&&p<58||p>64&&p<91||p>96&&p<123||p===95){u++;continue}break}u>=0&&(T.loc=u),T(`Unexpected token ${h}`)}let[$,...o]=h;if(T.loc=h.loc,$==="@custom")r.custom.push(o);else if($==="rec")for(let u=0;u<o.length;u++){let[,...g]=o[u];re(g,r.type);let p=[];for(;g[0]?.[0]==="descriptor"||g[0]?.[0]==="describes";)p.push(g.shift());(g=Te(g,r)).push(u?!0:[r.type.length,o.length]),p.length&&(g.desc=g.desc?[...p,...g.desc]:p),r.type.push(g)}else if($==="type"){re(o,r.type);let u=[];for(;o[0]?.[0]==="descriptor"||o[0]?.[0]==="describes";)u.push(o.shift());let g=Te(o,r);u.length&&(g.desc=g.desc?[...u,...g.desc]:u),r.type.push(g)}else if($==="start"||$==="export")r[$].push(o);else return!0}).forEach(h=>{let[$,...o]=h;T.loc=h.loc;let u;$==="import"&&([$,...o]=(u=o).pop());let g=r[$];for(g||T(`Unknown section ${$}`),re(o,g);o[0]?.[0]==="export";)r.export.push([o.shift()[1],[$,g?.length]]);if(o[0]?.[0]==="import"&&([,...u]=o.shift()),$==="table"){let p=o[0]==="i64",A=p?1:0;if(o[A+1]?.[0]==="elem"){let[b,[,...M]]=[o[A],o[A+1]];o=p?["i64",M.length,M.length,b]:[M.length,M.length,b],r.elem.push([["table",g.length],["offset",[p?"i64.const":"i32.const",p?0n:0]],b,...M])}}else if($==="memory"){let p=o[0]==="i64",A=p?1:0;if(o[A]?.[0]==="data"){let b=o.find(v=>Array.isArray(v)&&v[0]==="pagesize")?.[1]??65536,[,...M]=o.splice(A,1)[0],z=""+Math.ceil(M.reduce((v,S)=>v+S.length,0)/b);r.data.push([["memory",g.length],[p?"i64.const":"i32.const",p?0n:0],...M]),o=p?["i64",z,z]:[z,z]}}else if($==="func"){let[p,A,b]=Dt(o,r);p??=Lt(A,b,r),!u&&r.code.push([[p,A,b],...yt(o,r)]),o=[["type",p]]}else if($==="tag"){let[p,A]=Dt(o,r);p??=Lt(A,[],r),o=[["type",p]]}u&&(r.import.push([...u,[$,...o]]),o=null),g.push(o)});let i=(h,$=!0)=>{let o=r[h].filter(Boolean).map(u=>ne[h](u,r)).filter(Boolean);return h===D.custom?o.flatMap(u=>[h,...C(u)]):o.length?[h,...C($?C(o):o.flat())]:[]},s=()=>{let h=[];for(let $ in r.metadata){let o=C(Tt(`"metadata.code.${$}"`)),u=C(r.metadata[$].map(([g,p])=>[...I(g),...C(p.map(([A,b])=>[...I(A),...C(b)]))]));h.push(0,...C([...o,...u]))}return h},n=i(D.global),l=i(D.elem),f=r.code.filter(Boolean).map(h=>ne[D.code](h,r)).filter(Boolean),c=f.length?[D.code,...C(C(f))]:[],a=s(),y=i(D.data),m=r.strings.length?[D.strings,...C([0,...C(r.strings.map(h=>C(h)))])]:[],_=[i(D.custom),i(D.type),i(D.import),i(D.func),i(D.table),i(D.memory),i(D.tag),m,n,i(D.export),i(D.start,!1),l,i(D.datacount,!1),c,a,y],d=Uint8Array.from([0,97,115,109,1,0,0,0,..._.flat()]),k=x();return k&&(d.metadata=k),d;function x(){let h=!1;for(let A in r.metadata)h=!0;if(!h)return;let $={},u=8+_.slice(0,_.indexOf(c)).reduce((A,b)=>A+b.length,0)+c.length-f.reduce((A,b)=>A+b.length,0),g=[];for(let A=0,b=u;A<f.length;A++)g[A]=b+(r.codeSizePrefix?.[A]??0),b+=f[A].length;let p=r.import.filter(A=>A[2][0]==="func").length;for(let A in r.metadata){let b=[];for(let[M,z]of r.metadata[A]){let v=g[M-p];for(let[S,w]of z)b.push([v+S,w])}$[A]=b.sort((M,z)=>M[0]-z[0])}return $}}var rt=t=>t?.[0]==="$"||!isNaN(t),H=t=>t?.[0]==="$",ie=t=>t?.[0]==="a"||t?.[0]==="o";function yt(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(Ot(t,e));else if(i==="else"||i==="end")H(t[0])&&t.shift();else if(i==="select")r.push(Ut(t)[1]);else if(i.endsWith("call_indirect")){let s=rt(t[0])?t.shift():0,[n,l,f]=Dt(t,e);r.push(s,["type",n??Lt(l,f,e)])}else i==="table.init"?r.push(rt(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(rt(t[0])?t.shift():0,rt(t[0])?t.shift():0):i.startsWith("table.")?r.push(rt(t[0])?t.shift():0):i==="memory.init"?(r.push(...rt(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"))&&rt(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(T.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(St[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(Ot(n,e),...yt(n,e),"end");else if(s==="if"){let l=[],f=[];n.at(-1)?.[0]==="else"&&(f=yt(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=yt(n.pop().slice(1),e));let c=[s];H(n[0])&&c.push(n.shift()),c.push(Ot(n,e)),r.push(...yt(n,e),...c,...l),f.length&&r.push("else",...f),r.push("end")}else if(s==="try_table"){for(r.push(s),H(n[0])&&r.push(n.shift()),r.push(Ot(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(...yt(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(...yt(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(...yt(n,e),s,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(i)}return r}var Lt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),se=(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},Ut=t=>{let e=se(t,"param"),r=se(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},Dt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...Ut(t)];let[,r]=t.shift(),[i,s]=Ut(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]]},Ot=(t,e)=>{let[r,i,s]=Dt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??Lt(i,s,e)]},re=(t,e)=>{let r=H(t[0])&&t.shift();return r&&(r in e?T(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Te=([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(f=>Array.isArray(f)&&(f[0]==="descriptor"||f[0]==="describes")?(n.push(f),!1):!0)),[s,...t]=t,s==="func"?(t=Ut(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=se(t,"field"):s==="array"&&([t]=t);let l=[s,t,r,i];return n.length&&(l.desc=n),l},ne=[([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 f=(t.desc??[]).flatMap(([a,y])=>[a==="descriptor"?77:76,...I(N(y,e.type))]),c=(a,y)=>a==="func"?[pt.func,...C(y[0].map(m=>K(m,e))),...C(y[1].map(m=>K(m,e)))]:a==="array"?[pt.array,...qt(y,e)]:a==="struct"?[pt.struct,...C(y.map(m=>qt(m,e)))]:a==="cont"?[pt.cont,...I(N(y[0]??y,e.type))]:[pt[a]];if(l){let[a,y]=l,m=Array.from({length:y},(_,d)=>{let k=e.type[a+d],x=k.slice(0,4);return k.desc&&(x.desc=k.desc),ne[D.type](x,e)});return[pt.rec,...C(m)]}else if(s==="sub"||n?.length)return[pt[s],...C(n.map(a=>N(a,e.type))),...f,...c(r,i)];return[...f,...c(r,i)]},([t,e,[r,...i]],s)=>{let n,l=ee[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(l=32);let[[,c]]=i;n=I(N(c,s.type))}else if(r==="tag"){let[[,f]]=i;n=[0,...I(N(f,s.type))]}else r==="memory"?n=Ft(i):r==="global"?n=qt(i[0],s):r==="table"?n=[...K(i.pop(),s),...Ft(i)]:T(`Unknown kind ${r}`);return[...C(t),...C(e),l,...n]},([[,t]],e)=>I(N(t,e.type)),(t,e)=>{let r=Ft(t),i=K(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...At(s,e)]:[...i,...r]},(t,e)=>Ft(t),([t,e],r)=>[...qt(t,r),...At(e,r)],([t,[e,r]],i)=>[...C(t),ee[e],...I(N(r,i[e]))],([t],e)=>I(N(t,e.func)),(t,e)=>{let r=0,i=0,s=0,n=0,l,f,c;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=N(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=N(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(f=t.shift(),f[0]==="offset"&&([,f]=f),f=At(f,e)):i||(r=1),P[t[0]]||t[0]?.[0]==="ref"?c=K(t.shift(),e):t[0]==="func"?c=[P[t.shift()]]:c=[P.func],t=t.map(y=>(y[0]==="item"&&(y=y.length===3&&y[1]==="ref.func"?y[2]:y[1]),y[0]==="ref.func"&&([,y]=y),typeof y!="string"&&(s=1),y)),c[0]!==P.funcref&&(n=1,s=1);let a=s<<2|(r||i?i:!!l||n)<<1|(r||i);return[a,...a===0?f:a===1?[0]:a===2?[...I(l||0),...f,0]:a===3?[0]:a===4?f:a===5?c:a===6?[...I(l||0),...f,...c]:c,...C(t.map(s?y=>At(typeof y=="string"?["ref.func",y]:y,e):y=>I(N(y,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[N(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[,...y]=t.shift();if(H(y[0])){let m=y.shift();m in e.local?T(`Duplicate local ${m}`):e.local[m]=e.local.length}e.local.push(...y)}e.meta={};let n=Ce(t,e),l=e.local.slice(i.length).reduce((y,m)=>(m==y[y.length-1]?.[1]?y[y.length-1][0]++:y.push([1,m]),y),[]),f=C(l.map(([y,m])=>[...I(y),...K(m,e)])),c=e.import.filter(y=>y[2][0]==="func").length+s;for(let y in e.meta){for(let m of e.meta[y])m[0]+=f.length;((e.metadata??={})[y]??=[]).push([c,e.meta[y]])}e.local=e.block=e.meta=null;let a=C([...f,...n]);return(e.codeSizePrefix??=[])[s]=a.length-f.length-n.length,a},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=N(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=N(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??T("Bad offset",r)),[...i?[2,...I(i),...At(r,e)]:r?[0,...At(r,e)]:[1],...C(t.flatMap(s=>qr(s)??[...s]))]},(t,e)=>I(e.data.length),([[,t]],e)=>[0,...I(N(t,e.type))]],K=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[P.refnull,98,...I(N(t[2][1],e.type))]:P[t[2]]?[P[t[2]]]:[P.refnull,...I(N(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[P.ref,98,...I(N(t[1][1],e.type))]:[P.ref,...I(P[t[t.length-1]]||N(t[t.length-1],e.type))]:[P[t]??T(`Unknown type ${t}`)],qt=(t,e,r=t[0]==="mut"?1:0)=>[...K(r?t[1]:t,e),r],Fe={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...I(N(i,e.elem)),...I(N(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"?K(r[1],e):I(N(r[1],e.type)):[P.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"?K(r[1],e):I(N(r[1],e.type)):[P.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(),f=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;f<=1?s.push(f,...I(N(l[1],e.tag)),...I(gt(l[2],e.block))):s.push(f,...I(gt(l[1],e.block))),n++}return e.block.push(1),[...i,...I(n),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...I(N(i,e.type)),...I(N(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||H(t[0]));)r.push(...I(gt(t.shift(),e.block))),i++;return[...I(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?C(r.map(i=>K(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...I(N(r[1],e.type))]:P[r]?[P[r]]:I(N(r,e.type))},memarg:(t,e,r)=>Ee(t,r,rt(t[0])&&!ie(t[0])?N(t.shift(),e.memory):0),opt_memory:(t,e)=>I(N(rt(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=K(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=gt(t.shift(),e.block),i=K(t.shift(),e),s=K(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(s[0]!==P.ref)<<1|i[0]!==P.ref,...I(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 f=0;f<r;f++)l[f]=Et[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(Et[e](t.shift()),l*s);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(Rt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&T("invalid lane length"),e},memlane:(t,e,r)=>{let i=H(t[0])||rt(t[0])&&(ie(t[1])||rt(t[1]))?N(t.shift(),e.memory):0;return[...Ee(t,r,i),...I(Rt(t.shift()))]},"*":t=>I(t.shift()),labelidx:(t,e)=>I(gt(t.shift(),e.block)),laneidx:t=>[Rt(t.shift(),255)],funcidx:(t,e)=>I(N(t.shift(),e.func)),typeidx:(t,e)=>I(N(t.shift(),e.type)),tableidx:(t,e)=>I(N(t.shift(),e.table)),memoryidx:(t,e)=>I(N(t.shift(),e.memory)),globalidx:(t,e)=>I(N(t.shift(),e.global)),localidx:(t,e)=>I(N(t.shift(),e.local)),dataidx:(t,e)=>I(N(t.shift(),e.data)),elemidx:(t,e)=>I(N(t.shift(),e.elem)),tagidx:(t,e)=>I(N(t.shift(),e.tag)),"memoryidx?":(t,e)=>I(N(rt(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),I(s)},i32:t=>Y(t.shift()),i64:t=>xt(t.shift()),f32:t=>dt(t.shift()),f64:t=>_t(t.shift()),v128:t=>te(t.shift()),typeidx_field:(t,e)=>{let r=N(t.shift(),e.type);return[...I(r),...I(N(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...I(N(t.shift(),e.type)),...I(t.shift())],typeidx_dataidx:(t,e)=>[...I(N(t.shift(),e.type)),...I(N(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...I(N(t.shift(),e.type)),...I(N(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...I(N(t.shift(),e.type)),...I(N(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...I(N(t.shift(),e.data)),...I(N(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...I(N(t.shift(),e.memory)),...I(N(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...I(N(t.shift(),e.table)),...I(N(t.shift(),e.table))],cont_bind:(t,e)=>[...I(N(t.shift(),e.type)),...I(N(t.shift(),e.type))],switch_cont:(t,e)=>[...I(N(t.shift(),e.type)),...I(N(t.shift(),e.tag))],resume:(t,e)=>{let r=I(N(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...I(N(n,e.tag))):i.push(0,...I(N(n,e.tag)),...I(gt(l,e.block))),s++}return[...r,...I(s),...i]},resume_throw:(t,e)=>{let r=I(N(t.shift(),e.type)),i=I(N(t.shift(),e.tag)),s=[],n=0;for(;t[0]?.[0]==="on";){let[,l,f]=t.shift();f==="switch"?s.push(1,...I(N(l,e.tag))):s.push(0,...I(N(l,e.tag)),...I(gt(f,e.block))),n++}return[...r,...i,...I(n),...s]},resume_throw_ref:(t,e)=>{let r=I(N(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...I(N(n,e.tag))):i.push(0,...I(N(n,e.tag)),...I(gt(l,e.block))),s++}return[...r,...I(s),...i]}},Ct={};(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(" "),St[n]=r?[r,...I(i)]:[i],l&&(Ct[n]=Fe[l])))})(St);var Ce=(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&&(T.loc=s.loc),T(`Unknown instruction ${s[0]}`));let[...n]=St[s]||T(`Unknown instruction ${s}`);if(Ct[s]&&(s==="select"&&t[0]?.length?n[0]++:Ct[s]===Fe.reftype&&!s.endsWith("_null")&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...Ct[s](t,e,s))),i.length){for(let[l,f]of i)(e.meta[l]??=[]).push([r.length,f]);i=[]}r.push(...n)}return r.push(11),r},At=(t,e)=>Ce(yt([t],e),e),N=(t,e,r)=>(r=H(t)?e[t]:+t,r in e?r:T(`Unknown ${e.name} ${t}`)),gt=(t,e,r)=>(r=H(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?T(`Bad label ${t}`):r),Er=t=>{let e,r,i,s;for(;ie(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:T(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&T(`Bad offset ${r}`),(e<=0||e>4294967295)&&T(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&T(`Bad align ${e}`),[e,r]},Ee=(t,e,r=0)=>{let[i,s]=Er(t),n=(i??Or(e))|(r&&64);return r?[...I(n),...I(r),...I(s??0)]:[...I(n),...I(s??0)]},Or=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)},qr=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(Y.parse(n)&511&255):e==="i16"?(s.setInt16(0,Y.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,Y.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(...dt(n)):e==="f64"&&i.push(..._t(n));return i},Ft=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(a=>Array.isArray(a)&&a[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),f=e?a=>{if(typeof a=="bigint")return a;let y=typeof a=="string"?a.replaceAll("_",""):String(a);return BigInt(y)}:Rt,c=s>=0?I(s):[];return n?[l,...I(f(t.shift())),...I(f(t.shift())),...c]:[l,...I(f(t.shift())),...c]},Rt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?Y.parse(t):typeof t=="number"?t:T(`Bad int ${t}`);return r>e?T(`Value out of range ${t}`):r},C=t=>[...I(t.length),...t.flat()];function Re(t,e={}){typeof t=="string"&&(t=lt(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(f=>s||!n(f)).map(f=>l(f)).join(i);function n(f){return typeof f=="string"&&f[1]===";"}function l(f,c=0){if(!Array.isArray(f))return f;let a=f[0];if(!a)return"";let y=!1;if(a==="try_table"){let d=1;for(typeof f[d]=="string"&&f[d][0]==="$"&&(a+=" "+f[d++]),Array.isArray(f[d])&&(f[d][0]==="result"||f[d][0]==="type")&&(a+=" "+l(f[d++],c));Array.isArray(f[d])&&/^catch/.test(f[d][0]);)a+=" "+l(f[d++],c).trim();for(;d<f.length;d++)a+=Array.isArray(f[d])?i+r.repeat(c+1)+l(f[d],c+1):" "+f[d];return`(${a+i+r.repeat(c)})`}let m=!!i&&f.length<4&&!f.some(d=>typeof d=="string"&&d[0]===";"&&d[1]===";"),_=r.repeat(c+1);for(let d=1;d<f.length;d++){let k=f[d]?.valueOf?.()??f[d];if(typeof k=="string"&&k[1]===";"){if(!s)continue;if(k[0]===";")if(i)a+=i+_+k.trimEnd(),y=!0;else{let x=a[a.length-1];x&&x!==" "&&x!=="("&&(a+=" "),a+=k.trimEnd()+`
5
- `}else{let x=a[a.length-1];x&&x!==" "&&x!=="("&&(a+=" "),a+=k.trimEnd()}}else if(Array.isArray(k))m&&(m=k.every(x=>!Array.isArray(x))),a+=i+_+l(k,c+1),y=!1;else if(f[0]==="data")m=!1,(i||a[a.length-1]!==")")&&(a+=i||" "),a+=_+k,y=!1;else{let x=a[a.length-1];y&&i?a+=i+_:x===`
6
- `?a+="":(x&&x!==")"&&x!==" "||i||x===")")&&(a+=" "),a+=k,y=!1}}return m?`(${a.replaceAll(i+_+"("," (")})`:`(${a+i+r.repeat(c)})`}}var Ue=(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},Pt=(t,e,r)=>t.splice(e,0,r),Fr=0,ft=t=>`$__${t}${Fr++}`,Cr=(t,e)=>{let r=new Set;if(G(t,a=>{Array.isArray(a)&&a[0]==="ref.func"&&r.add(a[1])}),!r.size)return t;let i=ft("fntbl"),s=[...r],n=Object.fromEntries(s.map((a,y)=>[a,y])),l=Ue(t,"func"),f=l.length?l[0].idx:t[0]==="module"?1:0;Pt(t,f,["table",i,"funcref",["elem",...s]]);let c={};return G(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let y=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!y)return;let m=[],_=[];for(let d of a){if(Array.isArray(d)&&d[0]==="param")for(let k=1;k<d.length;k++)d[k][0]!=="$"&&m.push(d[k]);if(Array.isArray(d)&&d[0]==="result")for(let k=1;k<d.length;k++)_.push(d[k])}c[y]={params:m,results:_}}),tt(t,(a,y,m)=>{if(!(!Array.isArray(a)||!y)){if(a[0]==="ref.func"&&n[a[1]]!==void 0&&(y[m]=["i32.const",n[a[1]]]),a[0]==="call_ref"){let _=a[1],d=a.slice(2);y[m]=["call_indirect",i,["type",_],...d]}if(a[0]==="return_call_ref"){let _=a[1],d=a.slice(2);y[m]=["return_call_indirect",i,["type",_],...d]}}}),t},Rr={"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)=>(tt(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=Rr[r[0]];if(!n)return;let[l,f]=n,c=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...c,[`${l}.const`,f]],[`${l}.const`,f]]}),t),Le={"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}},Ur=(t,e)=>{let r=new Set;if(G(t,s=>{Array.isArray(s)&&Le[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:f,min:c,max:a}=Le[s],y=ft(`trunc_${n}_${l}_${f?"s":"u"}`);i[s]=y;let m=`${n}.trunc_${l}_${f?"s":"u"}`,_=n==="i64"?0n:0,d=["func",y,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,_]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof c=="bigint"?Number(c):c]],["then",[`${n}.const`,c]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof a=="bigint"?Number(a):a]],["then",[`${n}.const`,a]],["else",[m,["local.get","$v"]]]]]]]]];t.push(d)}return tt(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t},Dr=(t,e)=>{let r=new Set,i=new Set;G(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0;r.add(`${f}_${c}`)}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0;i.add(f)}}});let s={},n={};for(let l of r){let[f,c]=l.split("_").map(Number),a=ft(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=a;let y=f?["i32.store8",f]:["i32.store8"],m=c?["i32.load8_u",c]:["i32.load8_u"];t.push(["func",a,["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"]]],[...y,["i32.add",["local.get","$dst"],["local.get","$i"]],[...m,["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 f=ft(`memset${l===0?"":"_"+l}`);n[l]=f;let c=l?["i32.store8",l]:["i32.store8"];t.push(["func",f,["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"]]],[...c,["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 tt(t,(l,f,c)=>{if(!(!Array.isArray(l)||!f)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,y=typeof l[2]=="number"?l[2]:0,m=l.filter(_=>Array.isArray(_)||typeof _=="string"&&_[0]==="$");f[c]=["call",s[`${a}_${y}`],...m]}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0,y=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");f[c]=["call",n[a],...y]}}}),t},Pr=(t,e)=>{let r=!1;return G(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&tt(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},Wr=(t,e)=>(tt(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),jr=(t,e)=>{let r={};G(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 f=s[l];if(Array.isArray(f)&&(f[0]==="i32.const"||f[0]==="i64.const"||f[0]==="f32.const"||f[0]==="f64.const")){r[n]={type:f[0].split(".")[0],value:f[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]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let c=n.split(".")[0],a=c==="i64"?BigInt(l[1]):Number(l[1]),y=c==="i64"?BigInt(f[1]):Number(f[1]);return[`${c}.const`,a+y]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let c=n.split(".")[0],a=c==="i64"?BigInt(l[1]):Number(l[1]),y=c==="i64"?BigInt(f[1]):Number(f[1]);return[`${c}.const`,a-y]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let c=n.split(".")[0],a=c==="i64"?BigInt(l[1]):Number(l[1]),y=c==="i64"?BigInt(f[1]):Number(f[1]);return[`${c}.const`,a*y]}}return s};return tt(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let f=2;f<s.length;f++)if(Array.isArray(s[f])){let c=i(s[f]);c!==s[f]&&(s[f]=c)}}}),t},Gr=(t,e)=>{let r=new Map,i=[];if(G(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null,a=[];for(let y of f)if(Array.isArray(y)&&y[0]==="result")for(let m=1;m<y.length;m++)a.push(y[m]);a.length>1&&c&&r.set(c,a)}),!r.size)return t;let s=Math.max(...[...r.values()].map(f=>f.length)),n={};for(let[f,c]of r)for(let a=1;a<c.length;a++){let y=c[a];if(n[y]||(n[y]=[]),n[y].length<a){let m=ft(`ret_${y}_${n[y].length}`);n[y].push(m),i.push(["global",m,["mut",y],[`${y}.const`,y==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let f of i.reverse())Pt(t,l,f);return tt(t,(f,c,a)=>{if(!Array.isArray(f)||f[0]!=="func")return;let y=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!y||!r.has(y))return;let m=r.get(y);for(let _=0;_<f.length;_++)if(Array.isArray(f[_])&&f[_][0]==="result"){f[_]=["result",m[0]];break}}),t},Mt={i32:4,i64:8,f32:4,f64:8},Hr=(t,e)=>{let r=new Map,i=new Map,s=1;if(G(t,x=>{if(!Array.isArray(x)||x[0]!=="type")return;let h=typeof x[1]=="string"&&x[1][0]==="$"?x[1]:null;if(h){for(let $ of x)if(Array.isArray($)){if($[0]==="struct"){let o=[];for(let u of $)if(Array.isArray(u)&&u[0]==="field"){let g=typeof u[1]=="string"&&u[1][0]==="$"?u[1]:null,p=g?u[2]:u[1],A=Array.isArray(p)&&p[0]==="mut"?p[1]:p;o.push({name:g,type:A})}r.set(h,{kind:"struct",fields:o}),i.set(h,s++)}if($[0]==="array"){let o=$[1],u=Array.isArray(o)&&o[0]==="mut"?o[1]:o;r.set(h,{kind:"array",elemType:u}),i.set(h,s++)}}}}),!r.size)return t;let n=Ue(t,"memory").length>0,l=ft("alloc"),f=ft("heap_ptr"),c=t[0]==="module"?1:0;n||Pt(t,c,["memory",1]),Pt(t,c+1,["global",f,["mut","i32"],["i32.const",1024]]);let a=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",f]],["global.set",f,["i32.add",["global.get",f],["local.get","$size"]]],["local.get","$ptr"]];t.push(a);let y=x=>{let h=4;for(let $ of x.fields)h+=Mt[$.type]||4;return h},m=(x,h)=>{let $=4;for(let o=0;o<h;o++)$+=Mt[x.fields[o].type]||4;return $},_=(x,h)=>{for(let $=0;$<x.fields.length;$++)if(x.fields[$].name===h)return $;return-1},d=0,k=()=>`$__gc_tmp${d++}`;return G(t,x=>{if(!Array.isArray(x)||x[0]!=="func")return;let h=!1,$=!1,o=!1,u=!1;if(G(x,p=>{Array.isArray(p)&&((p[0]==="struct.new"||p[0]==="struct.new_default")&&(h=!0),(p[0]==="array.new"||p[0]==="array.new_default")&&($=!0,o=!0,u=!0))}),!h&&!$)return;let g=1;for(let p=1;p<x.length;p++){let A=x[p];if(Array.isArray(A)&&(A[0]==="param"||A[0]==="result"||A[0]==="local"||A[0]==="export"||A[0]==="type"))g=p+1;else if(typeof A=="string"&&A[0]==="$")g=p+1;else if(!Array.isArray(A))g=p+1;else break}h&&x.splice(g++,0,["local","$__gc_ptr","i32"]),$&&x.splice(g++,0,["local","$__gc_aptr","i32"]),o&&x.splice(g++,0,["local","$__gc_alen","i32"]),u&&x.splice(g++,0,["local","$__gc_aidx","i32"])}),tt(t,(x,h,$)=>{if(!(!Array.isArray(x)||!h)){if(x[0]==="struct.new"||x[0]==="struct.new_default"){let o=x[1],u=r.get(o);if(!u||u.kind!=="struct")return;let g=y(u),p=i.get(o),A=x.slice(2),b="$__gc_ptr",M=[["local.set",b,["call",l,["i32.const",g]]],["i32.store",["local.get",b],["i32.const",p]]];if(x[0]==="struct.new")for(let z=0;z<u.fields.length;z++){let v=u.fields[z],S=m(u,z),w=v.type==="i64"?"i64.store":v.type==="f32"?"f32.store":v.type==="f64"?"f64.store":"i32.store";M.push([w,["i32.add",["local.get",b],["i32.const",S]],A[z]||[`${v.type}.const`,0]])}else for(let z=0;z<u.fields.length;z++){let v=u.fields[z],S=m(u,z),w=v.type==="i64"?"i64.store":v.type==="f32"?"f32.store":v.type==="f64"?"f64.store":"i32.store",B=v.type==="i64"?["i64.const",0n]:v.type==="f32"?["f32.const",0]:v.type==="f64"?["f64.const",0]:["i32.const",0];M.push([w,["i32.add",["local.get",b],["i32.const",S]],B])}M.push(["local.get",b]),h[$]=["block",["result","i32"],...M]}if(x[0]==="struct.get"){let o=x[1],u=x[2],g=x[3],p=r.get(o);if(!p||p.kind!=="struct")return;let A=typeof u=="string"&&u[0]==="$"?_(p,u):parseInt(u);if(A<0)return;let b=p.fields[A],M=m(p,A),z=b.type==="i64"?"i64.load":b.type==="f32"?"f32.load":b.type==="f64"?"f64.load":"i32.load";h[$]=[z,["i32.add",g,["i32.const",M]]]}if(x[0]==="struct.set"){let o=x[1],u=x[2],g=x[3],p=x[4],A=r.get(o);if(!A||A.kind!=="struct")return;let b=typeof u=="string"&&u[0]==="$"?_(A,u):parseInt(u);if(b<0)return;let M=A.fields[b],z=m(A,b),v=M.type==="i64"?"i64.store":M.type==="f32"?"f32.store":M.type==="f64"?"f64.store":"i32.store";h[$]=[v,["i32.add",g,["i32.const",z]],p]}if(x[0]==="array.new"||x[0]==="array.new_default"){let o=x[1],u=r.get(o);if(!u||u.kind!=="array")return;let g=i.get(o),p=Mt[u.elemType]||4,A=x[0]==="array.new"?x[2]:null,b=x[0]==="array.new"?x[3]:x[2],M="$__gc_aptr",z="$__gc_alen",v="$__gc_aidx",S=u.elemType==="i64"?"i64.store":u.elemType==="f32"?"f32.store":u.elemType==="f64"?"f64.store":"i32.store",w=[["local.set",z,b],["local.set",M,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",z],["i32.const",p]]]]],["i32.store",["local.get",M],["i32.const",g]],["i32.store",["i32.add",["local.get",M],["i32.const",4]],["local.get",z]]];A&&w.push(["local.set",v,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",v],["local.get",z]]],[S,["i32.add",["i32.add",["local.get",M],["i32.const",8]],["i32.mul",["local.get",v],["i32.const",p]]],A],["local.set",v,["i32.add",["local.get",v],["i32.const",1]]],["br","$loop"]]]),w.push(["local.get",M]),h[$]=["block",["result","i32"],...w]}if(x[0]==="array.get"){let o=x[1],u=x[2],g=x[3],p=r.get(o);if(!p||p.kind!=="array")return;let A=Mt[p.elemType]||4,b=p.elemType==="i64"?"i64.load":p.elemType==="f32"?"f32.load":p.elemType==="f64"?"f64.load":"i32.load";h[$]=[b,["i32.add",["i32.add",u,["i32.const",8]],["i32.mul",g,["i32.const",A]]]]}if(x[0]==="array.set"){let o=x[1],u=x[2],g=x[3],p=x[4],A=r.get(o);if(!A||A.kind!=="array")return;let b=Mt[A.elemType]||4,M=A.elemType==="i64"?"i64.store":A.elemType==="f32"?"f32.store":A.elemType==="f64"?"f64.store":"i32.store";h[$]=[M,["i32.add",["i32.add",u,["i32.const",8]],["i32.mul",g,["i32.const",b]]],p]}if(x[0]==="array.len"){let o=x[1];h[$]=["i32.load",["i32.add",o,["i32.const",4]]]}}}),t},Vr=(t,e)=>{let r=new Map,i=1;return G(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&&tt(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let f=s[1],c=null;Array.isArray(f)&&f[0]==="ref"&&(c=f[1]==="null"?f[2]:f[1]);let a=s[2],y=r.get(c);y!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",a],["then",["i32.const",0]],["else",["i32.eq",["i32.load",a],["i32.const",y]]]])}if(s[0]==="ref.cast"){let f=s[1],c=null,a=!1;Array.isArray(f)&&f[0]==="ref"&&(f[1]==="null"?(a=!0,c=f[2]):c=f[1]);let y=s[2],m=r.get(c);if(m!==void 0){let _=ft("cast");a?n[l]=["block",["result","i32"],["local",_,"i32"],["local.set",_,y],["if",["i32.and",["i32.ne",["local.get",_],["i32.const",0]],["i32.ne",["i32.load",["local.get",_]],["i32.const",m]]],["then",["unreachable"]]],["local.get",_]]:n[l]=["block",["result","i32"],["local",_,"i32"],["local.set",_,y],["if",["i32.or",["i32.eqz",["local.get",_]],["i32.ne",["i32.load",["local.get",_]],["i32.const",m]]],["then",["unreachable"]]],["local.get",_]]}}if(s[0]==="br_on_cast"){let f=s[1],c=s[2],a=s[3],y=s[4],m=null;Array.isArray(a)&&a[0]==="ref"&&(m=a[1]==="null"?a[2]:a[1]);let _=r.get(m);if(_!==void 0){let d=ft("brcast");n[l]=["block",["result","i32"],["local",d,"i32"],["local.set",d,y],["br_if",f,["i32.and",["i32.ne",["local.get",d],["i32.const",0]],["i32.eq",["i32.load",["local.get",d]],["i32.const",_]]]],["local.get",d]]}}if(s[0]==="br_on_cast_fail"){let f=s[1],c=s[2],a=s[3],y=s[4],m=null;Array.isArray(a)&&a[0]==="ref"&&(m=a[1]==="null"?a[2]:a[1]);let _=r.get(m);if(_!==void 0){let d=ft("brfail");n[l]=["block",["result","i32"],["local",d,"i32"],["local.set",d,y],["br_if",f,["i32.or",["i32.eqz",["local.get",d]],["i32.ne",["i32.load",["local.get",d]],["i32.const",_]]]],["local.get",d]]}}}}),t},Wt=[["funcref",["ref.func","call_ref","return_call_ref"],Cr],["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"],Ur],["bulk_memory",["memory.copy","memory.fill"],Dr],["return_call",["return_call","return_call_indirect"],Pr],["i31ref",["ref.i31","i31.get_s","i31.get_u"],Wr],["extended_const",["global.get"],jr],["multi_value",[],Gr],["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"],Hr],["ref_cast",["ref.test","ref.cast","br_on_cast","br_on_cast_fail"],Vr]],ks=Object.fromEntries(Wt.map(t=>[t[0],t[1]])),Yr=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 Wt)r[i[0]]=e?e.has("all")||e.has(i[0]):!0;return r},Xr=t=>{let e=new Set;return G(t,r=>{if(typeof r=="string")for(let i of Wt)i[1].some(n=>r===n||r.startsWith(n+" "))&&e.add(i[0])}),G(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")&&G(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),G(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 le(t,e=!0){typeof t=="string"&&(t=lt(t)),t=Qt(t),e=Yr(e);let r=Xr(t),i={uid:0};for(let s of Wt){let n=s[2];r.has(s[0])&&e[s[0]]!==!1&&(t=n(t,i))}return t}var Zr=6,Ze=16,Q=t=>Array.isArray(t)?t.map(Q):t,F=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)F(t[s],e,t,s)},j=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++)j(t[n],e,t,n);let s=e(t,r,i);return s!==void 0&&r&&(r[i]=s),s!==void 0?s:t},De=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};var Pe=t=>{try{return bt(t).length}catch{return 1/0}},nt=(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(!nt(t[r],e[r]))return!1;return!0},vt=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}},Kr=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,f=(v,S,w,B=!1)=>{let E=typeof S[1]=="string"&&S[1][0]==="$",Z=E?S[1]:w,V=!B&&S.some(O=>Array.isArray(O)&&O[0]==="export"),U={node:S,idx:w,used:V,isImport:B};return v.set(Z,U),E&&v.set(w,U),l.set(S,U),U},c=0,a=0,y=0,m=0,_=0,d=[],k=[],x=[],h=[];for(let v of t.slice(1)){if(!Array.isArray(v))continue;let S=v[0];if(S==="type")f(i,v,y++);else if(S==="func")f(e,v,c++);else if(S==="global")f(r,v,a++);else if(S==="table")f(s,v,m++);else if(S==="memory")f(n,v,_++);else if(S==="import")for(let w of v)Array.isArray(w)&&(w[0]==="func"?f(e,w,c++,!0):w[0]==="global"?f(r,w,a++,!0):w[0]==="table"?f(s,w,m++,!0):w[0]==="memory"&&f(n,w,_++,!0));else S==="export"?x.push(v):S==="start"?h.push(v):S==="elem"?d.push(v):S==="data"&&k.push(v)}let $=[],o=v=>{v&&!v.scanned&&$.push(v)},u=v=>{let S=e.get(v);S&&(S.used||(S.used=!0),o(S))},g=v=>{let S=r.get(v);S&&(S.used=!0)},p=v=>{let S=s.get(v);S&&(S.used=!0)},A=v=>{typeof v=="string"&&v[0]!=="$"&&(v=+v);let S=n.get(v);S&&(S.used=!0)},b=v=>{let S=i.get(v);S&&(S.used=!0)};for(let v of x)for(let S of v){if(!Array.isArray(S))continue;let[w,B]=S;w==="func"?u(B):w==="global"?g(B):w==="table"?p(B):w==="memory"&&A(B)}for(let v of h){let S=v[1];typeof S=="string"&&S[0]!=="$"&&(S=+S),u(S)}for(let v of d)F(v,S=>{Array.isArray(S)&&S[0]==="ref.func"?u(S[1]):typeof S=="string"&&S[0]==="$"&&u(S)});for(let v of k){let S=v[1];Array.isArray(S)&&S[0]==="memory"?A(S[1]):typeof S=="string"&&S[0]==="$"?A(S):Array.isArray(S)&&A(0)}for(let v of[e,r,s,n])for(let S of v.values())S.used&&o(S);if(!(x.length>0||h.length>0||d.length>0||$.length>0)){for(let v of[e,r,s,n])for(let S of v.values())S.used=!0;return t}for(;$.length;){let v=$.pop();v.scanned||(v.scanned=!0,!v.isImport&&F(v.node,S=>{if(!Array.isArray(S)){typeof S=="string"&&S[0]==="$"&&u(S);return}let[w,B]=S;if(w==="call"||w==="return_call"||w==="ref.func")u(B);else if(w==="global.get"||w==="global.set")g(B);else if(w==="type")b(B);else if(w==="call_indirect"||w==="return_call_indirect")for(let E of S)typeof E=="string"&&E[0]==="$"&&p(E);typeof w=="string"&&(w.startsWith("memory.")||w.includes(".load")||w.includes(".store"))&&A(0)}))}let z=["module"];for(let v of t.slice(1)){if(!Array.isArray(v)){z.push(v);continue}let S=v[0];if(S==="func"||S==="global"||S==="type")l.get(v)?.used&&z.push(v);else if(S==="import"){let w=!1;for(let B of v){if(!Array.isArray(B))continue;if(l.get(B)?.used){w=!0;break}}w&&z.push(v)}else z.push(v)}return z},We=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),Ke=new ArrayBuffer(8),ye=new Float64Array(Ke),It=new Uint32Array(Ke),Qe=new ArrayBuffer(4),pe=new Float32Array(Qe),ge=new Int32Array(Qe),X=t=>(t>>>0).toString(16).padStart(8,"0"),Qr=t=>{let e="",r=1;for(let i=15;i>=0;i--){let s=15-parseInt(t[i],16)+r;e=(s&15).toString(16)+e,r=s>>4}return e},Nt=t=>{let e=t.toString(16);return e[0]==="-"?Qr(e.slice(1).padStart(16,"0")):e.padStart(16,"0")},W="0x0000000000000000",fe="0x0000000000000001",Zt="0xffffffffffffffff",mt=t=>{if(typeof t=="string"){let e=t.replaceAll("_","");if(e.length===18&&e[1]==="x")return"0x"+e.slice(2).toLowerCase();let r=e[0]==="-",i=e[0]==="-"||e[0]==="+"?e.slice(1):e;return"0x"+Nt(r?-BigInt(i):BigInt(i))}return typeof t=="bigint"?"0x"+Nt(BigInt(String(t))):"0x"+Nt(BigInt(Math.trunc(t)||0))},je=t=>(parseInt(t[2],16)^8).toString(16)+t.slice(3),jt=t=>parseInt(t.slice(10),16)|0,at=t=>parseInt(t.slice(2,10),16)>>>0,it=t=>t==null?null:"0x"+Nt(t),Bt=t=>{let e=BigInt(t);return e>0x7fffffffffffffffn&&(e=e-0x8000000000000000n-0x8000000000000000n),e},Jr=t=>(ye[0]=t,"0x"+X(It[1])+X(It[0])),ti=t=>(It[1]=parseInt(t.slice(2,10),16),It[0]=parseInt(t.slice(10),16),ye[0]),ei=t=>(pe[0]=t,ge[0]),ri=t=>(ge[0]=t|0,pe[0]),wt=t=>(e,r)=>t(e,r)?1:0,Gt=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,Ht=t=>(e,r)=>t(je(e),je(r))?1:0,Vt=t=>(e,r)=>t(e,r)?1:0,ii={"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":wt((t,e)=>t===e),"i32.ne":wt((t,e)=>t!==e),"i32.lt_s":wt((t,e)=>t<e),"i32.lt_u":Gt((t,e)=>t<e),"i32.gt_s":wt((t,e)=>t>e),"i32.gt_u":Gt((t,e)=>t>e),"i32.le_s":wt((t,e)=>t<=e),"i32.le_u":Gt((t,e)=>t<=e),"i32.ge_s":wt((t,e)=>t>=e),"i32.ge_u":Gt((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=>jt(t),"i32.extend8_s":t=>t<<24>>24,"i32.extend16_s":t=>t<<16>>16,"i64.add":(t,e)=>it(BigInt(t)+BigInt(e)&0xffffffffffffffffn),"i64.sub":(t,e)=>it(BigInt(t)-BigInt(e)&0xffffffffffffffffn),"i64.mul":(t,e)=>it(BigInt(t)*BigInt(e)&0xffffffffffffffffn),"i64.div_s":(t,e)=>e!==W&&!(t==="0x8000000000000000"&&e===Zt)?it(Bt(t)/Bt(e)&0xffffffffffffffffn):null,"i64.div_u":(t,e)=>e!==W&&!(at(t)>>>31)&&!(at(e)>>>31)?it(BigInt(t)/BigInt(e)):null,"i64.rem_s":(t,e)=>e!==W?it(Bt(t)%Bt(e)&0xffffffffffffffffn):null,"i64.rem_u":(t,e)=>e!==W&&!(at(t)>>>31)&&!(at(e)>>>31)?it(BigInt(t)%BigInt(e)):null,"i64.and":(t,e)=>it(BigInt(t)&BigInt(e)&0xffffffffffffffffn),"i64.or":(t,e)=>it((BigInt(t)|BigInt(e))&0xffffffffffffffffn),"i64.xor":(t,e)=>it((BigInt(t)^BigInt(e))&0xffffffffffffffffn),"i64.shl":(t,e)=>it(BigInt(t)<<(BigInt(e)&63n)&0xffffffffffffffffn),"i64.shr_s":(t,e)=>it(Bt(t)>>(BigInt(e)&63n)&0xffffffffffffffffn),"i64.shr_u":(t,e)=>{let r=parseInt(e.slice(10),16)&63,i=at(t),s=parseInt(t.slice(10),16)>>>0,n=r>=32?0:i>>>r,l=r===0?s:r>=32?i>>>r-32:(s>>>r|i<<32-r)>>>0;return"0x"+X(n)+X(l)},"i64.eq":(t,e)=>t===e?1:0,"i64.ne":(t,e)=>t!==e?1:0,"i64.lt_s":Ht((t,e)=>t<e),"i64.lt_u":Vt((t,e)=>t<e),"i64.gt_s":Ht((t,e)=>t>e),"i64.gt_u":Vt((t,e)=>t>e),"i64.le_s":Ht((t,e)=>t<=e),"i64.le_u":Vt((t,e)=>t<=e),"i64.ge_s":Ht((t,e)=>t>=e),"i64.ge_u":Vt((t,e)=>t>=e),"i64.eqz":t=>t===W?1:0,"i64.extend_i32_s":t=>"0x"+X(t>>31)+X(t),"i64.extend_i32_u":t=>"0x00000000"+X(t),"i64.extend8_s":t=>{let e=jt(t)<<24>>24;return"0x"+X(e>>31)+X(e)},"i64.extend16_s":t=>{let e=jt(t)<<16>>16;return"0x"+X(e>>31)+X(e)},"i64.extend32_s":t=>{let e=jt(t);return"0x"+X(e>>31)+X(e)},"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(We(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":We,"i32.reinterpret_f32":ei,"f32.reinterpret_i32":ri,"i64.reinterpret_f64":Jr,"f64.reinterpret_i64":ti,"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((at(t)|0)*4294967296+parseInt(t.slice(10),16)),"f32.convert_i64_u":t=>Math.fround(at(t)*4294967296+parseInt(t.slice(10),16)),"f64.convert_i32_s":t=>t|0,"f64.convert_i32_u":t=>t>>>0,"f64.convert_i64_s":t=>(at(t)|0)*4294967296+parseInt(t.slice(10),16),"f64.convert_i64_u":t=>at(t)*4294967296+parseInt(t.slice(10),16),"f32.demote_f64":t=>Math.fround(t),"f64.promote_f32":t=>Math.fround(t)},si=t=>{let e=t?.indexOf?.("nan");if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),s=(t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n).toString(16).padStart(16,"0"),n=(parseInt(s.slice(0,8),16)|2146435072|(t[0]==="-"?2147483648:0))>>>0;return"0x"+X(n)+s.slice(8)},ni=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),s=(t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n).toString(16).padStart(16,"0");return It[1]=(parseInt(s.slice(0,8),16)|2146435072|(t[0]==="-"?2147483648:0))>>>0,It[0]=parseInt(s.slice(8),16),ye[0]},li=(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 ge[0]=i|2139095040|(t[0]==="-"?2147483648:0)|0,pe[0]},q=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"?parseInt(r.replaceAll("_","")):r)|0};if(e==="i64.const")return{type:"i64",value:mt(r)};if(e==="f32.const"){let i=li(r);return{type:"f32",value:i!==null?i:Math.fround(Number(r))}}if(e==="f64.const"){let i=ni(r),s=i!==null?i:Number(r);return{type:"f64",value:Number.isNaN(s)?NaN:s}}return null},Ge=(t,e)=>{if(t==="i32")return["i32.const",e|0];if(t==="i64")return["i64.const",typeof e=="number"?e:mt(e)];if(t==="f32"){let r=Math.fround(e);return["f32.const",Number.isNaN(r)?"nan":r]}return t==="f64"?["f64.const",Number.isNaN(e)?"nan":e]:null},fi=t=>j(t,e=>{if(!Array.isArray(e))return;let r=ii[e[0]];if(r){if(e.length===2){if(e[0]==="i64.reinterpret_f64"){let n=e[1];if(Array.isArray(n)&&n.length===2&&n[0]==="f64.const"&&typeof n[1]=="string"){let l=si(n[1]);if(l)return["i64.const",l]}}if(e[0]==="f64.reinterpret_i64"){let n=q(e[1]);if(n&&n.type==="i64"){let l=n.value.slice(2),f=parseInt(l.slice(0,8),16)>>>0,c=parseInt(l.slice(8),16)>>>0;if((f&2146435072)===2146435072&&((f&1048575)!==0||c!==0))return["f64.const",(f&2147483648?"-":"")+"nan:0x"+(f&1048575).toString(16).padStart(5,"0")+l.slice(8)]}}let i=q(e[1]);if(!i)return;let s=r(i.value);return s==null?void 0:Ge(De(e[0]),s)}if(e.length===3){let i=q(e[1]),s=q(e[2]);if(!i||!s)return;let n=r(i.value,s.value);return n==null?void 0:Ge(De(e[0]),n)}}}),ot=t=>(e,r)=>{let i=q(e),s=q(r);return i?.value===t?r:s?.value===t?e:null},st=t=>(e,r)=>q(r)?.value===t?e:null,oi={"i32.add":ot(0),"i64.add":ot(W),"i32.sub":st(0),"i64.sub":st(W),"i32.mul":ot(1),"i64.mul":ot(fe),"i32.div_s":st(1),"i32.div_u":st(1),"i64.div_s":st(fe),"i64.div_u":st(fe),"i32.and":ot(-1),"i64.and":ot(Zt),"i32.or":ot(0),"i64.or":ot(W),"i32.xor":ot(0),"i64.xor":ot(W),"i32.shl":st(0),"i32.shr_s":st(0),"i32.shr_u":st(0),"i64.shl":st(W),"i64.shr_s":st(W),"i64.shr_u":st(W)},ai=t=>j(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=oi[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),ci=t=>j(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=q(s);if(n&&n.value>0&&!(n.value&n.value-1)){let f=Math.log2(n.value);if(Number.isInteger(f))return["i32.shl",i,["i32.const",f]]}let l=q(i);if(l&&l.value>0&&!(l.value&l.value-1)){let f=Math.log2(l.value);if(Number.isInteger(f))return["i32.shl",s,["i32.const",f]]}}if(r==="i64.mul"){let n=q(s),l=n?BigInt(n.value):null;if(l!=null&&l>0n&&(l&l-1n)===0n)return["i64.shl",i,["i64.const",l.toString(2).length-1]];let f=q(i),c=f?BigInt(f.value):null;if(c!=null&&c>0n&&(c&c-1n)===0n)return["i64.shl",s,["i64.const",c.toString(2).length-1]]}if(r==="i32.div_u"){let n=q(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=q(s),l=n?BigInt(n.value):null;if(l!=null&&l>0n&&(l&l-1n)===0n)return["i64.shr_u",i,["i64.const",l.toString(2).length-1]]}if(r==="i32.rem_u"){let n=q(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=q(s),l=n?BigInt(n.value):null;if(l!=null&&l>0n&&(l&l-1n)===0n)return["i64.and",i,["i64.const","0x"+Nt(l-1n)]]}}),ui=t=>j(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{condIdx:i,cond:s,thenBranch:n,elseBranch:l}=vt(e),f=q(s);if(!f)return;let c=f.value!==0&&f.value!==W?n:l;if(c&&c.length>1){let a=c.slice(1),y=e.slice(1,i).filter(m=>Array.isArray(m)&&(m[0]==="result"||m[0]==="param"));return y.length?["block",...y,...a]:a.length===1?a[0]:["block",...a]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=q(i);return s?s.value===0||s.value===W?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=q(i);return s?s.value===0||s.value===W?e[2]:e[1]:void 0}}),yi=t=>{if(Array.isArray(t))for(let e of t)Array.isArray(e)&&e[0]==="func"&&gi(e);return t},pi=new Set,gi=t=>{let e=new Map,r=new Map,i=new Map,s=new Map,n=o=>{if(!Array.isArray(o)||o.length!==2||o[0]!=="i32.const"&&o[0]!=="i64.const")return null;let u=typeof o[1]=="string"?Number(o[1].replaceAll("_","")):Number(o[1]);return Number.isFinite(u)?u:null},l=o=>Array.isArray(o)&&o[0]==="i32.const"?n(o):null,f=o=>Array.isArray(o)?o[0]==="i64.reinterpret_f64"&&Array.isArray(o[1])&&o[1][0]==="local.get"&&typeof o[1][1]=="string"?o[1][1]:o[0]==="local.get"&&typeof o[1]=="string"?e.get(o[1])??null:null:null,c=o=>{if(!Array.isArray(o))return null;let u=o[0];if(u==="local.get"&&typeof o[1]=="string")return r.get(o[1])??null;if(u==="call"&&o[1]==="$__ptr_type"&&o.length===3)return f(o[2]);let g=p=>Array.isArray(p)&&p[0]==="i64.shr_u"&&n(p[2])===47?f(p[1]):null;if(u==="i32.and"&&o.length===3){let[p,A]=l(o[2])===15?[o[1],null]:l(o[1])===15?[o[2],null]:[null,null];if(p&&Array.isArray(p)&&p[0]==="i32.wrap_i64")return g(p[1])}if(u==="i32.wrap_i64"&&Array.isArray(o[1])&&o[1][0]==="i64.and"){let p=o[1];if(n(p[2])===15)return g(p[1]);if(n(p[1])===15)return g(p[2])}return null},a=o=>{e.delete(o),r.delete(o),i.delete(o),s.delete(o);for(let[u,g]of e)g===o&&e.delete(u);for(let[u,g]of r)g===o&&r.delete(u)},y=new Map,m=o=>{if(!Array.isArray(o))return pi;let u=y.get(o);if(u)return u;u=new Set,(o[0]==="local.set"||o[0]==="local.tee")&&typeof o[1]=="string"&&u.add(o[1]);for(let g=1;g<o.length;g++)for(let p of m(o[g]))u.add(p);return y.set(o,u),u},_=()=>[new Map(i),new Map([...s].map(([o,u])=>[o,new Set(u)])),new Map(e),new Map(r)],d=(o,u)=>{o.clear();for(let[g,p]of u)o.set(g,p)},k=([o,u,g,p])=>{d(i,o),d(s,u),d(e,g),d(r,p)},x=(o,u,g)=>{if(!Array.isArray(o))return g;let p=o[0];if(p==="i32.eqz")return x(o[1],!u,g);if(p==="i32.and"&&u&&o.length===3)return x(o[1],!0,g),x(o[2],!0,g),g;if(p==="i32.or"&&!u&&o.length===3)return x(o[1],!1,g),x(o[2],!1,g),g;if((p==="i32.eq"||p==="i32.ne")&&o.length===3){let b=c(o[1]),M=l(o[2]);return(b==null||M==null)&&(b=c(o[2]),M=l(o[1])),b!=null&&M!=null&&g.push({x:b,k:M,eq:p==="i32.eq"===u}),g}let A=c(o);return A!=null&&g.push({x:A,k:0,eq:!u}),g},h=o=>{for(let{x:u,k:g,eq:p}of o)if(p)i.set(u,g);else{let A=s.get(u);A||s.set(u,A=new Set),A.add(g)}},$=(o,u,g)=>{if(!Array.isArray(o))return;let p=o[0];if(p==="local.set"||p==="local.tee"){Array.isArray(o[2])&&$(o[2],o,2);let b=o[1];if(typeof b!="string")return;a(b);let M=o[2];if(Array.isArray(M))if(M[0]==="i64.reinterpret_f64"&&Array.isArray(M[1])&&M[1][0]==="local.get"&&typeof M[1][1]=="string")e.set(b,M[1][1]);else if(M[0]==="local.get"&&typeof M[1]=="string"&&e.has(M[1]))e.set(b,e.get(M[1]));else{let z=c(M);z!=null&&r.set(b,z)}return}if(p==="if"){let{condIdx:b}=vt(o);Array.isArray(o[b])&&$(o[b],o,b);let M=o[b],{thenBranch:z,elseBranch:v}=vt(o),S=m(o),w=_();if(h(x(M,!0,[])),z)for(let B=1;B<z.length;B++)$(z[B],z,B);if(k(w),h(x(M,!1,[])),v)for(let B=1;B<v.length;B++)$(v[B],v,B);k(w);for(let B of S)a(B);return}if(p==="loop"){let b=m(o);for(let M of b)a(M);for(let M=1;M<o.length;M++)$(o[M],o,M);for(let M of b)a(M);return}if(p==="block"){for(let b=1;b<o.length;b++)$(o[b],o,b);for(let b of m(o))a(b);return}let A=c(o);if(A!=null&&i.has(A)&&u){u[g]=["i32.const",i.get(A)];return}if((p==="i32.eq"||p==="i32.ne")&&o.length===3){let b=c(o[1]),M=l(o[2]);if((b==null||M==null)&&(b=c(o[2]),M=l(o[1])),b!=null&&M!=null&&s.get(b)?.has(M)&&u){u[g]=["i32.const",p==="i32.eq"?0:1];return}}for(let b=1;b<o.length;b++)$(o[b],o,b)};for(let o=1;o<t.length;o++)$(t[o],t,o)},He=new Set(["unreachable","return","br","br_table"]),mi=t=>(F(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),He.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),He.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},_i=t=>(F(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])))}F(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let f=n[1];typeof f=="string"&&s.add(f)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:f}=r[n],c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;c&&!s.has(c)&&e.splice(l,1)}}),t),Je=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"]),tr=[".store","memory.",".atomic."],R=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||Je.has(e))return!1;for(let r of tr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!R(t[r]))return!1;return!0},hi=new Set(["if","then","else","block","loop","try"]),xi=t=>typeof t=="string"&&!Je.has(t)&&!hi.has(t)&&!tr.some(e=>t.includes(e)),er=t=>{if(!Array.isArray(t)||R(t))return[];let e=t[0];if(e==="local.tee"&&t.length===3)return[["local.set",t[1],t[2]]];if(xi(e)){let r=[];for(let i=1;i<t.length;i++)r.push(...er(t[i]));return r}return[["drop",t]]},di=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return F(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},Ai=t=>{let e=q(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=BigInt(e.value);return r<=63n||r>=0xffffffffffffffc0n}return!1},bi=(t,e)=>Array.isArray(t)&&t[0]==="local.get"&&t.length===2&&typeof t[1]=="string"&&t[1]!==e,rr=t=>t.pure&&t.singleUse||Ai(t.val)||t.copy,Yt=(t,e)=>{for(let[r,i]of t){let s=!1;F(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},oe=(t,e)=>{for(let[r,i]of t){let s=!1;F(i.val,n=>{Array.isArray(n)&&n[0]==="global.get"&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},ir=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(ir(t[r]))return!0;return!1},sr=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(sr(t[r]))return!0;return!1},ae=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(ae(t[r]))return!0;return!1},ce=(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&&rr(s)?Q(s.val):t}let i=e;if(ht(r)){let s=null;F(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=ce(t[s],i);n!==t[s]&&(t[s]=n),s+1<t.length&&Array.isArray(t[s])&&F(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]),Yt(i,l[1])):l[0]==="global.set"&&typeof l[1]=="string"&&(i===e&&(i=new Map(e)),oe(i,l[1])))})}return t},wi=(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 f=t[l];if(!Array.isArray(f))continue;let c=f[0];if(!(c==="param"||c==="result"||c==="local"||c==="type"||c==="export")){if((c==="local.set"||c==="local.tee")&&f.length===3&&typeof f[1]=="string"){let a=ce(f[2],n);a!==f[2]&&(f[2]=a,i=!0),F(f[2],m=>{Array.isArray(m)&&((m[0]==="local.set"||m[0]==="local.tee")&&typeof m[1]=="string"?(n.delete(m[1]),Yt(n,m[1])):m[0]==="global.set"&&typeof m[1]=="string"&&oe(n,m[1]))});let y=s(f[1]);if(Yt(n,f[1]),ae(f[2]))for(let[m,_]of n)_.readsMem&&n.delete(m);n.set(f[1],{val:f[2],pure:R(f[2]),readsMem:ir(f[2]),singleUse:y.gets<=1&&y.sets<=1&&y.tees===0,copy:bi(f[2],f[1])});continue}if(ht(c)&&n.clear(),c==="call"||c==="call_indirect"||c==="return_call"||c==="return_call_indirect")for(let[a,y]of n)sr(y.val)&&n.delete(a);if(c==="local.get"&&f.length===2&&typeof f[1]=="string"){let a=n.get(f[1]);if(a&&rr(a)){let y=Q(a.val);f.length=0,f.push(...Array.isArray(y)?y:[y]),i=!0;continue}}if(c!=="block"&&c!=="loop"&&c!=="if"){let a=Q(f);if(ce(f,n),nt(a,f)||(i=!0),F(f,y=>{Array.isArray(y)&&((y[0]==="local.set"||y[0]==="local.tee")&&typeof y[1]=="string"?(n.delete(y[1]),Yt(n,y[1])):y[0]==="global.set"&&typeof y[1]=="string"&&oe(n,y[1]))}),ae(f))for(let[y,m]of n)m.readsMem&&n.delete(y)}}}return i},$i=(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 f=n[1];if(l[1]!==f||e.has(f))continue;let c=r.get(f)||{gets:0,sets:0,tees:0};if(c.sets!==1||c.gets!==1||c.tees!==0)continue;let a=Q(n[2]);t.splice(s,2,...Array.isArray(a)?[a]:[a]),i=!0,s--}return i},vi=(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 f=n[1];if(l[1]!==f||e.has(f))continue;let c=r.get(f)||{gets:0,sets:0,tees:0};c.sets+c.gets+c.tees<=2||(t.splice(s,2,["local.tee",f,Q(n[2])]),i=!0)}return i},Ii=(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 f=typeof l[1]=="string"?l[1]:null;if(!f||e.has(f))continue;let c=s(f);l[0]==="local.set"&&c.gets===0&&c.tees===0?l.length===3?R(l[2])&&(t.splice(n,1),i=!0):l.length===2&&(t[n]=["drop"],i=!0):l[0]==="local"&&f[0]==="$"&&c.gets===0&&c.sets===0&&c.tees===0&&(t.splice(n,1),i=!0)}return i},ki=(t,e)=>{let r=!1;for(let i=1;i<t.length-1;i++){let s=t[i],n=t[i+1];if(!Array.isArray(s)||s[0]!=="local.set"||s.length!==3||!Array.isArray(n)||n[0]!=="local.set"&&n[0]!=="local.tee"||n.length!==3||n[1]!==s[1]||e.has(s[1])||!R(s[2]))continue;let l=!1;F(n[2],f=>{Array.isArray(f)&&(f[0]==="local.get"||f[0]==="local.tee")&&f[1]===s[1]&&(l=!0)}),!l&&(t.splice(i,1),r=!0,i--)}return r},me=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),ht=t=>t==="block"||t==="loop"||t==="if",ue=t=>(F(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=[];j(e,s=>{me(s)&&i.push(s)});for(let s=0;s<Zr;s++){let n=di(e),l=!1;for(let f of i)wi(f,r,n)&&(l=!0),$i(f,r,n)&&(l=!0),vi(f,r,n)&&(l=!0),Ii(f,r,n)&&(l=!0),ki(f,r)&&(l=!0);if(!l)break}}),t),nr=0,Si=new Set(["export","type","param","result","local"]),$t=t=>{let e=2;for(;e<t.length&&(typeof t[e]=="string"||Array.isArray(t[e])&&Si.has(t[e][0]));)e++;return e},_e=t=>t==="br"||t==="br_if"||t==="br_table",he=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(e==="return_call"||e==="return_call_indirect"||e==="return_call_ref"||e==="try"||e==="try_table"||e==="delegate"||e==="rethrow")return!0;if(_e(e)){for(let r=1;r<t.length;r++)if(typeof t[r]=="number"||typeof t[r]=="string"&&/^\d+$/.test(t[r]))return!0}for(let r=1;r<t.length;r++)if(he(t[r]))return!0;return!1},xe=(t,e)=>{if(!Array.isArray(t))return!1;if((t[0]==="call"||t[0]==="return_call")&&t[1]===e)return!0;for(let r=1;r<t.length;r++)if(xe(t[r],e))return!0;return!1},de=t=>t==="i32"?["i32.const",0]:t==="i64"?["i64.const",0]:t==="f32"?["f32.const",0]:t==="f64"?["f64.const",0]:t==="v128"?["v128.const","i64x2","0","0"]:null,lr=(t,e)=>{let r=!1,i=!1,s=0,n=l=>{if(r||!Array.isArray(l))return;let f=l[0],c=f==="local.set"||f==="local.tee";if((c||f==="local.get")&&l[1]===e){if(c)for(let y=2;y<l.length&&!r;y++)n(l[y]);if(r)return;r=!0,(f==="local.get"||s>0)&&(i=!0);return}let a=f==="if";for(let y=1;y<l.length&&!r;y++){let m=l[y],_=a&&Array.isArray(m)&&(m[0]==="then"||m[0]==="else");_&&s++,n(m),_&&s--}};for(let l of t){if(r)break;n(l)}return r?i:!1},Ae=(t,e)=>{if(!Array.isArray(t))return;let r=t[0];if(r==="export"&&Array.isArray(t[2])&&t[2][0]==="func"&&typeof t[2][1]=="string")e.add(t[2][1]);else if(r==="start"&&typeof t[1]=="string")e.add(t[1]);else if(r==="ref.func"&&typeof t[1]=="string")e.add(t[1]);else if(r==="elem")for(let i of t)typeof i=="string"&&i[0]==="$"&&e.add(i);for(let i of t)Ae(i,e)},Mi=t=>{let e=new Set;for(let r of t)(!Array.isArray(r)||r[0]!=="func")&&Ae(r,e);return e},Bi=t=>{let e=[],r=[],i=null,s=!0,n=0;for(let l=2;l<t.length;l++){let f=t[l];if(typeof f!="string"){if(!Array.isArray(f)){s=!1;break}if(f[0]==="param"){if(typeof f[1]!="string"||f[1][0]!=="$"){s=!1;break}e.push({name:f[1],type:f[2]})}else if(f[0]==="local"){if(typeof f[1]!="string"||f[1][0]!=="$"||!de(f[2])){s=!1;break}r.push({name:f[1],type:f[2]})}else if(f[0]==="result")n+=f.length-1,f.length>1&&(i=f[1]);else if(f[0]==="export"){s=!1;break}else{if(f[0]==="type")continue;break}}}return n>1&&(s=!1),s?{params:e,locals:r,inlResult:i}:null},Ni=t=>{let e=0,r=i=>{if(Array.isArray(i)){e++;for(let s=1;s<i.length;s++)r(i[s])}};for(let i=$t(t);i<t.length;i++)r(t[i]);return e},zi=(t,e,r,i,s)=>{let n=++nr,l=`$__inl${n}`,f=new Map;for(let h of t)f.set(h.name,`$__inl${n}_${h.name.slice(1)}`);for(let h of e)f.set(h.name,`$__inl${n}_${h.name.slice(1)}`);let c=new Map,a=h=>{if(Array.isArray(h)){ht(h[0])&&typeof h[1]=="string"&&h[1][0]==="$"&&!c.has(h[1])&&c.set(h[1],`$__inl${n}L_${h[1].slice(1)}`);for(let $=1;$<h.length;$++)a(h[$])}};for(let h of i)a(h);let y=h=>{if(!Array.isArray(h))return h;let $=h[0];return($==="local.get"||$==="local.set"||$==="local.tee")&&typeof h[1]=="string"&&f.has(h[1])?[$,f.get(h[1]),...h.slice(2).map(y)]:$==="return"?["br",l,...h.slice(1).map(y)]:ht($)&&typeof h[1]=="string"&&c.has(h[1])?[$,c.get(h[1]),...h.slice(2).map(y)]:_e($)?[$,...h.slice(1).map(o=>typeof o=="string"&&c.has(o)?c.get(o):y(o))]:h.map((o,u)=>u===0?o:y(o))},m=t.map((h,$)=>["local.set",f.get(h.name),s[$]]),_=e.filter(h=>lr(i,h.name)).map(h=>["local.set",f.get(h.name),de(h.type)]),d=i.map(y),k=r?["block",l,["result",r],...m,..._,...d]:["block",l,...m,..._,...d],x=[...t,...e].map(h=>["local",f.get(h.name),h.type]);return{block:k,decls:x}},Ti=90,Ei=(t,e)=>e==="v128"&&t.length>0&&t.every(r=>r.type==="v128"),fr=(t,{simdOnly:e=!1}={})=>{if(!Array.isArray(t)||t[0]!=="module")return t;let r=new Set;for(let i=0;i<Ze;i++){let s=t.filter(u=>Array.isArray(u)&&u[0]==="func"),n=new Map;for(let u of s)typeof u[1]=="string"&&n.set(u[1],u);let l=new Map,f=new Set,c=u=>{if(!Array.isArray(u))return;let g=u[0];g==="call"&&typeof u[1]=="string"?l.set(u[1],(l.get(u[1])||0)+1):g==="return_call"&&typeof u[1]=="string"&&f.add(u[1]);for(let p=1;p<u.length;p++)c(u[p])};c(t);let a=new Set;for(let u of t)(!Array.isArray(u)||u[0]!=="func")&&Ae(u,a);let y=null,m=null;for(let[u,g]of n){if(r.has(u)||a.has(u)||f.has(u)||ar.has(u)||!(l.get(u)>=1)||Ni(g)>Ti||xe(g,u))continue;let p=Bi(g);if(!p||e&&!Ei(p.params,p.inlResult))continue;let A=!1;for(let b=$t(g);b<g.length;b++)if(he(g[b])){A=!0;break}if(!A){y=u,m=p;break}}if(!y)break;let _=n.get(y),{params:d,locals:k,inlResult:x}=m,h=_.slice($t(_)),$=l.get(y)||0,o=0;for(let u of s){if(u===_)continue;let g=[];for(let p=$t(u);p<u.length;p++)u[p]=j(u[p],A=>{if(!Array.isArray(A)||A[0]!=="call"||A[1]!==y)return;let b=A.slice(2);if(b.length!==d.length)return;let{block:M,decls:z}=zi(d,k,x,h,b);return g.push(...z),o++,M});g.length&&u.splice($t(u),0,...g)}if(o===$){let u=t.indexOf(_);u>=0&&t.splice(u,1)}else r.add(y)}return t},or=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=[],n=!1;if(F(t,o=>{Array.isArray(o)&&typeof o[0]=="string"&&(o[0]==="table.set"||o[0]==="table.grow"||o[0]==="table.init"||o[0]==="table.copy"||o[0]==="table.fill")&&(n=!0)}),n)return t;for(let o of t.slice(1))if(Array.isArray(o))if(o[0]==="elem"){let u=o[1];if(!Array.isArray(u)||u[0]!=="i32.const")return t;let g=Number(u[1]);for(let p=2;p<o.length;p++)typeof o[p]=="string"&&o[p][0]==="$"&&e.set(g++,o[p])}else o[0]==="type"&&typeof o[1]=="string"?r.set(o[1],o[2]):o[0]==="func"&&(s.push(o),typeof o[1]=="string"&&i.set(o[1],o));if(!e.size)return t;let l=new Map,f=(o,u)=>Array.isArray(o)&&o[0]==="i64.const"&&mt(o[1])===u,c="0x0000000000007fff",a="0x0000000000000020",y=(o,u)=>Array.isArray(o)?o[0]==="i64.const"?(u.push(o),!0):o[0]==="f64.const"&&typeof o[1]=="string"&&o[1].startsWith("nan:")?(u.push(["i64.const",mt(o[1].slice(4))]),!0):o[0]==="f64.reinterpret_i64"&&o.length===2?y(o[1],u):o[0]==="select"&&o.length===4?y(o[1],u)&&y(o[2],u):!1:!1,m=new Map;F(t,o=>{!Array.isArray(o)||o[0]!=="global.set"||typeof o[1]!="string"||(m.has(o[1])||m.set(o[1],[]),m.get(o[1]).push(o[2]))});let _=(o,u,g)=>{if(!Array.isArray(o))return!1;if(o[0]==="i64.const")return u.push(o),!0;if(o[0]==="f64.const"&&typeof o[1]=="string"&&o[1].startsWith("nan:"))return u.push(["i64.const",mt(o[1].slice(4))]),!0;if((o[0]==="f64.reinterpret_i64"||o[0]==="i64.reinterpret_f64")&&o.length===2)return _(o[1],u,g);if(o[0]==="global.get"&&typeof o[1]=="string")return g.push(o[1]),!0;if(o[0]==="local.get"||o[0]==="local.tee")return o[0]==="local.tee"&&o.length===3?_(o[2],u,g):!1;if(o[0]==="select"&&o.length===4)return _(o[1],u,g)&&_(o[2],u,g);if(o[0]==="if"){let p=!0,A=!1;for(let b=1;b<o.length;b++){let M=o[b];Array.isArray(M)&&(M[0]==="then"||M[0]==="else")&&(A=!0,(M.length!==2||!_(M[1],u,g))&&(p=!1))}return p&&A}return!1},d=new Map;for(let[o,u]of m){let g=[],p=[],A=!0;for(let b of u)if(!_(b,g,p)){A=!1;break}d.set(o,A?{consts:g,reads:p}:null)}let k=!0,x=new Map;for(;k;){k=!1;for(let[o,u]of d){if(x.get(o)===null)continue;if(u===null){x.get(o)!==null&&(x.set(o,null),k=!0);continue}let g=x.get(o)||new Map,p=g.size,A=!1;for(let b of u.consts)g.set(mt(b[1]),b);for(let b of u.reads){if(d.get(b)===null||x.get(b)===null){A=!0;break}let M=x.get(b);if(M)for(let[z,v]of M)g.set(z,v)}if(A){x.set(o,null),k=!0;continue}(!x.has(o)||g.size!==p)&&(x.set(o,g),k=!0)}}for(let[o,u]of x)l.set(o,u);let h=o=>{if(!Array.isArray(o)||o[0]!=="i32.wrap_i64")return null;let u=o[1];if(!Array.isArray(u)||u[0]!=="i64.and")return null;let g=u[1],p=u[2];if(f(p,c)||(g=u[2],p=u[1]),!f(p,c)||!Array.isArray(g)||g[0]!=="i64.shr_u"||!f(g[2],a))return null;let A=g[1];if(!Array.isArray(A)||A[0]!=="i64.reinterpret_f64")return null;let b=A[1];return Array.isArray(b)&&b[0]==="local.get"&&typeof b[1]=="string"?{local:b[1]}:Array.isArray(b)&&b[0]==="global.get"&&typeof b[1]=="string"?{global:b[1]}:null},$=o=>{let u=[],g=[];for(let p of o)if(Array.isArray(p))if(p[0]==="param")for(let A of p.slice(1))typeof A=="string"&&A[0]!=="$"&&u.push(A);else p[0]==="result"&&g.push(...p.slice(1));return u.join(",")+"->"+g.join(",")};for(let o of s){let u=new Map;for(let g of o)Array.isArray(g)&&g[0]==="param"&&typeof g[1]=="string"&&u.set(g[1],null);F(o,g=>{if(!Array.isArray(g)||g[0]!=="local.set"&&g[0]!=="local.tee"||typeof g[1]!="string"||u.get(g[1])===null)return;let p=[];if(y(g[2],p)){let A=u.get(g[1])||new Map;for(let b of p)A.set(mt(b[1]),b);u.set(g[1],A)}else if(Array.isArray(g[2])&&g[2][0]==="global.get"&&typeof g[2][1]=="string"&&l.get(g[2][1])){let A=l.get(g[2][1]),b=u.get(g[1])||new Map;for(let[M,z]of A)b.set(M,z);u.set(g[1],b)}else u.set(g[1],null)}),j(o,(g,p)=>{if(!Array.isArray(g)||g[0]!=="call_indirect"||p&&p[0]==="else")return;let A=Array.isArray(g[1])&&g[1][0]==="type"?g[1]:null;if(!A)return;let b=r.get(A[1]),M=Array.isArray(b)?$(b.slice(1)):null;if(M==null)return;let z=[];for(let O of b.slice(1))Array.isArray(O)&&O[0]==="result"&&z.push(...O.slice(1));let v=g.slice(2,-1),S=g[g.length-1],w=O=>{let J=i.get(O);if(!J)return!1;let ct=J.find(ut=>Array.isArray(ut)&&ut[0]==="type");return ct?ct[1]===A[1]||r.get(ct[1])&&$(r.get(ct[1]).slice(1))===M:$(J.slice(2))===M};if(Array.isArray(S)&&S[0]==="i32.const"){let O=e.get(Number(S[1]));return O&&w(O)?["call",O,...v]:void 0}let B=h(S);if(!B)return;let E=B.local!=null?u.get(B.local):l.get(B.global);if(!E||E.size===0||E.size>4)return;let Z=[];for(let O of E.values()){let J=e.get(at(mt(O[1]))&32767);if(!J||!w(J))return;Z.push([O,J])}let V=B.local!=null?["local.get",B.local]:["global.get",B.global],U=g;for(let O=Z.length-1;O>=0;O--){let[J,ct]=Z[O];U=["if",...z.length?[["result",...z]]:[],["i64.eq",["i64.reinterpret_f64",Q(V)],Q(J)],["then",["call",ct,...v.map(Q)]],["else",U]]}return U})}return t},ar=new Set(["$math.sin_core","$math.cos_core","$math.sin","$math.cos","$math.pow","$math.atan2","$math.hypot","$math.log"]),Oi=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=$t,r=xe,i=he,s=_e,n=de,l=lr;for(let f=0;f<Ze;f++){let c=t.filter(w=>Array.isArray(w)&&w[0]==="func"),a=new Map;for(let w of c)typeof w[1]=="string"&&a.set(w[1],w);let y=new Map,m=new Set,_=w=>{if(!Array.isArray(w))return;let B=w[0];B==="call"&&typeof w[1]=="string"?y.set(w[1],(y.get(w[1])||0)+1):B==="return_call"&&typeof w[1]=="string"&&m.add(w[1]);for(let E=1;E<w.length;E++)_(w[E])};_(t);let d=Mi(t),k=null;for(let[w,B]of a){if(d.has(w)||m.has(w)||y.get(w)!==1||ar.has(w)||r(B,w))continue;let E=!0,Z=0;for(let U=2;U<B.length;U++){let O=B[U];if(typeof O!="string"){if(!Array.isArray(O)){E=!1;break}if(O[0]==="param"||O[0]==="local"){if(typeof O[1]!="string"||O[1][0]!=="$"){E=!1;break}if(O[0]==="local"&&!n(O[2])){E=!1;break}}else if(O[0]==="result")Z+=O.length-1;else if(O[0]==="export"){E=!1;break}else{if(O[0]==="type")continue;break}}}if(!E||Z>1)continue;let V=!1;for(let U=e(B);U<B.length;U++)if(i(B[U])){V=!0;break}if(!V){k=w;break}}if(!k)break;let x=a.get(k),h=[],$=[],o=null;for(let w=2;w<x.length;w++){let B=x[w];if(!(typeof B=="string"||!Array.isArray(B)))if(B[0]==="param")h.push({name:B[1],type:B[2]});else if(B[0]==="result")B.length>1&&(o=B[1]);else if(B[0]==="local")$.push({name:B[1],type:B[2]});else{if(B[0]==="export"||B[0]==="type")continue;break}}let u=x.slice(e(x)),g=++nr,p=`$__inl${g}`,A=new Map;for(let w of h)A.set(w.name,`$__inl${g}_${w.name.slice(1)}`);for(let w of $)A.set(w.name,`$__inl${g}_${w.name.slice(1)}`);let b=new Map,M=w=>{if(Array.isArray(w)){ht(w[0])&&typeof w[1]=="string"&&w[1][0]==="$"&&!b.has(w[1])&&b.set(w[1],`$__inl${g}L_${w[1].slice(1)}`);for(let B=1;B<w.length;B++)M(w[B])}};for(let w of u)M(w);let z=w=>{if(!Array.isArray(w))return w;let B=w[0];return(B==="local.get"||B==="local.set"||B==="local.tee")&&typeof w[1]=="string"&&A.has(w[1])?[B,A.get(w[1]),...w.slice(2).map(z)]:B==="return"?["br",p,...w.slice(1).map(z)]:ht(B)&&typeof w[1]=="string"&&b.has(w[1])?[B,b.get(w[1]),...w.slice(2).map(z)]:s(B)?[B,...w.slice(1).map(E=>typeof E=="string"&&b.has(E)?b.get(E):z(E))]:w.map((E,Z)=>Z===0?E:z(E))},v=!1;for(let w of c){if(w===x||v)continue;let B=e(w);for(let E=B;E<w.length;E++){let Z=j(w[E],V=>{if(v||!Array.isArray(V)||V[0]!=="call"||V[1]!==k)return;let U=V.slice(2);if(U.length!==h.length)return;let O=h.map((ut,xr)=>["local.set",A.get(ut.name),U[xr]]),J=$.filter(ut=>l(u,ut.name)).map(ut=>["local.set",A.get(ut.name),n(ut.type)]),ct=u.map(z);return v=!0,o?["block",p,["result",o],...O,...J,...ct]:["block",p,...O,...J,...ct]});if(Z!==w[E]&&(w[E]=Z),v){let V=[...h,...$].map(U=>["local",A.get(U.name),U.type]);V.length&&w.splice(e(w),0,...V);break}}if(v)break}if(!v)break;let S=t.indexOf(x);S>=0&&t.splice(S,1)}return t},Xt=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],f=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(f=!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 c=1;c<s.length&&typeof s[c]=="string";c++)if(s[c]===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 c=1;c<s.length;c++)i(s[c],f)};for(let s of t)i(s,!1);return r},cr=t=>(j(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 f=e[r];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="type")){r++;continue}if(Array.isArray(f)&&f[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&&Xt(n,i))){e.length=0;for(let f of l)e.push(f)}}),F(t,e=>{if(!me(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)){r++;continue}{let f=i[0],c=f==="local.set"||f==="global.set"?2:f==="drop"?1:-1;if(c>=0&&i.length===c+1){let a=i[c];if(Array.isArray(a)&&a[0]==="block"){let y=1,m=null;typeof a[1]=="string"&&a[1][0]==="$"&&(m=a[1],y=2);let _=!1;for(;y<a.length;){let k=a[y];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="type")){y++;continue}if(Array.isArray(k)&&k[0]==="result"){_=!0,y++;continue}break}let d=_?a.slice(y):null;if(d&&d.length>=2&&!(m&&Xt(d,m))){let k=d[d.length-1],x=d.slice(0,-1);i[c]=k,e.splice(r,1,...x,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 f=i[s];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="result"||f[0]==="type")){s++;continue}break}let l=i.slice(s);if(n&&Xt(l,n)){r++;continue}e.splice(r,1,...l),r+=l.length}}),t),ur=t=>(F(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let _ of e)Array.isArray(_)&&_[0]==="local"&&typeof _[1]=="string"&&_[1][0]==="$"&&typeof _[2]=="string"&&r.set(_[1],_[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,f=0,c=_=>{if(l||!Array.isArray(_))return;let d=_[0],k=d==="loop";k&&s.push({start:n,end:n});let x=d==="local.set"||d==="local.tee";if(x||d==="local.get"){let h=_[1];if(typeof h!="string"||h[0]!=="$"){l=!0;return}if(x)for(let o=2;o<_.length;o++)c(_[o]);let $=n++;if(r.has(h)){let o=i.get(h);o||(o={start:$,end:$,firstOp:d,firstCond:f>0,loops:new Set},i.set(h,o)),$>o.end&&(o.end=$);for(let u of s)o.loops.add(u)}}else{n++;let h=d==="if";for(let $=1;$<_.length;$++){let o=_[$],u=h&&Array.isArray(o)&&(o[0]==="then"||o[0]==="else");u&&f++,c(o),u&&f--}}if(k){let h=s.pop();h.end=n}};if(c(e),l)return;for(let _ of i.values())for(let d of _.loops)d.start<_.start&&(_.start=d.start),d.end>_.end&&(_.end=d.end);let a=[...i.entries()].sort((_,d)=>_[1].start-d[1].start),y=new Map,m=[];for(let[_,d]of a){let k=d.firstOp==="local.get"||d.firstCond,x=r.get(_),h=k?null:m.find($=>$.type===x&&$.end<d.start);h?(y.set(_,h.primary),d.end>h.end&&(h.end=d.end)):m.push({primary:_,type:x,end:d.end})}y.size!==0&&F(e,_=>{Array.isArray(_)&&(_[0]==="local.get"||_[0]==="local.set"||_[0]==="local.tee")&&y.has(_[1])&&(_[1]=y.get(_[1]))})}),t),yr=t=>j(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2){let i=er(e[1]);return i.length===0?["nop"]:i.length===1?i[0]:["block",...i]}if(r==="select"&&e.length>=4&&nt(e[1],e[2])&&R(e[3]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=vt(e),l=!s||s.length<=1,f=!n||n.length<=1;if(l&&f)return R(i)?["nop"]:["drop",i];if(n&&f&&!l)return e.filter(c=>c!==n)}if(me(e)){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],f=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&f&&R(n)){s++;continue}if(Array.isArray(n)&&f&&n[0]==="local.tee"&&n.length===3){i.push(["local.set",n[1],n[2]]),s++;continue}i.push(n)}if(i.length!==e.length)return i}}),L=t=>(e,r)=>nt(e,r)&&R(e)?t:null,qi={"i32.sub":L(["i32.const",0]),"i64.sub":L(["i64.const",0]),"i32.xor":L(["i32.const",0]),"i64.xor":L(["i64.const",0]),"i32.eq":L(["i32.const",1]),"i64.eq":L(["i32.const",1]),"i32.ne":L(["i32.const",0]),"i64.ne":L(["i32.const",0]),"i32.lt_s":L(["i32.const",0]),"i32.lt_u":L(["i32.const",0]),"i32.gt_s":L(["i32.const",0]),"i32.gt_u":L(["i32.const",0]),"i32.le_s":L(["i32.const",1]),"i32.le_u":L(["i32.const",1]),"i32.ge_s":L(["i32.const",1]),"i32.ge_u":L(["i32.const",1]),"i64.lt_s":L(["i32.const",0]),"i64.lt_u":L(["i32.const",0]),"i64.gt_s":L(["i32.const",0]),"i64.gt_u":L(["i32.const",0]),"i64.le_s":L(["i32.const",1]),"i64.le_u":L(["i32.const",1]),"i64.ge_s":L(["i32.const",1]),"i64.ge_u":L(["i32.const",1]),"i32.mul":(t,e)=>q(e)?.value===0&&R(t)?["i32.const",0]:q(t)?.value===0&&R(e)?["i32.const",0]:null,"i64.mul":(t,e)=>q(e)?.value===W&&R(t)?["i64.const",0]:q(t)?.value===W&&R(e)?["i64.const",0]:null,"i32.and":(t,e)=>nt(t,e)&&R(e)?t:q(e)?.value===0&&R(t)?["i32.const",0]:q(t)?.value===0&&R(e)?["i32.const",0]:null,"i64.and":(t,e)=>nt(t,e)&&R(e)?t:q(e)?.value===W&&R(t)?["i64.const",0]:q(t)?.value===W&&R(e)?["i64.const",0]:null,"i32.or":(t,e)=>nt(t,e)&&R(e)?t:q(e)?.value===-1&&R(t)?["i32.const",-1]:q(t)?.value===-1&&R(e)?["i32.const",-1]:null,"i64.or":(t,e)=>nt(t,e)&&R(e)?t:q(e)?.value===Zt&&R(t)?["i64.const",-1]:q(t)?.value===Zt&&R(e)?["i64.const",-1]:null,"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Fi=t=>j(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=qi[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Ci=t=>{let e=typeof t=="bigint"?t:BigInt(typeof t=="string"?t.replaceAll("_",""):Math.trunc(Number(t)||0));e>0x7fffffffffffffffn&&(e=e-0x8000000000000000n-0x8000000000000000n);let r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},Ri=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Ci(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},Li=2,Ui=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(a=>Array.isArray(a)&&a[0]==="export")&&r.add(l);let f=n[2];if(Array.isArray(f)&&f[0]==="mut"||Array.isArray(f)&&f[0]==="import")continue;let c=n[3];q(c)&&e.set(l,c)}if(e.size===0)return t;let i=new Map;F(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 f=i.get(n)||0;if(f===0)continue;let c=Ri(l),a=c+2,y=f*Li+a;f*c+(r.has(n)?a:0)<=y&&s.add(n)}if(s.size===0)return t;j(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return Q(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},Di=t=>j(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 f=i?e.length-2:e.length-1,c=i?e.length-1:-1;if(f<l)return;let a=e[f];if(!Array.isArray(a)||a[0]!=="i32.add"||a.length!==3)return;let y=a[1],m=a[2],_=q(y),d=q(m),k=null,x=null;if(_&&_.type==="i32"?(x=_.value,k=m):d&&d.type==="i32"&&(x=d.value,k=y),k===null||x===null)return;let h=s+x,$=[r];n!==null&&$.push(n),$.push(`offset=${h}`);let o=null;for(let u=l;u<f;u++)typeof e[u]=="string"&&e[u].startsWith("align=")&&(o=e[u]);return o&&$.push(o),$.push(k),i&&$.push(e[c]),$}),Pi=t=>(F(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 f=e.length-1;f>=i;f--){let c=e[f];if(!Array.isArray(c)){c!=="nop"&&c!=="end"&&(n=f);continue}let a=c[0];if(!(a==="param"||a==="result"||a==="local"||a==="type"||a==="export")){n=f;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),Wi=t=>(F(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 k=e[r];if(Array.isArray(k)&&k[0]==="type"){r++;continue}if(Array.isArray(k)&&(k[0]==="param"||k[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 f=[];for(;n<s.length;){let k=s[n];if(Array.isArray(k)&&k[0]==="type"){f.push(k),n++;continue}if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"))return;break}let c=s.slice(n);if(c.length<2)return;let a=c[0],y=c[c.length-1];if(!Array.isArray(a)||a[0]!=="br_if"||a[1]!==i||a.length!==3||!Array.isArray(y)||y[0]!=="br"||y[1]!==l||y.length!==2)return;let m=c.slice(1,-1);if(Xt(m,i))return;let _=a[2];Array.isArray(_)&&_[0]==="i32.eqz"&&_.length===2?_=_[1]:_=["i32.eqz",_];let d=["loop"];l&&d.push(l);for(let k of f)d.push(k);d.push(["if",_,["then",...m,y]]),e.length=0;for(let k of d)e.push(k)}),t),ji=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return F(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),j(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}})},Gi=t=>j(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=vt(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let f=i[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],r]}if(n&&!l&&s.length===2){let f=s[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],["i32.eqz",r]]}}),Hi=t=>j(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=vt(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(_=>Array.isArray(_)&&_[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let _=1;_<l&&nt(r[r.length-_],i[i.length-_]);_++)n++;if(n===0)return;let f=r.slice(r.length-n),c=r.slice(0,r.length-n),a=i.slice(0,i.length-n),y=["block"];for(let _=1;_<e.length;_++){let d=e[_];if(Array.isArray(d)&&(d[0]==="then"||d[0]==="else"))break;Array.isArray(d)&&(d[0]==="result"||d[0]==="type")&&y.push(d)}let m=["if"];for(let _=1;_<e.length;_++){let d=e[_];if(Array.isArray(d)&&(d[0]==="then"||d[0]==="else"))break;Array.isArray(d)&&(d[0]==="result"||d[0]==="type")||m.push(d)}return m.push(c.length>1?c:["then"]),m.push(a.length>1?a:["else"]),y.push(m,...f),y}),pr=(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(",")},Vi=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]),F(i,f=>{if(!Array.isArray(f)||typeof f[1]!="string"||f[1][0]!=="$")return;let c=f[0];(c==="param"||c==="local"||ht(c))&&n.add(f[1])});let l=pr(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||j(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},Yi=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=pr(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 j(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 f=1;f<l.length;f++){let c=l[f];Array.isArray(c)&&c[0]==="type"&&typeof c[1]=="string"&&r.has(c[1])&&(l[f]=["type",r.get(c[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},Kt=t=>{if(typeof t!="string"||t.length<2||t[0]!=='"')return[];let e=[],r=s=>s>=48&&s<=57?s-48:s>=97&&s<=102?s-87:s>=65&&s<=70?s-55:-1,i=t.length-1;for(let s=1;s<i;s++){let n=t.charCodeAt(s);if(n!==92){e.push(n);continue}let l=t.charCodeAt(++s);if(l===120||l===88)e.push(r(t.charCodeAt(s+1))<<4|r(t.charCodeAt(s+2))),s+=2;else{let f=r(l),c=s+1<i?r(t.charCodeAt(s+1)):-1;f>=0&&c>=0?(e.push(f<<4|c),s++):l===110?e.push(10):l===116?e.push(9):l===114?e.push(13):e.push(l)}}return e},gr=(t,e)=>{let r='"';for(let i=0;i<e;i++){let s=t[i];s>=32&&s<127&&s!==34&&s!==92?r+=String.fromCharCode(s):r+="\\"+s.toString(16).padStart(2,"0")}return r+'"'},Xi=t=>{let e=[];for(let i of t)if(typeof i=="string"){let s=Kt(i);for(let n=0;n<s.length;n++)e.push(s[n])}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?[]:[gr(e,r)]},Zi=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},Ye=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+=Kt(s).length;else if(Array.isArray(s)&&s[0]==="i8")r+=s.length-1;else return null}return r},Ki=(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=Kt(s[0]),f=Kt(n[0]);for(let c=0;c<f.length;c++)l.push(f[c]);return t.length=r,t.push(gr(l,l.length)),!0}return t.length=r,t.push(...s,...n),!0},Qi=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=Xi(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=Zi(s);if(n){let l=Ye(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&&Ki(s.node,n.node)&&(r.add(n.index),s.len=Ye(s.node))}return r.size>0&&(t=t.filter((i,s)=>!r.has(s))),t},Xe=()=>{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)}},Ji=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=Xe(),r=Xe();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},ts=t=>{let e=!0;return F(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},es=t=>{if(!Array.isArray(t)||t[0]!=="module"||!ts(t))return t;let e=new Map;F(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]},zt=[["stripmut",ji,!0,"strip mut from never-written globals"],["globals",Ui,!0,"propagate immutable global constants"],["guardRefine",yi,!1,"fold NaN-box tag reads under dominating tag guards (jz NaN-box-specific; opt-in)"],["fold",fi,!0,"constant folding"],["identity",ai,!0,"remove identity ops (x + 0 \u2192 x)"],["peephole",Fi,!0,"x-x\u21920, x&0\u21920, etc."],["strength",ci,!0,"strength reduction (x * 2 \u2192 x << 1)"],["branch",ui,!0,"simplify constant branches"],["propagate",ue,!0,"forward-propagate single-use locals & tiny consts (never inflates)"],["devirt",or,!1,"call_indirect with a constant or known closure-const index \u2192 direct/guarded calls \u2014 grows bytes for speed"],["inlineOnce",Oi,!0,"inline single-call functions into their lone caller (never duplicates)"],["inline",fr,!1,"inline tiny functions \u2014 can duplicate bodies"],["offset",Di,!0,"fold add+const into load/store offset"],["unbranch",Pi,!0,"remove redundant br at end of own block"],["loopify",Wi,!0,"collapse block+loop+brif while-idiom into loop+if"],["brif",Gi,!0,"if-then-br \u2192 br_if"],["foldarms",Hi,!1,"merge identical trailing if arms \u2014 can add block wrapper"],["deadcode",mi,!0,"eliminate dead code after unreachable/br/return"],["vacuum",yr,!0,"remove nops, drop-of-pure, empty branches"],["mergeBlocks",cr,!0,"unwrap `(block $L \u2026)` whose label is never targeted"],["coalesce",ur,!0,"share local slots between same-type non-overlapping locals"],["locals",_i,!0,"remove unused locals"],["dedupe",Vi,!0,"eliminate duplicate functions"],["dedupTypes",Yi,!0,"merge identical type definitions"],["packData",Qi,!0,"trim trailing zeros, merge adjacent data segments"],["reorder",es,!1,"put hot functions first \u2014 no AST reduction"],["treeshake",Kr,!0,"remove unused funcs/globals/types/tables"],["minifyImports",Ji,!1,"shorten import names \u2014 enable only when you control the host"]],Ns=Object.fromEntries(zt.map(t=>[t[0],t[2]])),rs=t=>{if(t===!1)return{};if(t!==!0&&typeof t!="string"){let i={...t};for(let s of zt)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 zt)r[i[0]]=e?e.has("all")||e.has(i[0]):i[2];return r},is=t=>{if(!Array.isArray(t))return!1;let e=new Map,r=new Set,i=new Set,s=n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="call"&&typeof n[1]=="string")e.set(n[1],(e.get(n[1])||0)+1);else if(l==="return_call"&&typeof n[1]=="string")i.add(n[1]);else if(l==="ref.func"&&typeof n[1]=="string")r.add(n[1]);else if(l==="export"&&Array.isArray(n[2])&&n[2][0]==="func"&&typeof n[2][1]=="string")r.add(n[2][1]);else if(l==="start"&&typeof n[1]=="string")r.add(n[1]);else if(l==="elem")for(let f of n)typeof f=="string"&&f[0]==="$"&&r.add(f);for(let f=1;f<n.length;f++)s(n[f])};s(t);for(let n of t){if(!Array.isArray(n)||n[0]!=="func"||typeof n[1]!="string")continue;let l=n[1];if(!(e.get(l)!==1||r.has(l)||i.has(l))&&!n.some(f=>Array.isArray(f)&&f[0]==="export"))return!0}return!1},ss=new Set(["export","type","param","result","local"]);function ns(t){if(!Array.isArray(t)||t[0]!=="module")return t;let e=t.find(i=>Array.isArray(i)&&i[0]==="func"&&i[1]==="$__start");if(!e)return t;let r=2;for(;r<e.length&&Array.isArray(e[r])&&ss.has(e[r][0]);)r++;return r<e.length?t:t.filter(i=>!(Array.isArray(i)&&(i[0]==="func"&&i[1]==="$__start"||i[0]==="start"&&i[1]==="$__start")))}function be(t,e=!0){typeof t=="string"&&(t=lt(t));let r=e===!0;e=rs(e);let i=e.log?(a,y)=>e.log(a,y):()=>{},s=e.verbose||e.log;t=Q(t);let n=a=>(e.inline&&(a=fr(a,{simdOnly:e.inline==="simd"}),e.propagate&&(a=ue(a)),e.mergeBlocks&&(a=cr(a)),e.vacuum&&(a=yr(a)),e.coalesceLocals&&(a=ur(a))),a),l=a=>(a=n(a),ns(e.devirt?or(a):a));if(!((e.inlineOnce||e.inline)&&is(t))){for(let a=0;a<3;a++){let y=Q(t);for(let[m,_]of zt)e[m]&&m!=="inlineOnce"&&m!=="inline"&&m!=="devirt"&&(t=_(t));if(nt(y,t))break;s&&i(` round ${a+1} applied`)}return l(t)}let f=null,c=Pe(t);for(let a=0;a<3;a++){f=Q(t);for(let[d,k]of zt)e[d]&&d!=="devirt"&&d!=="inline"&&(t=k(t));if(e.propagate&&(e.inlineOnce||e.inline)&&(t=ue(t)),nt(f,t))break;let y=Pe(t),m=y-c;if((s||m!==0)&&i(` round ${a+1}: ${m>0?"+":""}${m} bytes`,m),m>(r?0:16)){s&&i(` \u26A0 round ${a+1} inflated by ${m} bytes, reverting`,m),t=f;break}c=y}return l(t)}var mr="\uE000",ls=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t,s=ze(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 we(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=we(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function fs(t,e){let r=[],i=new Map;return we(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 f=[];for(let y=2;y<s.length;y++){let m=ls(s[y]);m&&f.push(m)}let c=r.length,a=n.name||`$fn${c}`;i.set(n,{idx:c,name:a.startsWith("$")?a:"$"+a,params:f,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function os(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function $e(t,e,r){let{parse:i,compile:s,optimize:n,polyfill:l}=t,f={};if(!Array.isArray(e)&&r.length&&typeof r[r.length-1]=="object"&&r[r.length-1]!==null&&!r[r.length-1].byteLength&&(f=r.pop()),Array.isArray(e)&&e.raw){let c=e[0];for(let k=0;k<r.length;k++)c+=mr+e[k+1];let a=i(c),y=[],m=0;a=we(a,k=>{if(k===mr){let x=r[m++];if(typeof x=="function")return y.push(x),x;if(typeof x=="string"&&(x[0]==="("||/^\s*\(/.test(x))){let h=i(x);return Array.isArray(h)&&Array.isArray(h[0])&&(h._splice=!0),h}return x?.byteLength!==void 0?[...x]:typeof x=="bigint"?x.toString():x}return k});let _=null;if(y.length){let k=fs(a,y);if(k.length){let x=os(k);a[0]==="module"?a.splice(1,0,...x):typeof a[0]=="string"?a=[...x,a]:a.unshift(...x),_={env:{}};for(let h of k)_.env[h.name.slice(1)]=h.fn}}f.polyfill&&(a=l(a,f.polyfill)),f.optimize&&(a=n(a,f.optimize));let d=s(a);return _&&(d._imports=_),d}if(f.polyfill||f.optimize){let c=typeof e=="string"?i(e):e;return f.polyfill&&(c=l(c,f.polyfill)),f.optimize&&(c=n(c,f.optimize)),s(c)}return s(e)}function _r(t,e,r){let i=$e(t,e,r),s=new WebAssembly.Module(i);return new WebAssembly.Instance(s,i._imports).exports}var hr={parse:lt,compile:bt,optimize:be,polyfill:le};function Us(t,...e){return $e(hr,t,e)}function as(t,...e){return _r(hr,t,e)}var Ds=as;export{Us as compile,Ds as default,be as optimize,lt as parse,le as polyfill,Re as print,as as watr};
1
+ var Ar=Object.defineProperty;var br=(t,e)=>{for(var r in e)Ar(t,r,{get:e[r],enumerable:!0})};var qt={};br(qt,{f32:()=>dt,f64:()=>mt,i16:()=>kr,i32:()=>X,i64:()=>xt,i8:()=>Ir,uleb:()=>I,uleb5:()=>vr,v128:()=>ee});var E=(t,e=E.loc)=>{if(e!=null&&E.src){let r=1,i=1;for(let s=0;s<e&&s<E.src.length;s++)E.src[s]===`
2
+ `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)},Se=/^_|_$|[^\da-f]_|_[^\da-f]/i,Me=/^[+-]?(?:0x[\da-f]+|\d+)$/i,wr=new TextEncoder,$r=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),ke={n:10,r:13,t:9,'"':34,"'":39,"\\":92},Et=t=>{let e=[],r=1,i,s,n="",l=()=>(n&&e.push(...wr.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++):ke[t[r]]?i=ke[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},Be=t=>$r.decode(new Uint8Array(Et(t))),Jt=t=>Array.isArray(t)?t.map(Jt):t,V=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)V(t[s],e,t,s)},J=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++)J(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 I=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):X.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),I(t,e))};function vr(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 X(t,e=[]){for(typeof t=="string"&&(t=X.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 Te=t=>!Se.test(t)&&Me.test(t=t.replaceAll("_",""))?t:E(`Bad int ${t}`),Ir=X,kr=X;X.parse=t=>(t=parseInt(Te(t)),(t<-2147483648||t>4294967295)&&E("i32 constant out of range"),t);function xt(t,e=[]){for(typeof t=="string"?t=xt.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 St=new ArrayBuffer(8),tt=new Uint8Array(St),Sr=new Int32Array(St),Mr=new Float32Array(St),Br=new Float64Array(St),te=new BigInt64Array(St);xt.parse=t=>{t=Te(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)&&E("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)&&E("i64 constant out of range")}let s=BigInt(r);return e&&(s=0n-s),te[0]=s,te[0]};var Nr=2147483648,zr=2139095040,Ne=4194304;function dt(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"?Ne:X.parse(i)}else e=Ne;e=(e|zr)>>>0,t[0]==="-"&&(e=(e|Nr)>>>0),Sr[0]=e|0}else e=typeof t=="string"?dt.parse(t):t,Mr[0]=e;return[tt[0],tt[1],tt[2],tt[3]]}var Tr=0x8000000000000000n,Er=0x7ff0000000000000n,ze=0x8000000000000n;function mt(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"?ze:xt.parse(i)}else e=ze;e|=Er,t[0]==="-"&&(e|=Tr),te[0]=e}else e=typeof t=="string"?mt.parse(t):t,Br[0]=e;return[tt[0],tt[1],tt[2],tt[3],tt[4],tt[5],tt[6],tt[7]]}mt.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("."),f=l.length??0,c=0;for(let m=n.length-1;m>=2;m--){let _=parseInt(n[m],16);c+=_*16**(n.length-1-m)}let a=l?parseInt("0x"+l)/16**f:0;s=parseInt(s,10);let u=r*(c+a)*2**s;return u=Math.max(-e,Math.min(e,u)),u}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};dt.parse=t=>mt.parse(t,34028234663852886e22);var ee=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 Mt=["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"]],Ee=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},P={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},j={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},yt={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},re={func:0,table:1,memory:2,global:3,tag:4};var lt=t=>{let e=0,r=[],i="",s=0,n=0,l=()=>i&&(r.push(i),i=""),f=c=>{r.loc=c;for(let a,u,m;e<t.length;)if(a=t.charCodeAt(e),s===34)i+=t[e++],a===92?i+=t[e++]:a===34&&(l(),s=0);else if(s>59)a===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):a===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(l(),s=0)):i+=t[e++];else if(s<0)a===10||a===13?(i+=t[e++],l(),s=0):s===-2&&a===41?(l(),s=0):i+=t[e++];else if(a===34)i!=="$"&&l(),s=34,i+=t[e++];else if(a===40&&t.charCodeAt(e+1)===59)l(),s=60,i=t[e++]+t[e++];else if(a===59&&t.charCodeAt(e+1)===59)l(),s=t.indexOf(`
3
+ `,e)<0?-2:-1,i=t[e++]+t[e++];else if(a===40&&t.charCodeAt(e+1)===64)l(),m=e,e+=2,i="@",n++,(u=r).push(r=[]),f(m),r=u;else if(a===40)l(),m=e++,n++,(u=r).push(r=[]),f(m),r=u;else{if(a===41)return l(),e++,n--;a<=32?(l(),e++):i+=t[e++]}s<0&&l(),l()};return f(0),s===34&&E("Unclosed quote",e),s>59&&E("Unclosed block comment",e),n>0&&E("Unclosed parenthesis",e),e<t.length&&E("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Fe=t=>typeof t=="string"&&(t[0]===";"||t[1]===";")||Array.isArray(t)&&t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code."),Ce=(t,e)=>typeof t=="string"?t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+Be(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?Et(t):t:Array.isArray(t)?(e=t.filter(r=>!Fe(r)).map(Ce),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):t;function bt(t){typeof t=="string"?(E.src=t,t=lt(t)||[]):E.src="",E.loc=0,t=Fe(t)?[]:Ce(t)??[];let e=0;if(t[0]==="module"?(e++,Y(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return bt(t.slice(++e).map(h=>h.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((h,w)=>{if(w<e||!Array.isArray(h)||h[0]!=="import")return[h];let[,o,...y]=h;if(!y.some(g=>Array.isArray(g)&&g[0]==="item"))return[h];if(Array.isArray(y.at(-1))&&y.at(-1)[0]!=="item"){let g=y.at(-1);return y.slice(0,-1).filter(A=>A[0]==="item").map(([,A])=>["import",o,A,g])}return y.filter(g=>g[0]==="item").map(([,g,A])=>["import",o,g,A])});let r=[];for(let h in P)(r[P[h]]=r[h]=[]).name=h;r.metadata={},t.slice(e).filter(h=>{if(!Array.isArray(h)){let y=E.loc,p=E.src,g;for(;(y=p.indexOf(h,y))>=0;){if(g=p.charCodeAt(y-1),y>0&&(g>47&&g<58||g>64&&g<91||g>96&&g<123||g===95||g===36)){y++;continue}if(g=p.charCodeAt(y+h.length),g>47&&g<58||g>64&&g<91||g>96&&g<123||g===95){y++;continue}break}y>=0&&(E.loc=y),E(`Unexpected token ${h}`)}let[w,...o]=h;if(E.loc=h.loc,w==="@custom")r.custom.push(o);else if(w==="rec")for(let y=0;y<o.length;y++){let[,...p]=o[y];ie(p,r.type);let g=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)g.push(p.shift());(p=qe(p,r)).push(y?!0:[r.type.length,o.length]),g.length&&(p.desc=p.desc?[...g,...p.desc]:g),r.type.push(p)}else if(w==="type"){ie(o,r.type);let y=[];for(;o[0]?.[0]==="descriptor"||o[0]?.[0]==="describes";)y.push(o.shift());let p=qe(o,r);y.length&&(p.desc=p.desc?[...y,...p.desc]:y),r.type.push(p)}else if(w==="start"||w==="export")r[w].push(o);else return!0}).forEach(h=>{let[w,...o]=h;E.loc=h.loc;let y;w==="import"&&([w,...o]=(y=o).pop());let p=r[w];for(p||E(`Unknown section ${w}`),ie(o,p);o[0]?.[0]==="export";)r.export.push([o.shift()[1],[w,p?.length]]);if(o[0]?.[0]==="import"&&([,...y]=o.shift()),w==="table"){let g=o[0]==="i64",A=g?1:0;if(o[A+1]?.[0]==="elem"){let[b,[,...M]]=[o[A],o[A+1]];o=g?["i64",M.length,M.length,b]:[M.length,M.length,b],r.elem.push([["table",p.length],["offset",[g?"i64.const":"i32.const",g?0n:0]],b,...M])}}else if(w==="memory"){let g=o[0]==="i64",A=g?1:0;if(o[A]?.[0]==="data"){let b=o.find(v=>Array.isArray(v)&&v[0]==="pagesize")?.[1]??65536,[,...M]=o.splice(A,1)[0],N=""+Math.ceil(M.reduce((v,k)=>v+k.length,0)/b);r.data.push([["memory",p.length],[g?"i64.const":"i32.const",g?0n:0],...M]),o=g?["i64",N,N]:[N,N]}}else if(w==="func"){let[g,A,b]=Pt(o,r);g??=Ut(A,b,r),!y&&r.code.push([[g,A,b],...ut(o,r)]),o=[["type",g]]}else if(w==="tag"){let[g,A]=Pt(o,r);g??=Ut(A,[],r),o=[["type",g]]}y&&(r.import.push([...y,[w,...o]]),o=null),p.push(o)});let i=(h,w=!0)=>{let o=r[h].filter(Boolean).map(y=>le[h](y,r)).filter(Boolean);return h===P.custom?o.flatMap(y=>[h,...R(y)]):o.length?[h,...R(w?R(o):o.flat())]:[]},s=()=>{let h=[];for(let w in r.metadata){let o=R(Et(`"metadata.code.${w}"`)),y=R(r.metadata[w].map(([p,g])=>[...I(p),...R(g.map(([A,b])=>[...I(A),...R(b)]))]));h.push(0,...R([...o,...y]))}return h},n=i(P.global),l=i(P.elem),f=r.code.filter(Boolean).map(h=>le[P.code](h,r)).filter(Boolean),c=f.length?[P.code,...R(R(f))]:[],a=s(),u=i(P.data),m=r.strings.length?[P.strings,...R([0,...R(r.strings.map(h=>R(h)))])]:[],_=[i(P.custom),i(P.type),i(P.import),i(P.func),i(P.table),i(P.memory),i(P.tag),m,n,i(P.export),i(P.start,!1),l,i(P.datacount,!1),c,a,u],x=Uint8Array.from([0,97,115,109,1,0,0,0,..._.flat()]),S=d();return S&&(x.metadata=S),x;function d(){let h=!1;for(let A in r.metadata)h=!0;if(!h)return;let w={},y=8+_.slice(0,_.indexOf(c)).reduce((A,b)=>A+b.length,0)+c.length-f.reduce((A,b)=>A+b.length,0),p=[];for(let A=0,b=y;A<f.length;A++)p[A]=b+(r.codeSizePrefix?.[A]??0),b+=f[A].length;let g=r.import.filter(A=>A[2][0]==="func").length;for(let A in r.metadata){let b=[];for(let[M,N]of r.metadata[A]){let v=p[M-g];for(let[k,z]of N)b.push([v+k,z])}w[A]=b.sort((M,N)=>M[0]-N[0])}return w}}var et=t=>t?.[0]==="$"||!isNaN(t),Y=t=>t?.[0]==="$",se=t=>t?.[0]==="a"||t?.[0]==="o";function ut(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")Y(t[0])&&r.push(t.shift()),r.push(Ot(t,e));else if(i==="else"||i==="end")Y(t[0])&&t.shift();else if(i==="select")r.push(Dt(t)[1]);else if(i.endsWith("call_indirect")){let s=et(t[0])?t.shift():0,[n,l,f]=Pt(t,e);r.push(s,["type",n??Ut(l,f,e)])}else i==="table.init"?r.push(et(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(et(t[0])?t.shift():0,et(t[0])?t.shift():0):i.startsWith("table.")?r.push(et(t[0])?t.shift():0):i==="memory.init"?(r.push(...et(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"))&&et(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(E.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(Mt[s])){r.push(i);continue}let n=i.slice(1);if(s==="block"||s==="loop")r.push(s),Y(n[0])&&r.push(n.shift()),r.push(Ot(n,e),...ut(n,e),"end");else if(s==="if"){let l=[],f=[];n.at(-1)?.[0]==="else"&&(f=ut(n.pop().slice(1),e)),n.at(-1)?.[0]==="then"&&(l=ut(n.pop().slice(1),e));let c=[s];Y(n[0])&&c.push(n.shift()),c.push(Ot(n,e)),r.push(...ut(n,e),...c,...l),f.length&&r.push("else",...f),r.push("end")}else if(s==="try_table"){for(r.push(s),Y(n[0])&&r.push(n.shift()),r.push(Ot(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(...ut(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(...ut(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(...ut(n,e),s,...l),t.unshift(...r.splice(r.length-1-l.length))}}else r.push(i)}return r}var Ut=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),ne=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=Y(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},Dt=t=>{let e=ne(t,"param"),r=ne(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},Pt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...Dt(t)];let[,r]=t.shift(),[i,s]=Dt(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]]},Ot=(t,e)=>{let[r,i,s]=Pt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??Ut(i,s,e)]},ie=(t,e)=>{let r=Y(t[0])&&t.shift();return r&&(r in e?E(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},qe=([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(f=>Array.isArray(f)&&(f[0]==="descriptor"||f[0]==="describes")?(n.push(f),!1):!0)),[s,...t]=t,s==="func"?(t=Dt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=ne(t,"field"):s==="array"&&([t]=t);let l=[s,t,r,i];return n.length&&(l.desc=n),l},le=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...R(t),...i.flat()]},(t,e)=>{let[r,i,s,n,l]=t;if(l===!0)return;let f=(t.desc??[]).flatMap(([a,u])=>[a==="descriptor"?77:76,...I(B(u,e.type))]),c=(a,u)=>a==="func"?[yt.func,...R(u[0].map(m=>K(m,e))),...R(u[1].map(m=>K(m,e)))]:a==="array"?[yt.array,...Ft(u,e)]:a==="struct"?[yt.struct,...R(u.map(m=>Ft(m,e)))]:a==="cont"?[yt.cont,...I(B(u[0]??u,e.type))]:[yt[a]];if(l){let[a,u]=l,m=Array.from({length:u},(_,x)=>{let S=e.type[a+x],d=S.slice(0,4);return S.desc&&(d.desc=S.desc),le[P.type](d,e)});return[yt.rec,...R(m)]}else if(s==="sub"||n?.length)return[yt[s],...R(n.map(a=>B(a,e.type))),...f,...c(r,i)];return[...f,...c(r,i)]},([t,e,[r,...i]],s)=>{let n,l=re[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(l=32);let[[,c]]=i;n=I(B(c,s.type))}else if(r==="tag"){let[[,f]]=i;n=[0,...I(B(f,s.type))]}else r==="memory"?n=Ct(i):r==="global"?n=Ft(i[0],s):r==="table"?n=[...K(i.pop(),s),...Ct(i)]:E(`Unknown kind ${r}`);return[...R(t),...R(e),l,...n]},([[,t]],e)=>I(B(t,e.type)),(t,e)=>{let r=Ct(t),i=K(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...At(s,e)]:[...i,...r]},(t,e)=>Ct(t),([t,e],r)=>[...Ft(t,r),...At(e,r)],([t,[e,r]],i)=>[...R(t),re[e],...I(B(r,i[e]))],([t],e)=>I(B(t,e.func)),(t,e)=>{let r=0,i=0,s=0,n=0,l,f,c;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,l]=t.shift(),l=B(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=B(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(f=t.shift(),f[0]==="offset"&&([,f]=f),f=At(f,e)):i||(r=1),j[t[0]]||t[0]?.[0]==="ref"?c=K(t.shift(),e):t[0]==="func"?c=[j[t.shift()]]:c=[j.func],t=t.map(u=>(u[0]==="item"&&(u=u.length===3&&u[1]==="ref.func"?u[2]:u[1]),u[0]==="ref.func"&&([,u]=u),typeof u!="string"&&(s=1),u)),c[0]!==j.funcref&&(n=1,s=1);let a=s<<2|(r||i?i:!!l||n)<<1|(r||i);return[a,...a===0?f:a===1?[0]:a===2?[...I(l||0),...f,0]:a===3?[0]:a===4?f:a===5?c:a===6?[...I(l||0),...f,...c]:c,...R(t.map(s?u=>At(typeof u=="string"?["ref.func",u]:u,e):u=>I(B(u,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[B(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[,...u]=t.shift();if(Y(u[0])){let m=u.shift();m in e.local?E(`Duplicate local ${m}`):e.local[m]=e.local.length}e.local.push(...u)}e.meta={};let n=Le(t,e),l=e.local.slice(i.length).reduce((u,m)=>(m==u[u.length-1]?.[1]?u[u.length-1][0]++:u.push([1,m]),u),[]),f=R(l.map(([u,m])=>[...I(u),...K(m,e)])),c=e.import.filter(u=>u[2][0]==="func").length+s;for(let u in e.meta){for(let m of e.meta[u])m[0]+=f.length;((e.metadata??={})[u]??=[]).push([c,e.meta[u]])}e.local=e.block=e.meta=null;let a=R([...f,...n]);return(e.codeSizePrefix??=[])[s]=a.length-f.length-n.length,a},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=B(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=B(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??E("Bad offset",r)),[...i?[2,...I(i),...At(r,e)]:r?[0,...At(r,e)]:[1],...R(t.flatMap(s=>Fr(s)??[...s]))]},(t,e)=>I(e.data.length),([[,t]],e)=>[0,...I(B(t,e.type))]],K=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[j.refnull,98,...I(B(t[2][1],e.type))]:j[t[2]]?[j[t[2]]]:[j.refnull,...I(B(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[j.ref,98,...I(B(t[1][1],e.type))]:[j.ref,...I(j[t[t.length-1]]||B(t[t.length-1],e.type))]:[j[t]??E(`Unknown type ${t}`)],Ft=(t,e,r=t[0]==="mut"?1:0)=>[...K(r?t[1]:t,e),r],Re={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...I(B(i,e.elem)),...I(B(r,e.table))]},block:(t,e)=>{e.block.push(1),Y(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?K(r[1],e):I(B(r[1],e.type)):[j.void]},try_table:(t,e)=>{Y(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?K(r[1],e):I(B(r[1],e.type)):[j.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(),f=l[0]==="catch"?0:l[0]==="catch_ref"?1:l[0]==="catch_all"?2:3;f<=1?s.push(f,...I(B(l[1],e.tag)),...I(pt(l[2],e.block))):s.push(f,...I(pt(l[1],e.block))),n++}return e.block.push(1),[...i,...I(n),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...I(B(i,e.type)),...I(B(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||Y(t[0]));)r.push(...I(pt(t.shift(),e.block))),i++;return[...I(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?R(r.map(i=>K(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...I(B(r[1],e.type))]:j[r]?[j[r]]:I(B(r,e.type))},memarg:(t,e,r)=>Oe(t,r,et(t[0])&&!se(t[0])?B(t.shift(),e.memory):0),opt_memory:(t,e)=>I(B(et(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=K(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=pt(t.shift(),e.block),i=K(t.shift(),e),s=K(t.shift(),e),n=l=>l.length>1?l.slice(1):l;return[(s[0]!==j.ref)<<1|i[0]!==j.ref,...I(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 f=0;f<r;f++)l[f]=qt[e].parse(t.shift());return[...new Uint8Array(l.buffer)]}let n=new Uint8Array(16);for(let l=0;l<r;l++)n.set(qt[e](t.shift()),l*s);return[...n]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(Lt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&E("invalid lane length"),e},memlane:(t,e,r)=>{let i=Y(t[0])||et(t[0])&&(se(t[1])||et(t[1]))?B(t.shift(),e.memory):0;return[...Oe(t,r,i),...I(Lt(t.shift()))]},"*":t=>I(t.shift()),labelidx:(t,e)=>I(pt(t.shift(),e.block)),laneidx:t=>[Lt(t.shift(),255)],funcidx:(t,e)=>I(B(t.shift(),e.func)),typeidx:(t,e)=>I(B(t.shift(),e.type)),tableidx:(t,e)=>I(B(t.shift(),e.table)),memoryidx:(t,e)=>I(B(t.shift(),e.memory)),globalidx:(t,e)=>I(B(t.shift(),e.global)),localidx:(t,e)=>I(B(t.shift(),e.local)),dataidx:(t,e)=>I(B(t.shift(),e.data)),elemidx:(t,e)=>I(B(t.shift(),e.elem)),tagidx:(t,e)=>I(B(t.shift(),e.tag)),"memoryidx?":(t,e)=>I(B(et(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),I(s)},i32:t=>X(t.shift()),i64:t=>xt(t.shift()),f32:t=>dt(t.shift()),f64:t=>mt(t.shift()),v128:t=>ee(t.shift()),typeidx_field:(t,e)=>{let r=B(t.shift(),e.type);return[...I(r),...I(B(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...I(B(t.shift(),e.type)),...I(t.shift())],typeidx_dataidx:(t,e)=>[...I(B(t.shift(),e.type)),...I(B(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...I(B(t.shift(),e.type)),...I(B(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...I(B(t.shift(),e.type)),...I(B(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...I(B(t.shift(),e.data)),...I(B(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...I(B(t.shift(),e.memory)),...I(B(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...I(B(t.shift(),e.table)),...I(B(t.shift(),e.table))],cont_bind:(t,e)=>[...I(B(t.shift(),e.type)),...I(B(t.shift(),e.type))],switch_cont:(t,e)=>[...I(B(t.shift(),e.type)),...I(B(t.shift(),e.tag))],resume:(t,e)=>{let r=I(B(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...I(B(n,e.tag))):i.push(0,...I(B(n,e.tag)),...I(pt(l,e.block))),s++}return[...r,...I(s),...i]},resume_throw:(t,e)=>{let r=I(B(t.shift(),e.type)),i=I(B(t.shift(),e.tag)),s=[],n=0;for(;t[0]?.[0]==="on";){let[,l,f]=t.shift();f==="switch"?s.push(1,...I(B(l,e.tag))):s.push(0,...I(B(l,e.tag)),...I(pt(f,e.block))),n++}return[...r,...i,...I(n),...s]},resume_throw_ref:(t,e)=>{let r=I(B(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,n,l]=t.shift();l==="switch"?i.push(1,...I(B(n,e.tag))):i.push(0,...I(B(n,e.tag)),...I(pt(l,e.block))),s++}return[...r,...I(s),...i]}},Rt={};(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(" "),Mt[n]=r?[r,...I(i)]:[i],l&&(Rt[n]=Re[l])))})(Mt);var Le=(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&&(E.loc=s.loc),E(`Unknown instruction ${s[0]}`));let[...n]=Mt[s]||E(`Unknown instruction ${s}`);if(Rt[s]&&(s==="select"&&t[0]?.length?n[0]++:Rt[s]===Re.reftype&&!s.endsWith("_null")&&(t[0][1]==="null"||t[0][0]!=="ref")&&n[n.length-1]++,n.push(...Rt[s](t,e,s))),i.length){for(let[l,f]of i)(e.meta[l]??=[]).push([r.length,f]);i=[]}r.push(...n)}return r.push(11),r},At=(t,e)=>Le(ut([t],e),e),B=(t,e,r)=>(r=Y(t)?e[t]:+t,r in e?r:E(`Unknown ${e.name} ${t}`)),pt=(t,e,r)=>(r=Y(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?E(`Bad label ${t}`):r),qr=t=>{let e,r,i,s;for(;se(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:E(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&E(`Bad offset ${r}`),(e<=0||e>4294967295)&&E(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&E(`Bad align ${e}`),[e,r]},Oe=(t,e,r=0)=>{let[i,s]=qr(t),n=(i??Or(e))|(r&&64);return r?[...I(n),...I(r),...I(s??0)]:[...I(n),...I(s??0)]},Or=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)},Fr=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(X.parse(n)&511&255):e==="i16"?(s.setInt16(0,X.parse(n),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,X.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(...dt(n)):e==="f64"&&i.push(...mt(n));return i},Ct=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(a=>Array.isArray(a)&&a[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),f=e?a=>{if(typeof a=="bigint")return a;let u=typeof a=="string"?a.replaceAll("_",""):String(a);return BigInt(u)}:Lt,c=s>=0?I(s):[];return n?[l,...I(f(t.shift())),...I(f(t.shift())),...c]:[l,...I(f(t.shift())),...c]},Lt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?X.parse(t):typeof t=="number"?t:E(`Bad int ${t}`);return r>e?E(`Value out of range ${t}`):r},R=t=>[...I(t.length),...t.flat()];function Ue(t,e={}){typeof t=="string"&&(t=lt(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(f=>s||!n(f)).map(f=>l(f)).join(i);function n(f){return typeof f=="string"&&f[1]===";"}function l(f,c=0){if(!Array.isArray(f))return f;let a=f[0];if(!a)return"";let u=!1;if(a==="try_table"){let x=1;for(typeof f[x]=="string"&&f[x][0]==="$"&&(a+=" "+f[x++]),Array.isArray(f[x])&&(f[x][0]==="result"||f[x][0]==="type")&&(a+=" "+l(f[x++],c));Array.isArray(f[x])&&/^catch/.test(f[x][0]);)a+=" "+l(f[x++],c).trim();for(;x<f.length;x++)a+=Array.isArray(f[x])?i+r.repeat(c+1)+l(f[x],c+1):" "+f[x];return`(${a+i+r.repeat(c)})`}let m=!!i&&f.length<4&&!f.some(x=>typeof x=="string"&&x[0]===";"&&x[1]===";"),_=r.repeat(c+1);for(let x=1;x<f.length;x++){let S=f[x]?.valueOf?.()??f[x];if(typeof S=="string"&&S[1]===";"){if(!s)continue;if(S[0]===";")if(i)a+=i+_+S.trimEnd(),u=!0;else{let d=a[a.length-1];d&&d!==" "&&d!=="("&&(a+=" "),a+=S.trimEnd()+`
5
+ `}else{let d=a[a.length-1];d&&d!==" "&&d!=="("&&(a+=" "),a+=S.trimEnd()}}else if(Array.isArray(S))m&&(m=S.every(d=>!Array.isArray(d))),a+=i+_+l(S,c+1),u=!1;else if(f[0]==="data")m=!1,(i||a[a.length-1]!==")")&&(a+=i||" "),a+=_+S,u=!1;else{let d=a[a.length-1];u&&i?a+=i+_:d===`
6
+ `?a+="":(d&&d!==")"&&d!==" "||i||d===")")&&(a+=" "),a+=S,u=!1}}return m?`(${a.replaceAll(i+_+"("," (")})`:`(${a+i+r.repeat(c)})`}}var Pe=(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},Wt=(t,e,r)=>t.splice(e,0,r),Cr=0,ft=t=>`$__${t}${Cr++}`,Rr=(t,e)=>{let r=new Set;if(V(t,a=>{Array.isArray(a)&&a[0]==="ref.func"&&r.add(a[1])}),!r.size)return t;let i=ft("fntbl"),s=[...r],n=Object.fromEntries(s.map((a,u)=>[a,u])),l=Pe(t,"func"),f=l.length?l[0].idx:t[0]==="module"?1:0;Wt(t,f,["table",i,"funcref",["elem",...s]]);let c={};return V(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let u=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!u)return;let m=[],_=[];for(let x of a){if(Array.isArray(x)&&x[0]==="param")for(let S=1;S<x.length;S++)x[S][0]!=="$"&&m.push(x[S]);if(Array.isArray(x)&&x[0]==="result")for(let S=1;S<x.length;S++)_.push(x[S])}c[u]={params:m,results:_}}),J(t,(a,u,m)=>{if(!(!Array.isArray(a)||!u)){if(a[0]==="ref.func"&&n[a[1]]!==void 0&&(u[m]=["i32.const",n[a[1]]]),a[0]==="call_ref"){let _=a[1],x=a.slice(2);u[m]=["call_indirect",i,["type",_],...x]}if(a[0]==="return_call_ref"){let _=a[1],x=a.slice(2);u[m]=["return_call_indirect",i,["type",_],...x]}}}),t},Lr={"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]},Ur=(t,e)=>(J(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let n=Lr[r[0]];if(!n)return;let[l,f]=n,c=r.slice(1);i[s]=[`${l}.shr_s`,[`${l}.shl`,...c,[`${l}.const`,f]],[`${l}.const`,f]]}),t),De={"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}},Dr=(t,e)=>{let r=new Set;if(V(t,s=>{Array.isArray(s)&&De[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:n,ftype:l,signed:f,min:c,max:a}=De[s],u=ft(`trunc_${n}_${l}_${f?"s":"u"}`);i[s]=u;let m=`${n}.trunc_${l}_${f?"s":"u"}`,_=n==="i64"?0n:0,x=["func",u,["param","$v",l],["result",n],["if",["result",n],[`${l}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${n}.const`,_]],["else",["if",["result",n],[`${l}.lt`,["local.get","$v"],[`${l}.const`,typeof c=="bigint"?Number(c):c]],["then",[`${n}.const`,c]],["else",["if",["result",n],[`${l}.gt`,["local.get","$v"],[`${l}.const`,typeof a=="bigint"?Number(a):a]],["then",[`${n}.const`,a]],["else",[m,["local.get","$v"]]]]]]]]];t.push(x)}return J(t,(s,n,l)=>{!Array.isArray(s)||!n||i[s[0]]&&(n[l]=["call",i[s[0]],...s.slice(1)])}),t},Pr=(t,e)=>{let r=new Set,i=new Set;V(t,l=>{if(Array.isArray(l)){if(l[0]==="memory.copy"){let f=typeof l[1]=="number"?l[1]:0,c=typeof l[2]=="number"?l[2]:0;r.add(`${f}_${c}`)}if(l[0]==="memory.fill"){let f=typeof l[1]=="number"?l[1]:0;i.add(f)}}});let s={},n={};for(let l of r){let[f,c]=l.split("_").map(Number),a=ft(`memcpy${l==="0_0"?"":"_"+l}`);s[l]=a;let u=f?["i32.store8",f]:["i32.store8"],m=c?["i32.load8_u",c]:["i32.load8_u"];t.push(["func",a,["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"]]],[...u,["i32.add",["local.get","$dst"],["local.get","$i"]],[...m,["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 f=ft(`memset${l===0?"":"_"+l}`);n[l]=f;let c=l?["i32.store8",l]:["i32.store8"];t.push(["func",f,["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"]]],[...c,["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 J(t,(l,f,c)=>{if(!(!Array.isArray(l)||!f)){if(l[0]==="memory.copy"){let a=typeof l[1]=="number"?l[1]:0,u=typeof l[2]=="number"?l[2]:0,m=l.filter(_=>Array.isArray(_)||typeof _=="string"&&_[0]==="$");f[c]=["call",s[`${a}_${u}`],...m]}if(l[0]==="memory.fill"){let a=typeof l[1]=="number"?l[1]:0,u=l.filter(m=>Array.isArray(m)||typeof m=="string"&&m[0]==="$");f[c]=["call",n[a],...u]}}}),t},Wr=(t,e)=>{let r=!1;return V(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&J(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},jr=(t,e)=>(J(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),Gr=(t,e)=>{let r={};V(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 f=s[l];if(Array.isArray(f)&&(f[0]==="i32.const"||f[0]==="i64.const"||f[0]==="f32.const"||f[0]==="f64.const")){r[n]={type:f[0].split(".")[0],value:f[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]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let c=n.split(".")[0],a=c==="i64"?BigInt(l[1]):Number(l[1]),u=c==="i64"?BigInt(f[1]):Number(f[1]);return[`${c}.const`,a+u]}}if(n==="i32.sub"||n==="i64.sub"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let c=n.split(".")[0],a=c==="i64"?BigInt(l[1]):Number(l[1]),u=c==="i64"?BigInt(f[1]):Number(f[1]);return[`${c}.const`,a-u]}}if(n==="i32.mul"||n==="i64.mul"){let l=i(s[1]),f=i(s[2]);if(l&&f&&l[0]?.endsWith(".const")&&f[0]?.endsWith(".const")){let c=n.split(".")[0],a=c==="i64"?BigInt(l[1]):Number(l[1]),u=c==="i64"?BigInt(f[1]):Number(f[1]);return[`${c}.const`,a*u]}}return s};return J(t,(s,n,l)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!n)){for(let f=2;f<s.length;f++)if(Array.isArray(s[f])){let c=i(s[f]);c!==s[f]&&(s[f]=c)}}}),t},Hr=(t,e)=>{let r=new Map,i=[];if(V(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null,a=[];for(let u of f)if(Array.isArray(u)&&u[0]==="result")for(let m=1;m<u.length;m++)a.push(u[m]);a.length>1&&c&&r.set(c,a)}),!r.size)return t;let s=Math.max(...[...r.values()].map(f=>f.length)),n={};for(let[f,c]of r)for(let a=1;a<c.length;a++){let u=c[a];if(n[u]||(n[u]=[]),n[u].length<a){let m=ft(`ret_${u}_${n[u].length}`);n[u].push(m),i.push(["global",m,["mut",u],[`${u}.const`,u==="i64"?0n:0]])}}let l=t[0]==="module"?1:0;for(let f of i.reverse())Wt(t,l,f);return J(t,(f,c,a)=>{if(!Array.isArray(f)||f[0]!=="func")return;let u=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!u||!r.has(u))return;let m=r.get(u);for(let _=0;_<f.length;_++)if(Array.isArray(f[_])&&f[_][0]==="result"){f[_]=["result",m[0]];break}}),t},Bt={i32:4,i64:8,f32:4,f64:8},Vr=(t,e)=>{let r=new Map,i=new Map,s=1;if(V(t,d=>{if(!Array.isArray(d)||d[0]!=="type")return;let h=typeof d[1]=="string"&&d[1][0]==="$"?d[1]:null;if(h){for(let w of d)if(Array.isArray(w)){if(w[0]==="struct"){let o=[];for(let y of w)if(Array.isArray(y)&&y[0]==="field"){let p=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:null,g=p?y[2]:y[1],A=Array.isArray(g)&&g[0]==="mut"?g[1]:g;o.push({name:p,type:A})}r.set(h,{kind:"struct",fields:o}),i.set(h,s++)}if(w[0]==="array"){let o=w[1],y=Array.isArray(o)&&o[0]==="mut"?o[1]:o;r.set(h,{kind:"array",elemType:y}),i.set(h,s++)}}}}),!r.size)return t;let n=Pe(t,"memory").length>0,l=ft("alloc"),f=ft("heap_ptr"),c=t[0]==="module"?1:0;n||Wt(t,c,["memory",1]),Wt(t,c+1,["global",f,["mut","i32"],["i32.const",1024]]);let a=["func",l,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",f]],["global.set",f,["i32.add",["global.get",f],["local.get","$size"]]],["local.get","$ptr"]];t.push(a);let u=d=>{let h=4;for(let w of d.fields)h+=Bt[w.type]||4;return h},m=(d,h)=>{let w=4;for(let o=0;o<h;o++)w+=Bt[d.fields[o].type]||4;return w},_=(d,h)=>{for(let w=0;w<d.fields.length;w++)if(d.fields[w].name===h)return w;return-1},x=0,S=()=>`$__gc_tmp${x++}`;return V(t,d=>{if(!Array.isArray(d)||d[0]!=="func")return;let h=!1,w=!1,o=!1,y=!1;if(V(d,g=>{Array.isArray(g)&&((g[0]==="struct.new"||g[0]==="struct.new_default")&&(h=!0),(g[0]==="array.new"||g[0]==="array.new_default")&&(w=!0,o=!0,y=!0))}),!h&&!w)return;let p=1;for(let g=1;g<d.length;g++){let A=d[g];if(Array.isArray(A)&&(A[0]==="param"||A[0]==="result"||A[0]==="local"||A[0]==="export"||A[0]==="type"))p=g+1;else if(typeof A=="string"&&A[0]==="$")p=g+1;else if(!Array.isArray(A))p=g+1;else break}h&&d.splice(p++,0,["local","$__gc_ptr","i32"]),w&&d.splice(p++,0,["local","$__gc_aptr","i32"]),o&&d.splice(p++,0,["local","$__gc_alen","i32"]),y&&d.splice(p++,0,["local","$__gc_aidx","i32"])}),J(t,(d,h,w)=>{if(!(!Array.isArray(d)||!h)){if(d[0]==="struct.new"||d[0]==="struct.new_default"){let o=d[1],y=r.get(o);if(!y||y.kind!=="struct")return;let p=u(y),g=i.get(o),A=d.slice(2),b="$__gc_ptr",M=[["local.set",b,["call",l,["i32.const",p]]],["i32.store",["local.get",b],["i32.const",g]]];if(d[0]==="struct.new")for(let N=0;N<y.fields.length;N++){let v=y.fields[N],k=m(y,N),z=v.type==="i64"?"i64.store":v.type==="f32"?"f32.store":v.type==="f64"?"f64.store":"i32.store";M.push([z,["i32.add",["local.get",b],["i32.const",k]],A[N]||[`${v.type}.const`,0]])}else for(let N=0;N<y.fields.length;N++){let v=y.fields[N],k=m(y,N),z=v.type==="i64"?"i64.store":v.type==="f32"?"f32.store":v.type==="f64"?"f64.store":"i32.store",$=v.type==="i64"?["i64.const",0n]:v.type==="f32"?["f32.const",0]:v.type==="f64"?["f64.const",0]:["i32.const",0];M.push([z,["i32.add",["local.get",b],["i32.const",k]],$])}M.push(["local.get",b]),h[w]=["block",["result","i32"],...M]}if(d[0]==="struct.get"){let o=d[1],y=d[2],p=d[3],g=r.get(o);if(!g||g.kind!=="struct")return;let A=typeof y=="string"&&y[0]==="$"?_(g,y):parseInt(y);if(A<0)return;let b=g.fields[A],M=m(g,A),N=b.type==="i64"?"i64.load":b.type==="f32"?"f32.load":b.type==="f64"?"f64.load":"i32.load";h[w]=[N,["i32.add",p,["i32.const",M]]]}if(d[0]==="struct.set"){let o=d[1],y=d[2],p=d[3],g=d[4],A=r.get(o);if(!A||A.kind!=="struct")return;let b=typeof y=="string"&&y[0]==="$"?_(A,y):parseInt(y);if(b<0)return;let M=A.fields[b],N=m(A,b),v=M.type==="i64"?"i64.store":M.type==="f32"?"f32.store":M.type==="f64"?"f64.store":"i32.store";h[w]=[v,["i32.add",p,["i32.const",N]],g]}if(d[0]==="array.new"||d[0]==="array.new_default"){let o=d[1],y=r.get(o);if(!y||y.kind!=="array")return;let p=i.get(o),g=Bt[y.elemType]||4,A=d[0]==="array.new"?d[2]:null,b=d[0]==="array.new"?d[3]:d[2],M="$__gc_aptr",N="$__gc_alen",v="$__gc_aidx",k=y.elemType==="i64"?"i64.store":y.elemType==="f32"?"f32.store":y.elemType==="f64"?"f64.store":"i32.store",z=[["local.set",N,b],["local.set",M,["call",l,["i32.add",["i32.const",8],["i32.mul",["local.get",N],["i32.const",g]]]]],["i32.store",["local.get",M],["i32.const",p]],["i32.store",["i32.add",["local.get",M],["i32.const",4]],["local.get",N]]];A&&z.push(["local.set",v,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",v],["local.get",N]]],[k,["i32.add",["i32.add",["local.get",M],["i32.const",8]],["i32.mul",["local.get",v],["i32.const",g]]],A],["local.set",v,["i32.add",["local.get",v],["i32.const",1]]],["br","$loop"]]]),z.push(["local.get",M]),h[w]=["block",["result","i32"],...z]}if(d[0]==="array.get"){let o=d[1],y=d[2],p=d[3],g=r.get(o);if(!g||g.kind!=="array")return;let A=Bt[g.elemType]||4,b=g.elemType==="i64"?"i64.load":g.elemType==="f32"?"f32.load":g.elemType==="f64"?"f64.load":"i32.load";h[w]=[b,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",p,["i32.const",A]]]]}if(d[0]==="array.set"){let o=d[1],y=d[2],p=d[3],g=d[4],A=r.get(o);if(!A||A.kind!=="array")return;let b=Bt[A.elemType]||4,M=A.elemType==="i64"?"i64.store":A.elemType==="f32"?"f32.store":A.elemType==="f64"?"f64.store":"i32.store";h[w]=[M,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",p,["i32.const",b]]],g]}if(d[0]==="array.len"){let o=d[1];h[w]=["i32.load",["i32.add",o,["i32.const",4]]]}}}),t},Yr=(t,e)=>{let r=new Map,i=1;return V(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&&J(t,(s,n,l)=>{if(!(!Array.isArray(s)||!n)){if(s[0]==="ref.test"){let f=s[1],c=null;Array.isArray(f)&&f[0]==="ref"&&(c=f[1]==="null"?f[2]:f[1]);let a=s[2],u=r.get(c);u!==void 0&&(n[l]=["if",["result","i32"],["i32.eqz",a],["then",["i32.const",0]],["else",["i32.eq",["i32.load",a],["i32.const",u]]]])}if(s[0]==="ref.cast"){let f=s[1],c=null,a=!1;Array.isArray(f)&&f[0]==="ref"&&(f[1]==="null"?(a=!0,c=f[2]):c=f[1]);let u=s[2],m=r.get(c);if(m!==void 0){let _=ft("cast");a?n[l]=["block",["result","i32"],["local",_,"i32"],["local.set",_,u],["if",["i32.and",["i32.ne",["local.get",_],["i32.const",0]],["i32.ne",["i32.load",["local.get",_]],["i32.const",m]]],["then",["unreachable"]]],["local.get",_]]:n[l]=["block",["result","i32"],["local",_,"i32"],["local.set",_,u],["if",["i32.or",["i32.eqz",["local.get",_]],["i32.ne",["i32.load",["local.get",_]],["i32.const",m]]],["then",["unreachable"]]],["local.get",_]]}}if(s[0]==="br_on_cast"){let f=s[1],c=s[2],a=s[3],u=s[4],m=null;Array.isArray(a)&&a[0]==="ref"&&(m=a[1]==="null"?a[2]:a[1]);let _=r.get(m);if(_!==void 0){let x=ft("brcast");n[l]=["block",["result","i32"],["local",x,"i32"],["local.set",x,u],["br_if",f,["i32.and",["i32.ne",["local.get",x],["i32.const",0]],["i32.eq",["i32.load",["local.get",x]],["i32.const",_]]]],["local.get",x]]}}if(s[0]==="br_on_cast_fail"){let f=s[1],c=s[2],a=s[3],u=s[4],m=null;Array.isArray(a)&&a[0]==="ref"&&(m=a[1]==="null"?a[2]:a[1]);let _=r.get(m);if(_!==void 0){let x=ft("brfail");n[l]=["block",["result","i32"],["local",x,"i32"],["local.set",x,u],["br_if",f,["i32.or",["i32.eqz",["local.get",x]],["i32.ne",["i32.load",["local.get",x]],["i32.const",_]]]],["local.get",x]]}}}}),t},jt=[["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"],Ur],["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"],Dr],["bulk_memory",["memory.copy","memory.fill"],Pr],["return_call",["return_call","return_call_indirect"],Wr],["i31ref",["ref.i31","i31.get_s","i31.get_u"],jr],["extended_const",["global.get"],Gr],["multi_value",[],Hr],["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"],Vr],["ref_cast",["ref.test","ref.cast","br_on_cast","br_on_cast_fail"],Yr]],ks=Object.fromEntries(jt.map(t=>[t[0],t[1]])),Xr=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 jt)r[i[0]]=e?e.has("all")||e.has(i[0]):!0;return r},Zr=t=>{let e=new Set;return V(t,r=>{if(typeof r=="string")for(let i of jt)i[1].some(n=>r===n||r.startsWith(n+" "))&&e.add(i[0])}),V(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")&&V(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),V(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 fe(t,e=!0){typeof t=="string"&&(t=lt(t)),t=Jt(t),e=Xr(e);let r=Zr(t),i={uid:0};for(let s of jt){let n=s[2];r.has(s[0])&&e[s[0]]!==!1&&(t=n(t,i))}return t}var Kr=6,Qe=16,Q=t=>Array.isArray(t)?t.map(Q):t,C=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)C(t[s],e,t,s)},H=(t,e,r,i)=>{if(Array.isArray(t))for(let n=0;n<t.length;n++)H(t[n],e,t,n);let s=e(t,r,i);return s!==void 0&&r&&(r[i]=s),s!==void 0?s:t},We=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};var je=t=>{try{return bt(t).length}catch{return 1/0}},nt=(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(!nt(t[r],e[r]))return!1;return!0},vt=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}},Qr=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,f=(v,k,z,$=!1)=>{let T=typeof k[1]=="string"&&k[1][0]==="$",F=T?k[1]:z,st=!$&&k.some(O=>Array.isArray(O)&&O[0]==="export"),W={node:k,idx:z,used:st,isImport:$};return v.set(F,W),T&&v.set(z,W),l.set(k,W),W},c=0,a=0,u=0,m=0,_=0,x=[],S=[],d=[],h=[];for(let v of t.slice(1)){if(!Array.isArray(v))continue;let k=v[0];if(k==="type")f(i,v,u++);else if(k==="func")f(e,v,c++);else if(k==="global")f(r,v,a++);else if(k==="table")f(s,v,m++);else if(k==="memory")f(n,v,_++);else if(k==="import")for(let z of v)Array.isArray(z)&&(z[0]==="func"?f(e,z,c++,!0):z[0]==="global"?f(r,z,a++,!0):z[0]==="table"?f(s,z,m++,!0):z[0]==="memory"&&f(n,z,_++,!0));else k==="export"?d.push(v):k==="start"?h.push(v):k==="elem"?x.push(v):k==="data"&&S.push(v)}let w=[],o=v=>{v&&!v.scanned&&w.push(v)},y=v=>{let k=e.get(v);k&&(k.used||(k.used=!0),o(k))},p=v=>{let k=r.get(v);k&&(k.used=!0)},g=v=>{let k=s.get(v);k&&(k.used=!0)},A=v=>{typeof v=="string"&&v[0]!=="$"&&(v=+v);let k=n.get(v);k&&(k.used=!0)},b=v=>{let k=i.get(v);k&&(k.used=!0)};for(let v of d)for(let k of v){if(!Array.isArray(k))continue;let[z,$]=k;z==="func"?y($):z==="global"?p($):z==="table"?g($):z==="memory"&&A($)}for(let v of h){let k=v[1];typeof k=="string"&&k[0]!=="$"&&(k=+k),y(k)}for(let v of x)C(v,k=>{Array.isArray(k)&&k[0]==="ref.func"?y(k[1]):typeof k=="string"&&k[0]==="$"&&y(k)});for(let v of S){let k=v[1];Array.isArray(k)&&k[0]==="memory"?A(k[1]):typeof k=="string"&&k[0]==="$"?A(k):Array.isArray(k)&&A(0)}for(let v of[e,r,s,n])for(let k of v.values())k.used&&o(k);if(!(d.length>0||h.length>0||x.length>0||w.length>0)){for(let v of[e,r,s,n])for(let k of v.values())k.used=!0;return t}for(;w.length;){let v=w.pop();v.scanned||(v.scanned=!0,!v.isImport&&C(v.node,k=>{if(!Array.isArray(k)){typeof k=="string"&&k[0]==="$"&&y(k);return}let[z,$]=k;if(z==="call"||z==="return_call"||z==="ref.func")y($);else if(z==="global.get"||z==="global.set")p($);else if(z==="type")b($);else if(z==="call_indirect"||z==="return_call_indirect")for(let T of k)typeof T=="string"&&T[0]==="$"&&g(T);typeof z=="string"&&(z.startsWith("memory.")||z.includes(".load")||z.includes(".store"))&&A(0)}))}let N=["module"];for(let v of t.slice(1)){if(!Array.isArray(v)){N.push(v);continue}let k=v[0];if(k==="func"||k==="global"||k==="type")l.get(v)?.used&&N.push(v);else if(k==="import"){let z=!1;for(let $ of v){if(!Array.isArray($))continue;if(l.get($)?.used){z=!0;break}}z&&N.push(v)}else N.push(v)}return N},Ge=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),Je=new ArrayBuffer(8),pe=new Float64Array(Je),It=new Uint32Array(Je),tr=new ArrayBuffer(4),ge=new Float32Array(tr),me=new Int32Array(tr),Z=t=>(t>>>0).toString(16).padStart(8,"0"),Jr=t=>{let e="",r=1;for(let i=15;i>=0;i--){let s=15-parseInt(t[i],16)+r;e=(s&15).toString(16)+e,r=s>>4}return e},zt=t=>{let e=t.toString(16);return e[0]==="-"?Jr(e.slice(1).padStart(16,"0")):e.padStart(16,"0")},G="0x0000000000000000",oe="0x0000000000000001",Kt="0xffffffffffffffff",gt=t=>{if(typeof t=="string"){let e=t.replaceAll("_","");if(e.length===18&&e[1]==="x")return"0x"+e.slice(2).toLowerCase();let r=e[0]==="-",i=e[0]==="-"||e[0]==="+"?e.slice(1):e;return"0x"+zt(r?-BigInt(i):BigInt(i))}return typeof t=="bigint"?"0x"+zt(BigInt(String(t))):"0x"+zt(BigInt(Math.trunc(t)||0))},He=t=>(parseInt(t[2],16)^8).toString(16)+t.slice(3),Gt=t=>parseInt(t.slice(10),16)|0,at=t=>parseInt(t.slice(2,10),16)>>>0,rt=t=>t==null?null:"0x"+zt(t),Nt=t=>{let e=BigInt(t);return e>0x7fffffffffffffffn&&(e=e-0x8000000000000000n-0x8000000000000000n),e},ti=t=>(pe[0]=t,"0x"+Z(It[1])+Z(It[0])),ei=t=>(It[1]=parseInt(t.slice(2,10),16),It[0]=parseInt(t.slice(10),16),pe[0]),ri=t=>(ge[0]=t,me[0]),ii=t=>(me[0]=t|0,ge[0]),wt=t=>(e,r)=>t(e,r)?1:0,Ht=t=>(e,r)=>t(e>>>0,r>>>0)?1:0,Vt=t=>(e,r)=>t(He(e),He(r))?1:0,Yt=t=>(e,r)=>t(e,r)?1:0,si={"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":wt((t,e)=>t===e),"i32.ne":wt((t,e)=>t!==e),"i32.lt_s":wt((t,e)=>t<e),"i32.lt_u":Ht((t,e)=>t<e),"i32.gt_s":wt((t,e)=>t>e),"i32.gt_u":Ht((t,e)=>t>e),"i32.le_s":wt((t,e)=>t<=e),"i32.le_u":Ht((t,e)=>t<=e),"i32.ge_s":wt((t,e)=>t>=e),"i32.ge_u":Ht((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=>Gt(t),"i32.extend8_s":t=>t<<24>>24,"i32.extend16_s":t=>t<<16>>16,"i64.add":(t,e)=>rt(BigInt(t)+BigInt(e)&0xffffffffffffffffn),"i64.sub":(t,e)=>rt(BigInt(t)-BigInt(e)&0xffffffffffffffffn),"i64.mul":(t,e)=>rt(BigInt(t)*BigInt(e)&0xffffffffffffffffn),"i64.div_s":(t,e)=>e!==G&&!(t==="0x8000000000000000"&&e===Kt)?rt(Nt(t)/Nt(e)&0xffffffffffffffffn):null,"i64.div_u":(t,e)=>e!==G&&!(at(t)>>>31)&&!(at(e)>>>31)?rt(BigInt(t)/BigInt(e)):null,"i64.rem_s":(t,e)=>e!==G?rt(Nt(t)%Nt(e)&0xffffffffffffffffn):null,"i64.rem_u":(t,e)=>e!==G&&!(at(t)>>>31)&&!(at(e)>>>31)?rt(BigInt(t)%BigInt(e)):null,"i64.and":(t,e)=>rt(BigInt(t)&BigInt(e)&0xffffffffffffffffn),"i64.or":(t,e)=>rt((BigInt(t)|BigInt(e))&0xffffffffffffffffn),"i64.xor":(t,e)=>rt((BigInt(t)^BigInt(e))&0xffffffffffffffffn),"i64.shl":(t,e)=>rt(BigInt(t)<<(BigInt(e)&63n)&0xffffffffffffffffn),"i64.shr_s":(t,e)=>rt(Nt(t)>>(BigInt(e)&63n)&0xffffffffffffffffn),"i64.shr_u":(t,e)=>{let r=parseInt(e.slice(10),16)&63,i=at(t),s=parseInt(t.slice(10),16)>>>0,n=r>=32?0:i>>>r,l=r===0?s:r>=32?i>>>r-32:(s>>>r|i<<32-r)>>>0;return"0x"+Z(n)+Z(l)},"i64.eq":(t,e)=>t===e?1:0,"i64.ne":(t,e)=>t!==e?1:0,"i64.lt_s":Vt((t,e)=>t<e),"i64.lt_u":Yt((t,e)=>t<e),"i64.gt_s":Vt((t,e)=>t>e),"i64.gt_u":Yt((t,e)=>t>e),"i64.le_s":Vt((t,e)=>t<=e),"i64.le_u":Yt((t,e)=>t<=e),"i64.ge_s":Vt((t,e)=>t>=e),"i64.ge_u":Yt((t,e)=>t>=e),"i64.eqz":t=>t===G?1:0,"i64.extend_i32_s":t=>"0x"+Z(t>>31)+Z(t),"i64.extend_i32_u":t=>"0x00000000"+Z(t),"i64.extend8_s":t=>{let e=Gt(t)<<24>>24;return"0x"+Z(e>>31)+Z(e)},"i64.extend16_s":t=>{let e=Gt(t)<<16>>16;return"0x"+Z(e>>31)+Z(e)},"i64.extend32_s":t=>{let e=Gt(t);return"0x"+Z(e>>31)+Z(e)},"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(Ge(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":Ge,"i32.reinterpret_f32":ri,"f32.reinterpret_i32":ii,"i64.reinterpret_f64":ti,"f64.reinterpret_i64":ei,"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((at(t)|0)*4294967296+parseInt(t.slice(10),16)),"f32.convert_i64_u":t=>Math.fround(at(t)*4294967296+parseInt(t.slice(10),16)),"f64.convert_i32_s":t=>t|0,"f64.convert_i32_u":t=>t>>>0,"f64.convert_i64_s":t=>(at(t)|0)*4294967296+parseInt(t.slice(10),16),"f64.convert_i64_u":t=>at(t)*4294967296+parseInt(t.slice(10),16),"f32.demote_f64":t=>Math.fround(t),"f64.promote_f32":t=>Math.fround(t)},ni=t=>{let e=t?.indexOf?.("nan");if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),s=(t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n).toString(16).padStart(16,"0"),n=(parseInt(s.slice(0,8),16)|2146435072|(t[0]==="-"?2147483648:0))>>>0;return"0x"+Z(n)+s.slice(8)},li=(t,e=t?.indexOf?.("nan"))=>{if(e<0||e==null)return null;let r=t.slice(e+4).replaceAll("_",""),s=(t[e+3]===":"&&r!=="canonical"&&r!=="arithmetic"?BigInt(r):0x8000000000000n).toString(16).padStart(16,"0");return It[1]=(parseInt(s.slice(0,8),16)|2146435072|(t[0]==="-"?2147483648:0))>>>0,It[0]=parseInt(s.slice(8),16),pe[0]},fi=(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 me[0]=i|2139095040|(t[0]==="-"?2147483648:0)|0,ge[0]},q=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"?parseInt(r.replaceAll("_","")):r)|0};if(e==="i64.const")return{type:"i64",value:gt(r)};if(e==="f32.const"){let i=fi(r);return{type:"f32",value:i!==null?i:Math.fround(Number(r))}}if(e==="f64.const"){let i=li(r),s=i!==null?i:Number(r);return{type:"f64",value:Number.isNaN(s)?NaN:s}}return null},Ve=(t,e)=>{if(t==="i32")return["i32.const",e|0];if(t==="i64")return["i64.const",typeof e=="number"?e:gt(e)];if(t==="f32"){let r=Math.fround(e);return["f32.const",Number.isNaN(r)?"nan":r]}return t==="f64"?["f64.const",Number.isNaN(e)?"nan":e]:null},oi=t=>H(t,e=>{if(!Array.isArray(e))return;let r=si[e[0]];if(r){if(e.length===2){if(e[0]==="i64.reinterpret_f64"){let n=e[1];if(Array.isArray(n)&&n.length===2&&n[0]==="f64.const"&&typeof n[1]=="string"){let l=ni(n[1]);if(l)return["i64.const",l]}}if(e[0]==="f64.reinterpret_i64"){let n=q(e[1]);if(n&&n.type==="i64"){let l=n.value.slice(2),f=parseInt(l.slice(0,8),16)>>>0,c=parseInt(l.slice(8),16)>>>0;if((f&2146435072)===2146435072&&((f&1048575)!==0||c!==0))return["f64.const",(f&2147483648?"-":"")+"nan:0x"+(f&1048575).toString(16).padStart(5,"0")+l.slice(8)]}}let i=q(e[1]);if(!i)return;let s=r(i.value);return s==null?void 0:Ve(We(e[0]),s)}if(e.length===3){let i=q(e[1]),s=q(e[2]);if(!i||!s)return;let n=r(i.value,s.value);return n==null?void 0:Ve(We(e[0]),n)}}}),ot=t=>(e,r)=>{let i=q(e),s=q(r);return i?.value===t?r:s?.value===t?e:null},it=t=>(e,r)=>q(r)?.value===t?e:null,ai={"i32.add":ot(0),"i64.add":ot(G),"i32.sub":it(0),"i64.sub":it(G),"i32.mul":ot(1),"i64.mul":ot(oe),"i32.div_s":it(1),"i32.div_u":it(1),"i64.div_s":it(oe),"i64.div_u":it(oe),"i32.and":ot(-1),"i64.and":ot(Kt),"i32.or":ot(0),"i64.or":ot(G),"i32.xor":ot(0),"i64.xor":ot(G),"i32.shl":it(0),"i32.shr_s":it(0),"i32.shr_u":it(0),"i64.shl":it(G),"i64.shr_s":it(G),"i64.shr_u":it(G)},ci=t=>H(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=ai[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),ui=t=>H(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let n=q(s);if(n&&n.value>0&&!(n.value&n.value-1)){let f=Math.log2(n.value);if(Number.isInteger(f))return["i32.shl",i,["i32.const",f]]}let l=q(i);if(l&&l.value>0&&!(l.value&l.value-1)){let f=Math.log2(l.value);if(Number.isInteger(f))return["i32.shl",s,["i32.const",f]]}}if(r==="i64.mul"){let n=q(s),l=n?BigInt(n.value):null;if(l!=null&&l>0n&&(l&l-1n)===0n)return["i64.shl",i,["i64.const",l.toString(2).length-1]];let f=q(i),c=f?BigInt(f.value):null;if(c!=null&&c>0n&&(c&c-1n)===0n)return["i64.shl",s,["i64.const",c.toString(2).length-1]]}if(r==="i32.div_u"){let n=q(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=q(s),l=n?BigInt(n.value):null;if(l!=null&&l>0n&&(l&l-1n)===0n)return["i64.shr_u",i,["i64.const",l.toString(2).length-1]]}if(r==="i32.rem_u"){let n=q(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=q(s),l=n?BigInt(n.value):null;if(l!=null&&l>0n&&(l&l-1n)===0n)return["i64.and",i,["i64.const","0x"+zt(l-1n)]]}}),yi=t=>H(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let{condIdx:i,cond:s,thenBranch:n,elseBranch:l}=vt(e),f=q(s);if(!f)return;let c=f.value!==0&&f.value!==G?n:l;if(c&&c.length>1){let a=c.slice(1),u=e.slice(1,i).filter(m=>Array.isArray(m)&&(m[0]==="result"||m[0]==="param"));return u.length?["block",...u,...a]:a.length===1?a[0]:["block",...a]}return["nop"]}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=q(i);return s?s.value===0||s.value===G?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=q(i);return s?s.value===0||s.value===G?e[2]:e[1]:void 0}}),pi=t=>{if(Array.isArray(t))for(let e of t)Array.isArray(e)&&e[0]==="func"&&gi(e);return t},_e=new Set,gi=t=>{let e=new Map,r=new Map,i=new Map,s=new Map,n=o=>{if(!Array.isArray(o)||o.length!==2||o[0]!=="i32.const"&&o[0]!=="i64.const")return null;let y=typeof o[1]=="string"?Number(o[1].replaceAll("_","")):Number(o[1]);return Number.isFinite(y)?y:null},l=o=>Array.isArray(o)&&o[0]==="i32.const"?n(o):null,f=o=>Array.isArray(o)?o[0]==="i64.reinterpret_f64"&&Array.isArray(o[1])&&o[1][0]==="local.get"&&typeof o[1][1]=="string"?o[1][1]:o[0]==="local.get"&&typeof o[1]=="string"?e.get(o[1])??null:null:null,c=o=>{if(!Array.isArray(o))return null;let y=o[0];if(y==="local.get"&&typeof o[1]=="string")return r.get(o[1])??null;if(y==="call"&&o[1]==="$__ptr_type"&&o.length===3)return f(o[2]);let p=g=>Array.isArray(g)&&g[0]==="i64.shr_u"&&n(g[2])===47?f(g[1]):null;if(y==="i32.and"&&o.length===3){let[g,A]=l(o[2])===15?[o[1],null]:l(o[1])===15?[o[2],null]:[null,null];if(g&&Array.isArray(g)&&g[0]==="i32.wrap_i64")return p(g[1])}if(y==="i32.wrap_i64"&&Array.isArray(o[1])&&o[1][0]==="i64.and"){let g=o[1];if(n(g[2])===15)return p(g[1]);if(n(g[1])===15)return p(g[2])}return null},a=o=>{e.delete(o),r.delete(o),i.delete(o),s.delete(o);for(let[y,p]of e)p===o&&e.delete(y);for(let[y,p]of r)p===o&&r.delete(y)},u=new Map,m=o=>{if(!Array.isArray(o))return _e;let y=u.get(o);if(y)return y;y=new Set,(o[0]==="local.set"||o[0]==="local.tee")&&typeof o[1]=="string"&&y.add(o[1]);for(let p=1;p<o.length;p++)for(let g of m(o[p]))y.add(g);return u.set(o,y),y},_=()=>[new Map(i),new Map([...s].map(([o,y])=>[o,new Set(y)])),new Map(e),new Map(r)],x=(o,y)=>{o.clear();for(let[p,g]of y)o.set(p,g)},S=([o,y,p,g])=>{x(i,o),x(s,y),x(e,p),x(r,g)},d=(o,y,p)=>{if(!Array.isArray(o))return p;let g=o[0];if(g==="i32.eqz")return d(o[1],!y,p);if(g==="i32.and"&&y&&o.length===3)return d(o[1],!0,p),d(o[2],!0,p),p;if(g==="i32.or"&&!y&&o.length===3)return d(o[1],!1,p),d(o[2],!1,p),p;if((g==="i32.eq"||g==="i32.ne")&&o.length===3){let b=c(o[1]),M=l(o[2]);return(b==null||M==null)&&(b=c(o[2]),M=l(o[1])),b!=null&&M!=null&&p.push({x:b,k:M,eq:g==="i32.eq"===y}),p}let A=c(o);return A!=null&&p.push({x:A,k:0,eq:!y}),p},h=o=>{for(let{x:y,k:p,eq:g}of o)if(g)i.set(y,p);else{let A=s.get(y);A||s.set(y,A=new Set),A.add(p)}},w=(o,y,p)=>{if(!Array.isArray(o))return;let g=o[0];if(g==="local.set"||g==="local.tee"){Array.isArray(o[2])&&w(o[2],o,2);let b=o[1];if(typeof b!="string")return;a(b);let M=o[2];if(Array.isArray(M))if(M[0]==="i64.reinterpret_f64"&&Array.isArray(M[1])&&M[1][0]==="local.get"&&typeof M[1][1]=="string")e.set(b,M[1][1]);else if(M[0]==="local.get"&&typeof M[1]=="string"&&e.has(M[1]))e.set(b,e.get(M[1]));else{let N=c(M);N!=null&&r.set(b,N)}return}if(g==="if"){let{condIdx:b}=vt(o);Array.isArray(o[b])&&w(o[b],o,b);let M=o[b],{thenBranch:N,elseBranch:v}=vt(o),k=m(o),z=_();if(h(d(M,!0,[])),N)for(let $=1;$<N.length;$++)w(N[$],N,$);if(S(z),h(d(M,!1,[])),v)for(let $=1;$<v.length;$++)w(v[$],v,$);S(z);for(let $ of k)a($);return}if(g==="loop"){let b=m(o);for(let M of b)a(M);for(let M=1;M<o.length;M++)w(o[M],o,M);for(let M of b)a(M);return}if(g==="block"){for(let b=1;b<o.length;b++)w(o[b],o,b);for(let b of m(o))a(b);return}let A=c(o);if(A!=null&&i.has(A)&&y){y[p]=["i32.const",i.get(A)];return}if((g==="i32.eq"||g==="i32.ne")&&o.length===3){let b=c(o[1]),M=l(o[2]);if((b==null||M==null)&&(b=c(o[2]),M=l(o[1])),b!=null&&M!=null&&s.get(b)?.has(M)&&y){y[p]=["i32.const",g==="i32.eq"?0:1];return}}for(let b=1;b<o.length;b++)w(o[b],o,b)};for(let o=1;o<t.length;o++)w(t[o],t,o)},Ye=new Set(["unreachable","return","br","br_table"]),mi=t=>(C(t,e=>{if(!Array.isArray(e))return;let r=e[0];if((r==="func"||r==="block"||r==="loop")&&Xe(e),r==="if")for(let i=1;i<e.length;i++)Array.isArray(e[i])&&(e[i][0]==="then"||e[i][0]==="else")&&Xe(e[i])}),t),Xe=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),Ye.has(n)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),Ye.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},_i=t=>(C(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])))}C(e,n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="local.get"||l==="local.set"||l==="local.tee"){let f=n[1];typeof f=="string"&&s.add(f)}});for(let n=r.length-1;n>=0;n--){let{idx:l,node:f}=r[n],c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;c&&!s.has(c)&&e.splice(l,1)}}),t),er=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"]),rr=[".store","memory.",".atomic."],U=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||er.has(e))return!1;for(let r of rr)if(e.includes(r))return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!U(t[r]))return!1;return!0},hi=new Set(["if","then","else","block","loop","try"]),xi=t=>typeof t=="string"&&!er.has(t)&&!hi.has(t)&&!rr.some(e=>t.includes(e)),ir=t=>{if(!Array.isArray(t)||U(t))return[];let e=t[0];if(e==="local.tee"&&t.length===3)return[["local.set",t[1],t[2]]];if(xi(e)){let r=[];for(let i=1;i<t.length;i++)r.push(...ir(t[i]));return r}return[["drop",t]]},di=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return C(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},Ai=t=>{let e=q(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=BigInt(e.value);return r<=63n||r>=0xffffffffffffffc0n}return!1},bi=(t,e)=>Array.isArray(t)&&t[0]==="local.get"&&t.length===2&&typeof t[1]=="string"&&t[1]!==e,sr=t=>t.pure&&t.singleUse||Ai(t.val)||t.copy,Xt=(t,e)=>{for(let[r,i]of t){let s=!1;C(i.val,n=>{Array.isArray(n)&&(n[0]==="local.get"||n[0]==="local.tee")&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},ae=(t,e)=>{for(let[r,i]of t){let s=!1;C(i.val,n=>{Array.isArray(n)&&n[0]==="global.get"&&n[1]===e&&(s=!0)}),s&&t.delete(r)}},nr=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(nr(t[r]))return!0;return!1},lr=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(lr(t[r]))return!0;return!1},ce=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(ce(t[r]))return!0;return!1},ue=(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&&sr(s)?Q(s.val):t}let i=e;if(_t(r)){let s=null;C(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=ue(t[s],i);n!==t[s]&&(t[s]=n),s+1<t.length&&Array.isArray(t[s])&&C(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]),Xt(i,l[1])):l[0]==="global.set"&&typeof l[1]=="string"&&(i===e&&(i=new Map(e)),ae(i,l[1])))})}return t},wi=(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 f=t[l];if(!Array.isArray(f))continue;let c=f[0];if(!(c==="param"||c==="result"||c==="local"||c==="type"||c==="export")){if((c==="local.set"||c==="local.tee")&&f.length===3&&typeof f[1]=="string"){let a=ue(f[2],n);a!==f[2]&&(f[2]=a,i=!0),C(f[2],m=>{Array.isArray(m)&&((m[0]==="local.set"||m[0]==="local.tee")&&typeof m[1]=="string"?(n.delete(m[1]),Xt(n,m[1])):m[0]==="global.set"&&typeof m[1]=="string"&&ae(n,m[1]))});let u=s(f[1]);if(Xt(n,f[1]),ce(f[2]))for(let[m,_]of n)_.readsMem&&n.delete(m);n.set(f[1],{val:f[2],pure:U(f[2]),readsMem:nr(f[2]),singleUse:u.gets<=1&&u.sets<=1&&u.tees===0,copy:bi(f[2],f[1])});continue}if(_t(c)&&n.clear(),c==="call"||c==="call_indirect"||c==="return_call"||c==="return_call_indirect")for(let[a,u]of n)lr(u.val)&&n.delete(a);if(c==="local.get"&&f.length===2&&typeof f[1]=="string"){let a=n.get(f[1]);if(a&&sr(a)){let u=Q(a.val);f.length=0,f.push(...Array.isArray(u)?u:[u]),i=!0;continue}}if(c!=="block"&&c!=="loop"&&c!=="if"){let a=Q(f);if(ue(f,n),nt(a,f)||(i=!0),C(f,u=>{Array.isArray(u)&&((u[0]==="local.set"||u[0]==="local.tee")&&typeof u[1]=="string"?(n.delete(u[1]),Xt(n,u[1])):u[0]==="global.set"&&typeof u[1]=="string"&&ae(n,u[1]))}),ce(f))for(let[u,m]of n)m.readsMem&&n.delete(u)}}}return i},$i=(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 f=n[1];if(l[1]!==f||e.has(f))continue;let c=r.get(f)||{gets:0,sets:0,tees:0};if(c.sets!==1||c.gets!==1||c.tees!==0)continue;let a=Q(n[2]);t.splice(s,2,...Array.isArray(a)?[a]:[a]),i=!0,s--}return i},vi=(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 f=n[1];if(l[1]!==f||e.has(f))continue;let c=r.get(f)||{gets:0,sets:0,tees:0};c.sets+c.gets+c.tees<=2||(t.splice(s,2,["local.tee",f,Q(n[2])]),i=!0)}return i},Ii=(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 f=typeof l[1]=="string"?l[1]:null;if(!f||e.has(f))continue;let c=s(f);l[0]==="local.set"&&c.gets===0&&c.tees===0?l.length===3?U(l[2])&&(t.splice(n,1),i=!0):l.length===2&&(t[n]=["drop"],i=!0):l[0]==="local"&&f[0]==="$"&&c.gets===0&&c.sets===0&&c.tees===0&&(t.splice(n,1),i=!0)}return i},ki=(t,e)=>{let r=!1;for(let i=1;i<t.length-1;i++){let s=t[i],n=t[i+1];if(!Array.isArray(s)||s[0]!=="local.set"||s.length!==3||!Array.isArray(n)||n[0]!=="local.set"&&n[0]!=="local.tee"||n.length!==3||n[1]!==s[1]||e.has(s[1])||!U(s[2]))continue;let l=!1;C(n[2],f=>{Array.isArray(f)&&(f[0]==="local.get"||f[0]==="local.tee")&&f[1]===s[1]&&(l=!0)}),!l&&(t.splice(i,1),r=!0,i--)}return r},he=t=>Array.isArray(t)&&(t[0]==="func"||t[0]==="block"||t[0]==="loop"||t[0]==="then"||t[0]==="else"),_t=t=>t==="block"||t==="loop"||t==="if",ye=t=>(C(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=[];H(e,s=>{he(s)&&i.push(s)});for(let s=0;s<Kr;s++){let n=di(e),l=!1;for(let f of i)wi(f,r,n)&&(l=!0),$i(f,r,n)&&(l=!0),vi(f,r,n)&&(l=!0),Ii(f,r,n)&&(l=!0),ki(f,r)&&(l=!0);if(!l)break}}),t),fr=0,Si=new Set(["export","type","param","result","local"]),$t=t=>{let e=2;for(;e<t.length&&(typeof t[e]=="string"||Array.isArray(t[e])&&Si.has(t[e][0]));)e++;return e},xe=t=>t==="br"||t==="br_if"||t==="br_table",de=t=>{if(!Array.isArray(t))return!1;let e=t[0];if(e==="return_call"||e==="return_call_indirect"||e==="return_call_ref"||e==="try"||e==="try_table"||e==="delegate"||e==="rethrow")return!0;if(xe(e)){for(let r=1;r<t.length;r++)if(typeof t[r]=="number"||typeof t[r]=="string"&&/^\d+$/.test(t[r]))return!0}for(let r=1;r<t.length;r++)if(de(t[r]))return!0;return!1},Ae=(t,e)=>{if(!Array.isArray(t))return!1;if((t[0]==="call"||t[0]==="return_call")&&t[1]===e)return!0;for(let r=1;r<t.length;r++)if(Ae(t[r],e))return!0;return!1},be=t=>t==="i32"?["i32.const",0]:t==="i64"?["i64.const",0]:t==="f32"?["f32.const",0]:t==="f64"?["f64.const",0]:t==="v128"?["v128.const","i64x2","0","0"]:null,or=(t,e)=>{let r=!1,i=!1,s=0,n=l=>{if(r||!Array.isArray(l))return;let f=l[0],c=f==="local.set"||f==="local.tee";if((c||f==="local.get")&&l[1]===e){if(c)for(let u=2;u<l.length&&!r;u++)n(l[u]);if(r)return;r=!0,(f==="local.get"||s>0)&&(i=!0);return}let a=f==="if";for(let u=1;u<l.length&&!r;u++){let m=l[u],_=a&&Array.isArray(m)&&(m[0]==="then"||m[0]==="else");_&&s++,n(m),_&&s--}};for(let l of t){if(r)break;n(l)}return r?i:!1},we=(t,e)=>{if(!Array.isArray(t))return;let r=t[0];if(r==="export"&&Array.isArray(t[2])&&t[2][0]==="func"&&typeof t[2][1]=="string")e.add(t[2][1]);else if(r==="start"&&typeof t[1]=="string")e.add(t[1]);else if(r==="ref.func"&&typeof t[1]=="string")e.add(t[1]);else if(r==="elem")for(let i of t)typeof i=="string"&&i[0]==="$"&&e.add(i);for(let i of t)we(i,e)},Mi=t=>{let e=new Set;for(let r of t)(!Array.isArray(r)||r[0]!=="func")&&we(r,e);return e},Bi=t=>{let e=[],r=[],i=null,s=!0,n=0;for(let l=2;l<t.length;l++){let f=t[l];if(typeof f!="string"){if(!Array.isArray(f)){s=!1;break}if(f[0]==="param"){if(typeof f[1]!="string"||f[1][0]!=="$"){s=!1;break}e.push({name:f[1],type:f[2]})}else if(f[0]==="local"){if(typeof f[1]!="string"||f[1][0]!=="$"||!be(f[2])){s=!1;break}r.push({name:f[1],type:f[2]})}else if(f[0]==="result")n+=f.length-1,f.length>1&&(i=f[1]);else if(f[0]==="export"){s=!1;break}else{if(f[0]==="type")continue;break}}}return n>1&&(s=!1),s?{params:e,locals:r,inlResult:i}:null},Ni=t=>{let e=0,r=i=>{if(Array.isArray(i)){e++;for(let s=1;s<i.length;s++)r(i[s])}};for(let i=$t(t);i<t.length;i++)r(t[i]);return e},zi=(t,e,r,i,s)=>{let n=++fr,l=`$__inl${n}`,f=new Map;for(let h of t)f.set(h.name,`$__inl${n}_${h.name.slice(1)}`);for(let h of e)f.set(h.name,`$__inl${n}_${h.name.slice(1)}`);let c=new Map,a=h=>{if(Array.isArray(h)){_t(h[0])&&typeof h[1]=="string"&&h[1][0]==="$"&&!c.has(h[1])&&c.set(h[1],`$__inl${n}L_${h[1].slice(1)}`);for(let w=1;w<h.length;w++)a(h[w])}};for(let h of i)a(h);let u=h=>{if(!Array.isArray(h))return h;let w=h[0];return(w==="local.get"||w==="local.set"||w==="local.tee")&&typeof h[1]=="string"&&f.has(h[1])?[w,f.get(h[1]),...h.slice(2).map(u)]:w==="return"?["br",l,...h.slice(1).map(u)]:_t(w)&&typeof h[1]=="string"&&c.has(h[1])?[w,c.get(h[1]),...h.slice(2).map(u)]:xe(w)?[w,...h.slice(1).map(o=>typeof o=="string"&&c.has(o)?c.get(o):u(o))]:h.map((o,y)=>y===0?o:u(o))},m=t.map((h,w)=>["local.set",f.get(h.name),s[w]]),_=e.filter(h=>or(i,h.name)).map(h=>["local.set",f.get(h.name),be(h.type)]),x=i.map(u),S=r?["block",l,["result",r],...m,..._,...x]:["block",l,...m,..._,...x],d=[...t,...e].map(h=>["local",f.get(h.name),h.type]);return{block:S,decls:d}},Ti=90,Ei=(t,e)=>e==="v128"&&t.length>0&&t.every(r=>r.type==="v128"),ar=(t,{simdOnly:e=!1,pin:r=_e}={})=>{if(!Array.isArray(t)||t[0]!=="module")return t;let i=new Set;for(let s=0;s<Qe;s++){let n=t.filter(p=>Array.isArray(p)&&p[0]==="func"),l=new Map;for(let p of n)typeof p[1]=="string"&&l.set(p[1],p);let f=new Map,c=new Set,a=p=>{if(!Array.isArray(p))return;let g=p[0];g==="call"&&typeof p[1]=="string"?f.set(p[1],(f.get(p[1])||0)+1):g==="return_call"&&typeof p[1]=="string"&&c.add(p[1]);for(let A=1;A<p.length;A++)a(p[A])};a(t);let u=new Set;for(let p of t)(!Array.isArray(p)||p[0]!=="func")&&we(p,u);let m=null,_=null;for(let[p,g]of l){if(i.has(p)||u.has(p)||c.has(p)||r.has(p)||!(f.get(p)>=1)||Ni(g)>Ti||Ae(g,p))continue;let A=Bi(g);if(!A||e&&!Ei(A.params,A.inlResult))continue;let b=!1;for(let M=$t(g);M<g.length;M++)if(de(g[M])){b=!0;break}if(!b){m=p,_=A;break}}if(!m)break;let x=l.get(m),{params:S,locals:d,inlResult:h}=_,w=x.slice($t(x)),o=f.get(m)||0,y=0;for(let p of n){if(p===x)continue;let g=[];for(let A=$t(p);A<p.length;A++)p[A]=H(p[A],b=>{if(!Array.isArray(b)||b[0]!=="call"||b[1]!==m)return;let M=b.slice(2);if(M.length!==S.length)return;let{block:N,decls:v}=zi(S,d,h,w,M);return g.push(...v),y++,N});g.length&&p.splice($t(p),0,...g)}if(y===o){let p=t.indexOf(x);p>=0&&t.splice(p,1)}else i.add(m)}return t},cr=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=[],n=!1;if(C(t,o=>{Array.isArray(o)&&typeof o[0]=="string"&&(o[0]==="table.set"||o[0]==="table.grow"||o[0]==="table.init"||o[0]==="table.copy"||o[0]==="table.fill")&&(n=!0)}),n)return t;for(let o of t.slice(1))if(Array.isArray(o))if(o[0]==="elem"){let y=o[1];if(!Array.isArray(y)||y[0]!=="i32.const")return t;let p=Number(y[1]);for(let g=2;g<o.length;g++)typeof o[g]=="string"&&o[g][0]==="$"&&e.set(p++,o[g])}else o[0]==="type"&&typeof o[1]=="string"?r.set(o[1],o[2]):o[0]==="func"&&(s.push(o),typeof o[1]=="string"&&i.set(o[1],o));if(!e.size)return t;let l=new Map,f=(o,y)=>Array.isArray(o)&&o[0]==="i64.const"&&gt(o[1])===y,c="0x0000000000007fff",a="0x0000000000000020",u=(o,y)=>Array.isArray(o)?o[0]==="i64.const"?(y.push(o),!0):o[0]==="f64.const"&&typeof o[1]=="string"&&o[1].startsWith("nan:")?(y.push(["i64.const",gt(o[1].slice(4))]),!0):o[0]==="f64.reinterpret_i64"&&o.length===2?u(o[1],y):o[0]==="select"&&o.length===4?u(o[1],y)&&u(o[2],y):!1:!1,m=new Map;C(t,o=>{!Array.isArray(o)||o[0]!=="global.set"||typeof o[1]!="string"||(m.has(o[1])||m.set(o[1],[]),m.get(o[1]).push(o[2]))});let _=(o,y,p)=>{if(!Array.isArray(o))return!1;if(o[0]==="i64.const")return y.push(o),!0;if(o[0]==="f64.const"&&typeof o[1]=="string"&&o[1].startsWith("nan:"))return y.push(["i64.const",gt(o[1].slice(4))]),!0;if((o[0]==="f64.reinterpret_i64"||o[0]==="i64.reinterpret_f64")&&o.length===2)return _(o[1],y,p);if(o[0]==="global.get"&&typeof o[1]=="string")return p.push(o[1]),!0;if(o[0]==="local.get"||o[0]==="local.tee")return o[0]==="local.tee"&&o.length===3?_(o[2],y,p):!1;if(o[0]==="select"&&o.length===4)return _(o[1],y,p)&&_(o[2],y,p);if(o[0]==="if"){let g=!0,A=!1;for(let b=1;b<o.length;b++){let M=o[b];Array.isArray(M)&&(M[0]==="then"||M[0]==="else")&&(A=!0,(M.length!==2||!_(M[1],y,p))&&(g=!1))}return g&&A}return!1},x=new Map;for(let[o,y]of m){let p=[],g=[],A=!0;for(let b of y)if(!_(b,p,g)){A=!1;break}x.set(o,A?{consts:p,reads:g}:null)}let S=!0,d=new Map;for(;S;){S=!1;for(let[o,y]of x){if(d.get(o)===null)continue;if(y===null){d.get(o)!==null&&(d.set(o,null),S=!0);continue}let p=d.get(o)||new Map,g=p.size,A=!1;for(let b of y.consts)p.set(gt(b[1]),b);for(let b of y.reads){if(x.get(b)===null||d.get(b)===null){A=!0;break}let M=d.get(b);if(M)for(let[N,v]of M)p.set(N,v)}if(A){d.set(o,null),S=!0;continue}(!d.has(o)||p.size!==g)&&(d.set(o,p),S=!0)}}for(let[o,y]of d)l.set(o,y);let h=o=>{if(!Array.isArray(o)||o[0]!=="i32.wrap_i64")return null;let y=o[1];if(!Array.isArray(y)||y[0]!=="i64.and")return null;let p=y[1],g=y[2];if(f(g,c)||(p=y[2],g=y[1]),!f(g,c)||!Array.isArray(p)||p[0]!=="i64.shr_u"||!f(p[2],a))return null;let A=p[1];if(!Array.isArray(A)||A[0]!=="i64.reinterpret_f64")return null;let b=A[1];return Array.isArray(b)&&b[0]==="local.get"&&typeof b[1]=="string"?{local:b[1]}:Array.isArray(b)&&b[0]==="global.get"&&typeof b[1]=="string"?{global:b[1]}:null},w=o=>{let y=[],p=[];for(let g of o)if(Array.isArray(g))if(g[0]==="param")for(let A of g.slice(1))typeof A=="string"&&A[0]!=="$"&&y.push(A);else g[0]==="result"&&p.push(...g.slice(1));return y.join(",")+"->"+p.join(",")};for(let o of s){let y=new Map;for(let p of o)Array.isArray(p)&&p[0]==="param"&&typeof p[1]=="string"&&y.set(p[1],null);C(o,p=>{if(!Array.isArray(p)||p[0]!=="local.set"&&p[0]!=="local.tee"||typeof p[1]!="string"||y.get(p[1])===null)return;let g=[];if(u(p[2],g)){let A=y.get(p[1])||new Map;for(let b of g)A.set(gt(b[1]),b);y.set(p[1],A)}else if(Array.isArray(p[2])&&p[2][0]==="global.get"&&typeof p[2][1]=="string"&&l.get(p[2][1])){let A=l.get(p[2][1]),b=y.get(p[1])||new Map;for(let[M,N]of A)b.set(M,N);y.set(p[1],b)}else y.set(p[1],null)}),H(o,(p,g)=>{if(!Array.isArray(p)||p[0]!=="call_indirect"||g&&g[0]==="else")return;let A=Array.isArray(p[1])&&p[1][0]==="type"?p[1]:null;if(!A)return;let b=r.get(A[1]),M=Array.isArray(b)?w(b.slice(1)):null;if(M==null)return;let N=[];for(let O of b.slice(1))Array.isArray(O)&&O[0]==="result"&&N.push(...O.slice(1));let v=p.slice(2,-1),k=p[p.length-1],z=O=>{let L=i.get(O);if(!L)return!1;let ct=L.find(kt=>Array.isArray(kt)&&kt[0]==="type");return ct?ct[1]===A[1]||r.get(ct[1])&&w(r.get(ct[1]).slice(1))===M:w(L.slice(2))===M};if(Array.isArray(k)&&k[0]==="i32.const"){let O=e.get(Number(k[1]));return O&&z(O)?["call",O,...v]:void 0}let $=h(k);if(!$)return;let T=$.local!=null?y.get($.local):l.get($.global);if(!T||T.size===0||T.size>4)return;let F=[];for(let O of T.values()){let L=e.get(at(gt(O[1]))&32767);if(!L||!z(L))return;F.push([O,L])}let st=$.local!=null?["local.get",$.local]:["global.get",$.global],W=p;for(let O=F.length-1;O>=0;O--){let[L,ct]=F[O];W=["if",...N.length?[["result",...N]]:[],["i64.eq",["i64.reinterpret_f64",Q(st)],Q(L)],["then",["call",ct,...v.map(Q)]],["else",W]]}return W})}return t},qi=(t,{pin:e=_e}={})=>{if(!Array.isArray(t)||t[0]!=="module")return t;let r=$t,i=Ae,s=de,n=xe,l=be,f=or;for(let c=0;c<Qe;c++){let a=t.filter($=>Array.isArray($)&&$[0]==="func"),u=new Map;for(let $ of a)typeof $[1]=="string"&&u.set($[1],$);let m=new Map,_=new Set,x=$=>{if(!Array.isArray($))return;let T=$[0];T==="call"&&typeof $[1]=="string"?m.set($[1],(m.get($[1])||0)+1):T==="return_call"&&typeof $[1]=="string"&&_.add($[1]);for(let F=1;F<$.length;F++)x($[F])};x(t);let S=Mi(t),d=null;for(let[$,T]of u){if(S.has($)||_.has($)||m.get($)!==1||e.has($)||i(T,$))continue;let F=!0,st=0;for(let O=2;O<T.length;O++){let L=T[O];if(typeof L!="string"){if(!Array.isArray(L)){F=!1;break}if(L[0]==="param"||L[0]==="local"){if(typeof L[1]!="string"||L[1][0]!=="$"){F=!1;break}if(L[0]==="local"&&!l(L[2])){F=!1;break}}else if(L[0]==="result")st+=L.length-1;else if(L[0]==="export"){F=!1;break}else{if(L[0]==="type")continue;break}}}if(!F||st>1)continue;let W=!1;for(let O=r(T);O<T.length;O++)if(s(T[O])){W=!0;break}if(!W){d=$;break}}if(!d)break;let h=u.get(d),w=[],o=[],y=null;for(let $=2;$<h.length;$++){let T=h[$];if(!(typeof T=="string"||!Array.isArray(T)))if(T[0]==="param")w.push({name:T[1],type:T[2]});else if(T[0]==="result")T.length>1&&(y=T[1]);else if(T[0]==="local")o.push({name:T[1],type:T[2]});else{if(T[0]==="export"||T[0]==="type")continue;break}}let p=h.slice(r(h)),g=++fr,A=`$__inl${g}`,b=new Map;for(let $ of w)b.set($.name,`$__inl${g}_${$.name.slice(1)}`);for(let $ of o)b.set($.name,`$__inl${g}_${$.name.slice(1)}`);let M=new Map,N=$=>{if(Array.isArray($)){_t($[0])&&typeof $[1]=="string"&&$[1][0]==="$"&&!M.has($[1])&&M.set($[1],`$__inl${g}L_${$[1].slice(1)}`);for(let T=1;T<$.length;T++)N($[T])}};for(let $ of p)N($);let v=$=>{if(!Array.isArray($))return $;let T=$[0];return(T==="local.get"||T==="local.set"||T==="local.tee")&&typeof $[1]=="string"&&b.has($[1])?[T,b.get($[1]),...$.slice(2).map(v)]:T==="return"?["br",A,...$.slice(1).map(v)]:_t(T)&&typeof $[1]=="string"&&M.has($[1])?[T,M.get($[1]),...$.slice(2).map(v)]:n(T)?[T,...$.slice(1).map(F=>typeof F=="string"&&M.has(F)?M.get(F):v(F))]:$.map((F,st)=>st===0?F:v(F))},k=!1;for(let $ of a){if($===h||k)continue;let T=r($);for(let F=T;F<$.length;F++){let st=H($[F],W=>{if(k||!Array.isArray(W)||W[0]!=="call"||W[1]!==d)return;let O=W.slice(2);if(O.length!==w.length)return;let L=w.map((ht,dr)=>["local.set",b.get(ht.name),O[dr]]),ct=o.filter(ht=>f(p,ht.name)).map(ht=>["local.set",b.get(ht.name),l(ht.type)]),kt=p.map(v);return k=!0,y?["block",A,["result",y],...L,...ct,...kt]:["block",A,...L,...ct,...kt]});if(st!==$[F]&&($[F]=st),k){let W=[...w,...o].map(O=>["local",b.get(O.name),O.type]);W.length&&$.splice(r($),0,...W);break}}if(k)break}if(!k)break;let z=t.indexOf(h);z>=0&&t.splice(z,1)}return t},Zt=(t,e)=>{let r=!1,i=(s,n)=>{if(r||!Array.isArray(s))return;let l=s[0],f=n;if((l==="block"||l==="loop")&&typeof s[1]=="string"&&s[1]===e&&(f=!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 c=1;c<s.length&&typeof s[c]=="string";c++)if(s[c]===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 c=1;c<s.length;c++)i(s[c],f)};for(let s of t)i(s,!1);return r},ur=t=>(H(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 f=e[r];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="type")){r++;continue}if(Array.isArray(f)&&f[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&&Zt(n,i))){e.length=0;for(let f of l)e.push(f)}}),C(t,e=>{if(!he(e))return;let r=1;for(;r<e.length;){let i=e[r];if(!Array.isArray(i)){r++;continue}{let f=i[0],c=f==="local.set"||f==="global.set"?2:f==="drop"?1:-1;if(c>=0&&i.length===c+1){let a=i[c];if(Array.isArray(a)&&a[0]==="block"){let u=1,m=null;typeof a[1]=="string"&&a[1][0]==="$"&&(m=a[1],u=2);let _=!1;for(;u<a.length;){let S=a[u];if(Array.isArray(S)&&(S[0]==="param"||S[0]==="type")){u++;continue}if(Array.isArray(S)&&S[0]==="result"){_=!0,u++;continue}break}let x=_?a.slice(u):null;if(x&&x.length>=2&&!(m&&Zt(x,m))){let S=x[x.length-1],d=x.slice(0,-1);i[c]=S,e.splice(r,1,...d,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 f=i[s];if(Array.isArray(f)&&(f[0]==="param"||f[0]==="result"||f[0]==="type")){s++;continue}break}let l=i.slice(s);if(n&&Zt(l,n)){r++;continue}e.splice(r,1,...l),r+=l.length}}),t),yr=t=>(C(t,e=>{if(!Array.isArray(e)||e[0]!=="func")return;let r=new Map;for(let _ of e)Array.isArray(_)&&_[0]==="local"&&typeof _[1]=="string"&&_[1][0]==="$"&&typeof _[2]=="string"&&r.set(_[1],_[2]);if(r.size<2)return;let i=new Map,s=[],n=0,l=!1,f=0,c=_=>{if(l||!Array.isArray(_))return;let x=_[0],S=x==="loop";S&&s.push({start:n,end:n});let d=x==="local.set"||x==="local.tee";if(d||x==="local.get"){let h=_[1];if(typeof h!="string"||h[0]!=="$"){l=!0;return}if(d)for(let o=2;o<_.length;o++)c(_[o]);let w=n++;if(r.has(h)){let o=i.get(h);o||(o={start:w,end:w,firstOp:x,firstCond:f>0,loops:new Set},i.set(h,o)),w>o.end&&(o.end=w);for(let y of s)o.loops.add(y)}}else{n++;let h=x==="if";for(let w=1;w<_.length;w++){let o=_[w],y=h&&Array.isArray(o)&&(o[0]==="then"||o[0]==="else");y&&f++,c(o),y&&f--}}if(S){let h=s.pop();h.end=n}};if(c(e),l)return;for(let _ of i.values())for(let x of _.loops)x.start<_.start&&(_.start=x.start),x.end>_.end&&(_.end=x.end);let a=[...i.entries()].sort((_,x)=>_[1].start-x[1].start),u=new Map,m=[];for(let[_,x]of a){let S=x.firstOp==="local.get"||x.firstCond,d=r.get(_),h=S?null:m.find(w=>w.type===d&&w.end<x.start);h?(u.set(_,h.primary),x.end>h.end&&(h.end=x.end)):m.push({primary:_,type:d,end:x.end})}u.size!==0&&C(e,_=>{Array.isArray(_)&&(_[0]==="local.get"||_[0]==="local.set"||_[0]==="local.tee")&&u.has(_[1])&&(_[1]=u.get(_[1]))})}),t),pr=t=>H(t,e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="nop")return["nop"];if(r==="drop"&&e.length===2){let i=ir(e[1]);return i.length===0?["nop"]:i.length===1?i[0]:["block",...i]}if(r==="select"&&e.length>=4&&nt(e[1],e[2])&&U(e[3]))return e[1];if(r==="if"){let{cond:i,thenBranch:s,elseBranch:n}=vt(e),l=!s||s.length<=1,f=!n||n.length<=1;if(l&&f)return U(i)?["nop"]:["drop",i];if(n&&f&&!l)return e.filter(c=>c!==n)}if(he(e)){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],f=l==="drop"||Array.isArray(l)&&l[0]==="drop"&&l.length===1;if(Array.isArray(n)&&f&&U(n)){s++;continue}if(Array.isArray(n)&&f&&n[0]==="local.tee"&&n.length===3){i.push(["local.set",n[1],n[2]]),s++;continue}i.push(n)}if(i.length!==e.length)return i}}),D=t=>(e,r)=>nt(e,r)&&U(e)?t:null,Oi={"i32.sub":D(["i32.const",0]),"i64.sub":D(["i64.const",0]),"i32.xor":D(["i32.const",0]),"i64.xor":D(["i64.const",0]),"i32.eq":D(["i32.const",1]),"i64.eq":D(["i32.const",1]),"i32.ne":D(["i32.const",0]),"i64.ne":D(["i32.const",0]),"i32.lt_s":D(["i32.const",0]),"i32.lt_u":D(["i32.const",0]),"i32.gt_s":D(["i32.const",0]),"i32.gt_u":D(["i32.const",0]),"i32.le_s":D(["i32.const",1]),"i32.le_u":D(["i32.const",1]),"i32.ge_s":D(["i32.const",1]),"i32.ge_u":D(["i32.const",1]),"i64.lt_s":D(["i32.const",0]),"i64.lt_u":D(["i32.const",0]),"i64.gt_s":D(["i32.const",0]),"i64.gt_u":D(["i32.const",0]),"i64.le_s":D(["i32.const",1]),"i64.le_u":D(["i32.const",1]),"i64.ge_s":D(["i32.const",1]),"i64.ge_u":D(["i32.const",1]),"i32.mul":(t,e)=>q(e)?.value===0&&U(t)?["i32.const",0]:q(t)?.value===0&&U(e)?["i32.const",0]:null,"i64.mul":(t,e)=>q(e)?.value===G&&U(t)?["i64.const",0]:q(t)?.value===G&&U(e)?["i64.const",0]:null,"i32.and":(t,e)=>nt(t,e)&&U(e)?t:q(e)?.value===0&&U(t)?["i32.const",0]:q(t)?.value===0&&U(e)?["i32.const",0]:null,"i64.and":(t,e)=>nt(t,e)&&U(e)?t:q(e)?.value===G&&U(t)?["i64.const",0]:q(t)?.value===G&&U(e)?["i64.const",0]:null,"i32.or":(t,e)=>nt(t,e)&&U(e)?t:q(e)?.value===-1&&U(t)?["i32.const",-1]:q(t)?.value===-1&&U(e)?["i32.const",-1]:null,"i64.or":(t,e)=>nt(t,e)&&U(e)?t:q(e)?.value===Kt&&U(t)?["i64.const",-1]:q(t)?.value===Kt&&U(e)?["i64.const",-1]:null,"local.set":(t,e)=>Array.isArray(e)&&e[0]==="local.get"&&e[1]===t?["nop"]:null},Fi=t=>H(t,e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Oi[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Ci=t=>{let e=typeof t=="bigint"?t:BigInt(typeof t=="string"?t.replaceAll("_",""):Math.trunc(Number(t)||0));e>0x7fffffffffffffffn&&(e=e-0x8000000000000000n-0x8000000000000000n);let r=1;for(;;){let i=e&0x7fn;if(e>>=7n,e===0n&&(i&0x40n)===0n||e===-1n&&(i&0x40n)!==0n)return r;r++}},Ri=t=>{if(!Array.isArray(t))return 4;switch(t[0]){case"i32.const":case"i64.const":return 1+Ci(t[1]);case"f32.const":return 5;case"f64.const":return 9;case"v128.const":return 18;default:return 4}},Li=2,Ui=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(a=>Array.isArray(a)&&a[0]==="export")&&r.add(l);let f=n[2];if(Array.isArray(f)&&f[0]==="mut"||Array.isArray(f)&&f[0]==="import")continue;let c=n[3];q(c)&&e.set(l,c)}if(e.size===0)return t;let i=new Map;C(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 f=i.get(n)||0;if(f===0)continue;let c=Ri(l),a=c+2,u=f*Li+a;f*c+(r.has(n)?a:0)<=u&&s.add(n)}if(s.size===0)return t;H(t,n=>{if(!(!Array.isArray(n)||n[0]!=="global.get"||n.length!==2)&&s.has(n[1]))return Q(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},Di=t=>H(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 f=i?e.length-2:e.length-1,c=i?e.length-1:-1;if(f<l)return;let a=e[f];if(!Array.isArray(a)||a[0]!=="i32.add"||a.length!==3)return;let u=a[1],m=a[2],_=q(u),x=q(m),S=null,d=null;if(_&&_.type==="i32"?(d=_.value,S=m):x&&x.type==="i32"&&(d=x.value,S=u),S===null||d===null)return;let h=s+d,w=[r];n!==null&&w.push(n),w.push(`offset=${h}`);let o=null;for(let y=l;y<f;y++)typeof e[y]=="string"&&e[y].startsWith("align=")&&(o=e[y]);return o&&w.push(o),w.push(S),i&&w.push(e[c]),w}),Pi=t=>(C(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 f=e.length-1;f>=i;f--){let c=e[f];if(!Array.isArray(c)){c!=="nop"&&c!=="end"&&(n=f);continue}let a=c[0];if(!(a==="param"||a==="result"||a==="local"||a==="type"||a==="export")){n=f;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),Wi=t=>(C(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 S=e[r];if(Array.isArray(S)&&S[0]==="type"){r++;continue}if(Array.isArray(S)&&(S[0]==="param"||S[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 f=[];for(;n<s.length;){let S=s[n];if(Array.isArray(S)&&S[0]==="type"){f.push(S),n++;continue}if(Array.isArray(S)&&(S[0]==="param"||S[0]==="result"))return;break}let c=s.slice(n);if(c.length<2)return;let a=c[0],u=c[c.length-1];if(!Array.isArray(a)||a[0]!=="br_if"||a[1]!==i||a.length!==3||!Array.isArray(u)||u[0]!=="br"||u[1]!==l||u.length!==2)return;let m=c.slice(1,-1);if(Zt(m,i))return;let _=a[2];Array.isArray(_)&&_[0]==="i32.eqz"&&_.length===2?_=_[1]:_=["i32.eqz",_];let x=["loop"];l&&x.push(l);for(let S of f)x.push(S);x.push(["if",_,["then",...m,u]]),e.length=0;for(let S of x)e.push(S)}),t),ji=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Set;return C(t,r=>{Array.isArray(r)&&r[0]==="global.set"&&typeof r[1]=="string"&&e.add(r[1])}),H(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}})},Gi=t=>H(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{cond:r,thenBranch:i,elseBranch:s}=vt(e),n=!i||i.length<=1,l=!s||s.length<=1;if(!n&&l&&i.length===2){let f=i[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],r]}if(n&&!l&&s.length===2){let f=s[1];if(Array.isArray(f)&&f[0]==="br"&&f.length===2)return["br_if",f[1],["i32.eqz",r]]}}),Hi=t=>H(t,e=>{if(!Array.isArray(e)||e[0]!=="if")return;let{thenBranch:r,elseBranch:i}=vt(e);if(!r||!i||r.length<=1||i.length<=1||!e.some(_=>Array.isArray(_)&&_[0]==="result"))return;let n=0,l=Math.min(r.length,i.length);for(let _=1;_<l&&nt(r[r.length-_],i[i.length-_]);_++)n++;if(n===0)return;let f=r.slice(r.length-n),c=r.slice(0,r.length-n),a=i.slice(0,i.length-n),u=["block"];for(let _=1;_<e.length;_++){let x=e[_];if(Array.isArray(x)&&(x[0]==="then"||x[0]==="else"))break;Array.isArray(x)&&(x[0]==="result"||x[0]==="type")&&u.push(x)}let m=["if"];for(let _=1;_<e.length;_++){let x=e[_];if(Array.isArray(x)&&(x[0]==="then"||x[0]==="else"))break;Array.isArray(x)&&(x[0]==="result"||x[0]==="type")||m.push(x)}return m.push(c.length>1?c:["then"]),m.push(a.length>1?a:["else"]),u.push(m,...f),u}),gr=(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(",")},Vi=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]),C(i,f=>{if(!Array.isArray(f)||typeof f[1]!="string"||f[1][0]!=="$")return;let c=f[0];(c==="param"||c==="local"||_t(c))&&n.add(f[1])});let l=gr(i,n);e.has(l)?r.set(s,e.get(l)):e.set(l,s)}return r.size===0||H(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},Yi=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=gr(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 H(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 f=1;f<l.length;f++){let c=l[f];Array.isArray(c)&&c[0]==="type"&&typeof c[1]=="string"&&r.has(c[1])&&(l[f]=["type",r.get(c[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[];let e=[],r=s=>s>=48&&s<=57?s-48:s>=97&&s<=102?s-87:s>=65&&s<=70?s-55:-1,i=t.length-1;for(let s=1;s<i;s++){let n=t.charCodeAt(s);if(n!==92){e.push(n);continue}let l=t.charCodeAt(++s);if(l===120||l===88)e.push(r(t.charCodeAt(s+1))<<4|r(t.charCodeAt(s+2))),s+=2;else{let f=r(l),c=s+1<i?r(t.charCodeAt(s+1)):-1;f>=0&&c>=0?(e.push(f<<4|c),s++):l===110?e.push(10):l===116?e.push(9):l===114?e.push(13):e.push(l)}}return e},mr=(t,e)=>{let r='"';for(let i=0;i<e;i++){let s=t[i];s>=32&&s<127&&s!==34&&s!==92?r+=String.fromCharCode(s):r+="\\"+s.toString(16).padStart(2,"0")}return r+'"'},Xi=t=>{let e=[];for(let i of t)if(typeof i=="string"){let s=Qt(i);for(let n=0;n<s.length;n++)e.push(s[n])}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?[]:[mr(e,r)]},Zi=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},Ze=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},Ki=(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]),f=Qt(n[0]);for(let c=0;c<f.length;c++)l.push(f[c]);return t.length=r,t.push(mr(l,l.length)),!0}return t.length=r,t.push(...s,...n),!0},Qi=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=Xi(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=Zi(s);if(n){let l=Ze(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&&Ki(s.node,n.node)&&(r.add(n.index),s.len=Ze(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)}},Ji=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},ts=t=>{let e=!0;return C(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},es=t=>{if(!Array.isArray(t)||t[0]!=="module"||!ts(t))return t;let e=new Map;C(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]},Tt=[["stripmut",ji,!0,"strip mut from never-written globals"],["globals",Ui,!0,"propagate immutable global constants"],["guardRefine",pi,!1,"fold NaN-box tag reads under dominating tag guards (jz NaN-box-specific; opt-in)"],["fold",oi,!0,"constant folding"],["identity",ci,!0,"remove identity ops (x + 0 \u2192 x)"],["peephole",Fi,!0,"x-x\u21920, x&0\u21920, etc."],["strength",ui,!0,"strength reduction (x * 2 \u2192 x << 1)"],["branch",yi,!0,"simplify constant branches"],["propagate",ye,!0,"forward-propagate single-use locals & tiny consts (never inflates)"],["devirt",cr,!1,"call_indirect with a constant or known closure-const index \u2192 direct/guarded calls \u2014 grows bytes for speed"],["inlineOnce",qi,!0,"inline single-call functions into their lone caller (never duplicates)"],["inline",ar,!1,"inline tiny functions \u2014 can duplicate bodies"],["offset",Di,!0,"fold add+const into load/store offset"],["unbranch",Pi,!0,"remove redundant br at end of own block"],["loopify",Wi,!0,"collapse block+loop+brif while-idiom into loop+if"],["brif",Gi,!0,"if-then-br \u2192 br_if"],["foldarms",Hi,!1,"merge identical trailing if arms \u2014 can add block wrapper"],["deadcode",mi,!0,"eliminate dead code after unreachable/br/return"],["vacuum",pr,!0,"remove nops, drop-of-pure, empty branches"],["mergeBlocks",ur,!0,"unwrap `(block $L \u2026)` whose label is never targeted"],["coalesce",yr,!0,"share local slots between same-type non-overlapping locals"],["locals",_i,!0,"remove unused locals"],["dedupe",Vi,!0,"eliminate duplicate functions"],["dedupTypes",Yi,!0,"merge identical type definitions"],["packData",Qi,!0,"trim trailing zeros, merge adjacent data segments"],["reorder",es,!1,"put hot functions first \u2014 no AST reduction"],["treeshake",Qr,!0,"remove unused funcs/globals/types/tables"],["minifyImports",Ji,!1,"shorten import names \u2014 enable only when you control the host"]],Ns=Object.fromEntries(Tt.map(t=>[t[0],t[2]])),rs=t=>{if(t===!1)return{};if(t!==!0&&typeof t!="string"){let i={...t};for(let s of Tt)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 Tt)r[i[0]]=e?e.has("all")||e.has(i[0]):i[2];return r},is=t=>{if(!Array.isArray(t))return!1;let e=new Map,r=new Set,i=new Set,s=n=>{if(!Array.isArray(n))return;let l=n[0];if(l==="call"&&typeof n[1]=="string")e.set(n[1],(e.get(n[1])||0)+1);else if(l==="return_call"&&typeof n[1]=="string")i.add(n[1]);else if(l==="ref.func"&&typeof n[1]=="string")r.add(n[1]);else if(l==="export"&&Array.isArray(n[2])&&n[2][0]==="func"&&typeof n[2][1]=="string")r.add(n[2][1]);else if(l==="start"&&typeof n[1]=="string")r.add(n[1]);else if(l==="elem")for(let f of n)typeof f=="string"&&f[0]==="$"&&r.add(f);for(let f=1;f<n.length;f++)s(n[f])};s(t);for(let n of t){if(!Array.isArray(n)||n[0]!=="func"||typeof n[1]!="string")continue;let l=n[1];if(!(e.get(l)!==1||r.has(l)||i.has(l))&&!n.some(f=>Array.isArray(f)&&f[0]==="export"))return!0}return!1},ss=new Set(["export","type","param","result","local"]);function ns(t){if(!Array.isArray(t)||t[0]!=="module")return t;let e=t.find(i=>Array.isArray(i)&&i[0]==="func"&&i[1]==="$__start");if(!e)return t;let r=2;for(;r<e.length&&Array.isArray(e[r])&&ss.has(e[r][0]);)r++;return r<e.length?t:t.filter(i=>!(Array.isArray(i)&&(i[0]==="func"&&i[1]==="$__start"||i[0]==="start"&&i[1]==="$__start")))}function $e(t,e=!0){typeof t=="string"&&(t=lt(t));let r=e===!0;e=rs(e),e.pin=e.pin instanceof Set?e.pin:new Set(e.pin||[]);let i=e.log?(a,u)=>e.log(a,u):()=>{},s=e.verbose||e.log;t=Q(t);let n=a=>(e.inline&&(a=ar(a,{simdOnly:e.inline==="simd",pin:e.pin}),e.propagate&&(a=ye(a)),e.mergeBlocks&&(a=ur(a)),e.vacuum&&(a=pr(a)),e.coalesceLocals&&(a=yr(a))),a),l=a=>(a=n(a),ns(e.devirt?cr(a):a));if(!((e.inlineOnce||e.inline)&&is(t))){for(let a=0;a<3;a++){let u=Q(t);for(let[m,_]of Tt)e[m]&&m!=="inlineOnce"&&m!=="inline"&&m!=="devirt"&&(t=_(t,e));if(nt(u,t))break;s&&i(` round ${a+1} applied`)}return l(t)}let f=null,c=je(t);for(let a=0;a<3;a++){f=Q(t);for(let[x,S]of Tt)e[x]&&x!=="devirt"&&x!=="inline"&&(t=S(t,e));if(e.propagate&&(e.inlineOnce||e.inline)&&(t=ye(t)),nt(f,t))break;let u=je(t),m=u-c;if((s||m!==0)&&i(` round ${a+1}: ${m>0?"+":""}${m} bytes`,m),m>(r?0:16)){s&&i(` \u26A0 round ${a+1} inflated by ${m} bytes, reverting`,m),t=f;break}c=u}return l(t)}var _r="\uE000",ls=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t,s=Ee(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 ve(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=ve(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function fs(t,e){let r=[],i=new Map;return ve(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 f=[];for(let u=2;u<s.length;u++){let m=ls(s[u]);m&&f.push(m)}let c=r.length,a=n.name||`$fn${c}`;i.set(n,{idx:c,name:a.startsWith("$")?a:"$"+a,params:f,fn:n}),r.push(i.get(n))}let l=i.get(n);s[1]=l.name}return s}),r}function os(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function Ie(t,e,r){let{parse:i,compile:s,optimize:n,polyfill:l}=t,f={};if(!Array.isArray(e)&&r.length&&typeof r[r.length-1]=="object"&&r[r.length-1]!==null&&!r[r.length-1].byteLength&&(f=r.pop()),Array.isArray(e)&&e.raw){let c=e[0];for(let S=0;S<r.length;S++)c+=_r+e[S+1];let a=i(c),u=[],m=0;a=ve(a,S=>{if(S===_r){let d=r[m++];if(typeof d=="function")return u.push(d),d;if(typeof d=="string"&&(d[0]==="("||/^\s*\(/.test(d))){let h=i(d);return Array.isArray(h)&&Array.isArray(h[0])&&(h._splice=!0),h}return d?.byteLength!==void 0?[...d]:typeof d=="bigint"?d.toString():d}return S});let _=null;if(u.length){let S=fs(a,u);if(S.length){let d=os(S);a[0]==="module"?a.splice(1,0,...d):typeof a[0]=="string"?a=[...d,a]:a.unshift(...d),_={env:{}};for(let h of S)_.env[h.name.slice(1)]=h.fn}}f.polyfill&&(a=l(a,f.polyfill)),f.optimize&&(a=n(a,f.optimize));let x=s(a);return _&&(x._imports=_),x}if(f.polyfill||f.optimize){let c=typeof e=="string"?i(e):e;return f.polyfill&&(c=l(c,f.polyfill)),f.optimize&&(c=n(c,f.optimize)),s(c)}return s(e)}function hr(t,e,r){let i=Ie(t,e,r),s=new WebAssembly.Module(i);return new WebAssembly.Instance(s,i._imports).exports}var xr={parse:lt,compile:bt,optimize:$e,polyfill:fe};function Us(t,...e){return Ie(xr,t,e)}function as(t,...e){return hr(xr,t,e)}var Ds=as;export{Us as compile,Ds as default,$e as optimize,lt as parse,fe as polyfill,Ue as print,as 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.7.0",
3
+ "version": "4.7.1",
4
4
  "description": "Light & fast WAT compiler – WebAssembly Text to binary, parse, print, transform",
5
5
  "main": "watr.js",
6
6
  "bin": {
@@ -54,7 +54,7 @@
54
54
  "test:wasm": "WATR_WASM=1 node test",
55
55
  "test:repl": "npx playwright test",
56
56
  "types": "npx tsc src/*.js watr.js --allowJs --declaration --emitDeclarationOnly --declarationMap --outDir types",
57
- "prepublishOnly": "npm run build && npm run types && npm test && npm run test:wasm",
57
+ "prepublishOnly": "npm run build && npm run types && npm test",
58
58
  "prepare": "git submodule update --init --recursive 2>/dev/null || true"
59
59
  },
60
60
  "repository": {
package/src/optimize.js CHANGED
@@ -1873,7 +1873,7 @@ const buildInline = (params, locals, inlResult, cBody, args) => {
1873
1873
  *
1874
1874
  * A callee qualifies when it is small (≤ INLINE_MAX_NODES IR nodes), named with
1875
1875
  * named params/locals, single-result-or-void, non-recursive, not pinned
1876
- * (export/start/elem/ref.func), not a SIMD_PROTECTED transcendental, and free of
1876
+ * (export/start/elem/ref.func), not in the caller's `pin` set, and free of
1877
1877
  * depth-relative branches / tail calls (the inlParse + inlUnsafe liftability
1878
1878
  * contract). Runs to a fixpoint so small-helper chains (sdf → sdRep) collapse.
1879
1879
  *
@@ -1893,7 +1893,7 @@ const buildInline = (params, locals, inlResult, cBody, args) => {
1893
1893
  const INLINE_MAX_NODES = 90
1894
1894
  const isV128SimdHelper = (params, inlResult) =>
1895
1895
  inlResult === 'v128' && params.length > 0 && params.every(p => p.type === 'v128')
1896
- const inline = (ast, { simdOnly = false } = {}) => {
1896
+ const inline = (ast, { simdOnly = false, pin = EMPTY_SET } = {}) => {
1897
1897
  if (!Array.isArray(ast) || ast[0] !== 'module') return ast
1898
1898
 
1899
1899
  const skip = new Set() // callees with a non-inlinable site (arity mismatch) — don't re-pick
@@ -1917,7 +1917,7 @@ const inline = (ast, { simdOnly = false } = {}) => {
1917
1917
  // Pick a small, liftable, non-recursive callee with ≥1 plain-call site.
1918
1918
  let calleeName = null, parsed = null
1919
1919
  for (const [name, fn] of funcByName) {
1920
- if (skip.has(name) || pinned.has(name) || otherRef.has(name) || SIMD_PROTECTED.has(name)) continue
1920
+ if (skip.has(name) || pinned.has(name) || otherRef.has(name) || pin.has(name)) continue
1921
1921
  if (!(callRefs.get(name) >= 1)) continue
1922
1922
  if (inlBodySize(fn) > INLINE_MAX_NODES) continue
1923
1923
  if (inlCallsSelf(fn, name)) continue
@@ -2254,12 +2254,7 @@ const devirt = (ast) => {
2254
2254
  * @param {Array} ast
2255
2255
  * @returns {Array}
2256
2256
  */
2257
- // Scalar transcendental helpers the auto-vectorizer rewrites to f64x2 mirrors (PPC_CALL2 in
2258
- // src/optimize/vectorize.js). inlineOnce must NOT dissolve their call nodes when single-caller —
2259
- // the post-phase lift needs the call to rewrite it. Keep in sync with PPC_CALL2's keys.
2260
- const SIMD_PROTECTED = new Set(['$math.sin_core', '$math.cos_core', '$math.sin', '$math.cos', '$math.pow', '$math.atan2', '$math.hypot', '$math.log'])
2261
-
2262
- const inlineOnce = (ast) => {
2257
+ const inlineOnce = (ast, { pin = EMPTY_SET } = {}) => {
2263
2258
  if (!Array.isArray(ast) || ast[0] !== 'module') return ast
2264
2259
 
2265
2260
  // Lift primitives are shared with `inline` (defined once above buildInline). inlineOnce
@@ -2291,11 +2286,10 @@ const inlineOnce = (ast) => {
2291
2286
  for (const [name, fn] of funcByName) {
2292
2287
  if (pinned.has(name) || otherRef.has(name)) continue
2293
2288
  if (callRefs.get(name) !== 1) continue
2294
- // Keep the scalar transcendentals that the auto-vectorizer maps to f64x2 mirrors (PPC_CALL2 in
2295
- // src/optimize/vectorize.js): inlining a single-caller $math.atan2/hypot/log would dissolve the
2296
- // call node before the post-phase lift can rewrite it to $math.atan2_2/hypot_2/log_v. Keep in
2297
- // sync with PPC_CALL2's keys.
2298
- if (SIMD_PROTECTED.has(name)) continue
2289
+ // Caller-pinned functions stay intact: inlining a single-caller helper would dissolve the
2290
+ // call node, and a consumer may rely on it surviving (e.g. jz pins the scalar transcendentals
2291
+ // its auto-vectorizer later rewrites to f64x2 mirrors). The policy lives with the caller.
2292
+ if (pin.has(name)) continue
2299
2293
  if (callsSelf(fn, name)) continue
2300
2294
  // named params/locals only (we'll rename them); reject locals with types
2301
2295
  // we can't zero-init on block re-entry.
@@ -3867,6 +3861,10 @@ export default function optimize(ast, opts = true) {
3867
3861
  if (typeof ast === 'string') ast = parse(ast) // accept WAT source directly
3868
3862
  const strictGuard = opts === true // default: zero tolerance for bloat
3869
3863
  opts = normalize(opts)
3864
+ // `pin`: caller-supplied function names that inlineOnce/inline must NOT dissolve. Keeps
3865
+ // optimizer policy with the CALLER — e.g. jz pins the scalar transcendentals its own
3866
+ // auto-vectorizer later rewrites to f64x2 mirrors, so no consumer-specific names live here.
3867
+ opts.pin = opts.pin instanceof Set ? opts.pin : new Set(opts.pin || [])
3870
3868
 
3871
3869
  const log = opts.log ? (msg, delta) => opts.log(msg, delta) : () => {}
3872
3870
  const verbose = opts.verbose || opts.log
@@ -3888,7 +3886,7 @@ export default function optimize(ast, opts = true) {
3888
3886
  if (!opts.inline) return a
3889
3887
  // `inline: 'simd'` → SIMD-helper-only (jz's speed tier, avoids general bloat);
3890
3888
  // `inline: true` / `'all'` → general inlining of tiny functions.
3891
- a = inline(a, { simdOnly: opts.inline === 'simd' })
3889
+ a = inline(a, { simdOnly: opts.inline === 'simd', pin: opts.pin })
3892
3890
  if (opts.propagate) a = propagate(a)
3893
3891
  if (opts.mergeBlocks) a = mergeBlocks(a)
3894
3892
  if (opts.vacuum) a = vacuum(a)
@@ -3909,7 +3907,7 @@ export default function optimize(ast, opts = true) {
3909
3907
  // propagate, and it would only confirm what `mayInline` already proved.
3910
3908
  for (let round = 0; round < 3; round++) {
3911
3909
  const beforeRound = clone(ast)
3912
- for (const [key, fn] of PASSES) if (opts[key] && key !== 'inlineOnce' && key !== 'inline' && key !== 'devirt') ast = fn(ast)
3910
+ for (const [key, fn] of PASSES) if (opts[key] && key !== 'inlineOnce' && key !== 'inline' && key !== 'devirt') ast = fn(ast, opts)
3913
3911
  if (equal(beforeRound, ast)) break // fixpoint
3914
3912
  if (verbose) log(` round ${round + 1} applied`)
3915
3913
  }
@@ -3926,7 +3924,7 @@ export default function optimize(ast, opts = true) {
3926
3924
  for (let round = 0; round < 3; round++) {
3927
3925
  beforeRound = clone(ast)
3928
3926
 
3929
- for (const [key, fn] of PASSES) if (opts[key] && key !== 'devirt' && key !== 'inline') ast = fn(ast)
3927
+ for (const [key, fn] of PASSES) if (opts[key] && key !== 'devirt' && key !== 'inline') ast = fn(ast, opts)
3930
3928
  // Second propagate sweep: `inlineOnce`/`inline` (above) leave fresh
3931
3929
  // `(local.set $p arg) … (local.get $p)` wrappers around each inlined call;
3932
3930
  // re-running propagation collapses them within this same round, so the size
@@ -56,10 +56,42 @@ export function strength(ast: any[]): any[];
56
56
  */
57
57
  export function branch(ast: any[]): any[];
58
58
  export function propagate(ast: any): any;
59
- export function inline(ast: any, { simdOnly }?: {
59
+ export function inline(ast: any, { simdOnly, pin }?: {
60
60
  simdOnly?: boolean;
61
+ pin?: any;
61
62
  }): any;
62
- export function inlineOnce(ast: any): any;
63
+ /**
64
+ * Inline functions that are called from exactly one place into their lone caller,
65
+ * then delete them. Unlike {@link inline} (which duplicates tiny stateless bodies),
66
+ * this never duplicates code and never inflates: each inlined function drops a
67
+ * function-section entry, a type-section entry (if now unused), and a `call`
68
+ * instruction, paying back only a `block`/`local.set` wrapper. This is what
69
+ * `wasm-opt -Oz` does — collapsing helper chains down to a couple of functions —
70
+ * and it's the bulk of the gap between hand-tuned WASM and naive codegen.
71
+ *
72
+ * A function `$f` qualifies when it is, all of:
73
+ * • named, with named params and locals (numeric indices can't be safely renamed);
74
+ * • referenced exactly once across the whole module, by a plain `call` (no
75
+ * `return_call`, `ref.func`, `elem`, `export`, or `start` reference, and not
76
+ * recursive);
77
+ * • single-result or void (a multi-value result can't be modeled as `(block (result …))`);
78
+ * • free of numeric (depth-relative) branch labels — those would shift under the
79
+ * extra block nesting — and of `return_call*` in its body.
80
+ *
81
+ * `(call $f a0 a1 …)` becomes
82
+ * (block $__inlN (result T)?
83
+ * (local.set $__inlN_p0 a0) (local.set $__inlN_p1 a1) … ;; args evaluated once, in order
84
+ * …body, params/locals renamed to $__inlN_*, `return X` → `br $__inlN X`…)
85
+ * and the renamed params+locals are appended to the caller's `local` decls; the
86
+ * body's own block/loop/if labels are renamed too so they can't shadow the caller's.
87
+ * Runs to a fixpoint so helper chains fully collapse.
88
+ *
89
+ * @param {Array} ast
90
+ * @returns {Array}
91
+ */
92
+ export function inlineOnce(ast: any[], { pin }?: {
93
+ pin?: any;
94
+ }): any[];
63
95
  /**
64
96
  * Devirtualize `call_indirect` through NaN-boxed closure values with a statically
65
97
  * known candidate set. `let f = c ? a : b; … f(x)` emits a select of two i64
@@ -1 +1 @@
1
- {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AAyxHA,gEAyFC;AA9zHD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AA8CD;;;;;GAKG;AACH,6CAgJC;AAwUD;;;;GAIG;AACH,wCAkDC;AA0YD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AAndD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CAwDC;AAID;;;;GAIG;AACH,0CA6CC;AAuyBD,yCAqCC;AAmND;;QAqEC;AAySD,0CAgJC;AArbD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,sCAwOC;AAghDD;;;;;;;;GAQG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAc/B;AAvBD,qEAAqE;AACrE,uBAA8D;AArlC9D;;;;;GAKG;AACH,0CA8DC;AA+ED;;;;GAIG;AACH,4CAQC;AAiCD;;;;;;;;;;;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;AAwWD,uCAyBC;AA7XD;;;;;GAKG;AACH,8CAyEC;AA2ID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AA/sCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}
1
+ {"version":3,"file":"optimize.d.ts","sourceRoot":"","sources":["../../src/optimize.js"],"names":[],"mappings":"AAmxHA,gEA6FC;AA5zHD;;;;GAIG;AACH,4BAHW,GAAG,GACD,MAAM,CAOlB;AAED;;;;GAIG;AACH,wCAFa,MAAM,CAIlB;AA8CD;;;;;GAKG;AACH,6CAgJC;AAwUD;;;;GAIG;AACH,wCAkDC;AA0YD;;;;GAIG;AACH,4CAqBC;AA+CD;;;;;GAKG;AACH,8CAmDC;AAndD;;;;GAIG;AACH,4CASC;AAID;;;;GAIG;AACH,4CAwDC;AAID;;;;GAIG;AACH,0CA6CC;AAuyBD,yCAqCC;AAmND;;;QAqEC;AAuQD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH;;UA+IC;AA/aD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,sCAwOC;AA0gDD;;;;;;;;GAQG;AACH,gCAHW,OAAO,GAAC,MAAM,MAAO,OAc/B;AAvBD,qEAAqE;AACrE,uBAA8D;AArlC9D;;;;;GAKG;AACH,0CA8DC;AA+ED;;;;GAIG;AACH,4CAQC;AAiCD;;;;;;;;;;;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;AAwWD,uCAyBC;AA7XD;;;;;GAKG;AACH,8CAyEC;AA2ID;;;;GAIG;AACH,4CAyDC;AAqBD;;;;;GAKG;AACH,iDAgBC;AA/sCD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,+CAiFC;AAID;;;;;;;;;;;;;;;;GAgBG;AACH,kDAyFC"}