watr 4.3.1 → 4.3.4

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.min.js CHANGED
@@ -1,6 +1,6 @@
1
- var Gt=Object.defineProperty;var Kt=(t,e)=>{for(var r in e)Gt(t,r,{get:e[r],enumerable:!0})};var tt={};Kt(tt,{f32:()=>Q,f64:()=>J,i16:()=>te,i32:()=>W,i64:()=>Z,i8:()=>Qt,uleb:()=>g,uleb5:()=>Zt});var I=(t,e=I.loc)=>{if(e!=null&&I.src){let r=1,i=1;for(let s=0;s<e&&s<I.src.length;s++)I.src[s]===`
2
- `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var Nt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Bt=/^[+-]?(?:0x[\da-f]+|\d+)$/i,Xt=new TextEncoder,Jt=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),kt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},nt=t=>{let e=[],r=1,i,s,l="",n=()=>(l&&e.push(...Xt.encode(l)),l="");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++):kt[t[r]]?i=kt[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(n(),e.push(i)):l+=s;return n(),e.valueOf=()=>t,e},Mt=t=>Jt.decode(new Uint8Array(nt(t)));var g=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):W.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),g(t,e))};function Zt(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 W(t,e=[]){for(typeof t=="string"&&(t=W.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 zt=t=>!Nt.test(t)&&Bt.test(t=t.replaceAll("_",""))?t:I(`Bad int ${t}`),Qt=W,te=W;W.parse=t=>(t=parseInt(zt(t)),(t<-2147483648||t>4294967295)&&I("i32 constant out of range"),t);function Z(t,e=[]){for(typeof t=="string"?t=Z.parse(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}Z.parse=t=>(t=zt(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&I("i64 constant out of range"),q.setBigInt64(0,t),q.getBigInt64(0));var q=new DataView(new Float64Array(1).buffer),ee=2147483648,re=2139095040;function Q(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=W.parse(t.slice(r+4)),e|=re,t[0]==="-"&&(e|=ee),q.setInt32(0,e)):(e=typeof t=="string"?Q.parse(t):t,q.setFloat32(0,e)),[q.getUint8(3),q.getUint8(2),q.getUint8(1),q.getUint8(0)]}var ie=0x8000000000000000n,se=0x7ff0000000000000n;function J(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=Z.parse(t.slice(r+4)),e|=se,t[0]==="-"&&(e|=ie),q.setBigInt64(0,e)):(e=typeof t=="string"?J.parse(t):t,q.setFloat64(0,e)),[q.getUint8(7),q.getUint8(6),q.getUint8(5),q.getUint8(4),q.getUint8(3),q.getUint8(2),q.getUint8(1),q.getUint8(0)]}J.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),[l,n=""]=i.split("."),a=n.length??0,o=parseInt(l);isNaN(o)&&I();let f=n?parseInt("0x"+n)/16**a:0;s=parseInt(s,10);let c=r*(o+f)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};Q.parse=t=>J.parse(t,34028234663852886e22);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.cast 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"],["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"]],B={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},T={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,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},V={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},ht={func:0,table:1,memory:2,global:3,tag:4};var D=t=>{let e=0,r=[],i="",s=0,l=0,n=()=>i&&(r.push(i),i=""),a=o=>{r.loc=o;for(let f,c,u;e<t.length;)if(f=t.charCodeAt(e),s===34)i+=t[e++],f===92?i+=t[e++]:f===34&&(n(),s=0);else if(s>59)f===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(n(),s=0)):i+=t[e++];else if(s<0)f===10||f===13?(i+=t[e++],n(),s=0):s===-2&&f===41?(n(),s=0):i+=t[e++];else if(f===34)i!=="$"&&n(),s=34,i+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)n(),s=60,i=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)n(),s=t.indexOf(`
3
- `,e)<0?-2:-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)n(),u=e,e+=2,i="@",l++,(c=r).push(r=[]),a(u),r=c;else if(f===40)n(),u=e++,l++,(c=r).push(r=[]),a(u),r=c;else{if(f===41)return n(),e++,l--;f<=32?(n(),e++):i+=t[e++]}s<0&&n(),n()};return a(0),s===34&&I("Unclosed quote",e),s>59&&I("Unclosed block comment",e),l>0&&I("Unclosed parenthesis",e),e<t.length&&I("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Et=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Et).filter(r=>r!=null),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):typeof t!="string"?t:t[0]===";"||t[1]===";"?null:t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+Mt(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?nt(t):t;function rt(t){typeof t=="string"?(I.src=t,t=D(t)||[]):I.src="",I.loc=0,t=Et(t)||[];let e=0;if(t[0]==="module"?(e++,O(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return rt(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,h)=>{if(h<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,p,...b]=u;if(!b.some(x=>Array.isArray(x)&&x[0]==="item"))return[u];if(Array.isArray(b.at(-1))&&b.at(-1)[0]!=="item"){let x=b.at(-1);return b.slice(0,-1).filter(m=>m[0]==="item").map(([,m])=>["import",p,m,x])}return b.filter(x=>x[0]==="item").map(([,x,m])=>["import",p,x,m])});let r=[];for(let u in B)(r[B[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let b=I.loc,_=I.src,x;for(;(b=_.indexOf(u,b))>=0;){if(x=_.charCodeAt(b-1),b>0&&(x>47&&x<58||x>64&&x<91||x>96&&x<123||x===95||x===36)){b++;continue}if(x=_.charCodeAt(b+u.length),x>47&&x<58||x>64&&x<91||x>96&&x<123||x===95){b++;continue}break}b>=0&&(I.loc=b),I(`Unexpected token ${u}`)}let[h,...p]=u;if(I.loc=u.loc,h==="@custom")r.custom.push(p);else if(h==="rec")for(let b=0;b<p.length;b++){let[,..._]=p[b];dt(_,r.type);let x=[];for(;_[0]?.[0]==="descriptor"||_[0]?.[0]==="describes";)x.push(_.shift());(_=Ut(_,r)).push(b?!0:[r.type.length,p.length]),x.length&&(_.desc=_.desc?[...x,..._.desc]:x),r.type.push(_)}else if(h==="type"){dt(p,r.type);let b=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)b.push(p.shift());let _=Ut(p,r);b.length&&(_.desc=_.desc?[...b,..._.desc]:b),r.type.push(_)}else if(h==="start"||h==="export")r[h].push(p);else return!0}).forEach(u=>{let[h,...p]=u;I.loc=u.loc;let b;h==="import"&&([h,...p]=(b=p).pop());let _=r[h];for(_||I(`Unknown section ${h}`),dt(p,_);p[0]?.[0]==="export";)r.export.push([p.shift()[1],[h,_?.length]]);if(p[0]?.[0]==="import"&&([,...b]=p.shift()),h==="table"){let x=p[0]==="i64",m=x?1:0;if(p[m+1]?.[0]==="elem"){let[d,[,...y]]=[p[m],p[m+1]];p=x?["i64",y.length,y.length,d]:[y.length,y.length,d],r.elem.push([["table",_.length],["offset",[x?"i64.const":"i32.const",x?0n:0]],d,...y])}}else if(h==="memory"){let x=p[0]==="i64",m=x?1:0;if(p[m]?.[0]==="data"){let d=p.find(w=>Array.isArray(w)&&w[0]==="pagesize")?.[1]??65536,[,...y]=p.splice(m,1)[0],v=""+Math.ceil(y.reduce((w,k)=>w+k.length,0)/d);r.data.push([["memory",_.length],[x?"i64.const":"i32.const",x?0n:0],...y]),p=x?["i64",v,v]:[v,v]}}else if(h==="func"){let[x,m,d]=pt(p,r);x??=mt(m,d,r),!b&&r.code.push([[x,m,d],...Y(p,r)]),p=[["type",x]]}else if(h==="tag"){let[x,m]=pt(p,r);x??=mt(m,[],r),p=[["type",x]]}b&&(r.import.push([...b,[h,...p]]),p=null),_.push(p)});let i=(u,h=!0)=>{let p=r[u].filter(Boolean).map(b=>qt[u](b,r)).filter(Boolean);return u===B.custom?p.flatMap(b=>[u,...N(b)]):p.length?[u,...N(h?N(p):p)]:[]},s=()=>{let u=[];for(let h in r.metadata){let p=N(nt(`"metadata.code.${h}"`)),b=N(r.metadata[h].map(([_,x])=>[...g(_),...N(x.map(([m,d])=>[...g(m),...N(d)]))]));u.push(0,...N([...p,...b]))}return u},l=i(B.global),n=i(B.elem),a=i(B.code),o=s(),f=i(B.data),c=r.strings.length?[B.strings,...N([0,...N(r.strings.map(u=>N(u)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(B.custom),...i(B.type),...i(B.import),...i(B.func),...i(B.table),...i(B.memory),...i(B.tag),...c,...l,...i(B.export),...i(B.start,!1),...n,...i(B.datacount,!1),...a,...o,...f])}var L=t=>t?.[0]==="$"||!isNaN(t),O=t=>t?.[0]==="$",bt=t=>t?.[0]==="a"||t?.[0]==="o";function Y(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")O(t[0])&&r.push(t.shift()),r.push(at(t,e));else if(i==="else"||i==="end")O(t[0])&&t.shift();else if(i==="select")r.push(_t(t)[1]);else if(i.endsWith("call_indirect")){let s=L(t[0])?t.shift():0,[l,n,a]=pt(t,e);r.push(s,["type",l??mt(n,a,e)])}else i==="table.init"?r.push(L(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(L(t[0])?t.shift():0,L(t[0])?t.shift():0):i.startsWith("table.")?r.push(L(t[0])?t.shift():0):i==="memory.init"?(r.push(...L(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"))&&L(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(I.loc=i.loc),s?.startsWith?.("@metadata.code.")){let n=s.slice(15);r.push(["@metadata",n,i[1]]);continue}if(typeof s!="string"||!Array.isArray(st[s])){r.push(i);continue}let l=i.slice(1);if(s==="block"||s==="loop")r.push(s),O(l[0])&&r.push(l.shift()),r.push(at(l,e),...Y(l,e),"end");else if(s==="if"){let n=[],a=[];l.at(-1)?.[0]==="else"&&(a=Y(l.pop().slice(1),e)),l.at(-1)?.[0]==="then"&&(n=Y(l.pop().slice(1),e));let o=[s];O(l[0])&&o.push(l.shift()),o.push(at(l,e)),r.push(...Y(l,e),...o,...n),a.length&&r.push("else",...a),r.push("end")}else if(s==="try_table"){for(r.push(s),O(l[0])&&r.push(l.shift()),r.push(at(l,e));l[0]?.[0]==="catch"||l[0]?.[0]==="catch_ref"||l[0]?.[0]==="catch_all"||l[0]?.[0]==="catch_all_ref";)r.push(l.shift());r.push(...Y(l,e),"end")}else{let n=[];for(;l.length&&(!Array.isArray(l[0])||l[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(l[0][0]));)n.push(l.shift());r.push(...Y(l,e),s,...n),t.unshift(...r.splice(r.length-1-n.length))}}else r.push(i)}return r}var mt=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),At=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=O(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},_t=t=>{let e=At(t,"param"),r=At(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},pt=(t,e)=>{if(t[0]?.[0]!=="type")return[,..._t(t)];let[,r]=t.shift(),[i,s]=_t(t),l=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!l)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&l[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...l[1]]},at=(t,e)=>{let[r,i,s]=pt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??mt(i,s,e)]},dt=(t,e)=>{let r=O(t[0])&&t.shift();return r&&(r in e?I(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},Ut=([t],e)=>{let r="subfinal",i=[],s,l=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(l.push(a),!1):!0)),[s,...t]=t,s==="func"?(t=_t(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=At(t,"field"):s==="array"&&([t]=t);let n=[s,t,r,i];return l.length&&(n.desc=l),n},qt=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...N(t),...i.flat()]},(t,e)=>{let[r,i,s,l,n]=t;if(n===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...g(A(c,e.type))]),o=(f,c)=>f==="func"?[V.func,...N(c[0].map(u=>C(u,e))),...N(c[1].map(u=>C(u,e)))]:f==="array"?[V.array,...ft(c,e)]:f==="struct"?[V.struct,...N(c.map(u=>ft(u,e)))]:f==="cont"?[V.cont,...g(A(c[0]??c,e.type))]:[V[f]];if(n){let[f,c]=n,u=Array.from({length:c},(h,p)=>{let b=e.type[f+p],_=b.slice(0,4);return b.desc&&(_.desc=b.desc),qt[B.type](_,e)});return[V.rec,...N(u)]}else if(s==="sub"||l?.length)return[V[s],...N(l.map(f=>A(f,e.type))),...a,...o(r,i)];return[...a,...o(r,i)]},([t,e,[r,...i]],s)=>{let l,n=ht[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(n=32);let[[,o]]=i;l=g(A(o,s.type))}else if(r==="tag"){let[[,a]]=i;l=[0,...g(A(a,s.type))]}else r==="memory"?l=ot(i):r==="global"?l=ft(i[0],s):r==="table"?l=[...C(i.pop(),s),...ot(i)]:I(`Unknown kind ${r}`);return[...N(t),...N(e),n,...l]},([[,t]],e)=>g(A(t,e.type)),(t,e)=>{let r=ot(t),i=C(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...et(s,e)]:[...i,...r]},(t,e)=>ot(t),([t,e],r)=>[...ft(t,r),...et(e,r)],([t,[e,r]],i)=>[...N(t),ht[e],...g(A(r,i[e]))],([t],e)=>g(A(t,e.func)),(t,e)=>{let r=0,i=0,s=0,l=0,n,a,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,n]=t.shift(),n=A(n,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"))&&(n=A(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(a=t.shift(),a[0]==="offset"&&([,a]=a),a=et(a,e)):i||(r=1),T[t[0]]||t[0]?.[0]==="ref"?o=C(t.shift(),e):t[0]==="func"?o=[T[t.shift()]]:o=[T.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==T.funcref&&(l=1,s=1);let f=s<<2|(r||i?i:!!n||l)<<1|(r||i);return[f,...f===0?a:f===1?[0]:f===2?[...g(n||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...g(n||0),...a,...o]:o,...N(t.map(s?c=>et(typeof c=="string"?["ref.func",c]:c,e):c=>g(A(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[A(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(O(o[0])){let f=o.shift();f in e.local?I(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let l=Ot(t,e),n=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([n,e.meta[o]]);let a=e.local.slice(i.length).reduce((o,f)=>(f==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,f]),o),[]);return e.local=e.block=e.meta=null,N([...N(a.map(([o,f])=>[...g(o),...C(f,e)])),...l])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=A(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=A(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??I("Bad offset",r)),[...i?[2,...g(i),...et(r,e)]:r?[0,...et(r,e)]:[1],...N(t.flatMap(s=>ae(s)??[...s]))]},(t,e)=>g(e.data.length),([[,t]],e)=>[0,...g(A(t,e.type))]],C=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[T.refnull,98,...g(A(t[2][1],e.type))]:T[t[2]]?[T[t[2]]]:[T.refnull,...g(A(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[T.ref,98,...g(A(t[1][1],e.type))]:[T.ref,...g(T[t[t.length-1]]||A(t[t.length-1],e.type))]:[T[t]??I(`Unknown type ${t}`)],ft=(t,e,r=t[0]==="mut"?1:0)=>[...C(r?t[1]:t,e),r],St={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...g(A(i,e.elem)),...g(A(r,e.table))]},block:(t,e)=>{e.block.push(1),O(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?C(r[1],e):g(A(r[1],e.type)):[T.void]},try_table:(t,e)=>{O(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?C(r[1],e):g(A(r[1],e.type)):[T.void],s=[],l=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let n=t.shift(),a=n[0]==="catch"?0:n[0]==="catch_ref"?1:n[0]==="catch_all"?2:3;a<=1?s.push(a,...g(A(n[1],e.tag)),...g(H(n[2],e.block))):s.push(a,...g(H(n[1],e.block))),l++}return e.block.push(1),[...i,...g(l),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...g(A(i,e.type)),...g(A(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||O(t[0]));)r.push(...g(H(t.shift(),e.block))),i++;return[...g(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?N(r.map(i=>C(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...g(A(r[1],e.type))]:T[r]?[T[r]]:g(A(r,e.type))},memarg:(t,e,r)=>Tt(t,r,L(t[0])&&!bt(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>g(A(L(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=C(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=H(t.shift(),e.block),i=C(t.shift(),e),s=C(t.shift(),e),l=n=>n.length>1?n.slice(1):n;return[(s[0]!==T.ref)<<1|i[0]!==T.ref,...g(r),...l(i),...l(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let n=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)n[a]=tt[e].parse(t.shift());return[...new Uint8Array(n.buffer)]}let l=new Uint8Array(16);for(let n=0;n<r;n++)l.set(tt[e](t.shift()),n*s);return[...l]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(ut(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&I("invalid lane length"),e},memlane:(t,e,r)=>{let i=O(t[0])||L(t[0])&&(bt(t[1])||L(t[1]))?A(t.shift(),e.memory):0;return[...Tt(t,r,i),...g(ut(t.shift()))]},"*":t=>g(t.shift()),labelidx:(t,e)=>g(H(t.shift(),e.block)),laneidx:t=>[ut(t.shift(),255)],funcidx:(t,e)=>g(A(t.shift(),e.func)),typeidx:(t,e)=>g(A(t.shift(),e.type)),tableidx:(t,e)=>g(A(t.shift(),e.table)),memoryidx:(t,e)=>g(A(t.shift(),e.memory)),globalidx:(t,e)=>g(A(t.shift(),e.global)),localidx:(t,e)=>g(A(t.shift(),e.local)),dataidx:(t,e)=>g(A(t.shift(),e.data)),elemidx:(t,e)=>g(A(t.shift(),e.elem)),tagidx:(t,e)=>g(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>g(A(L(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(l=>l.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),g(s)},i32:t=>W(t.shift()),i64:t=>Z(t.shift()),f32:t=>Q(t.shift()),f64:t=>J(t.shift()),v128:t=>(void 0)(t.shift()),typeidx_field:(t,e)=>{let r=A(t.shift(),e.type);return[...g(r),...g(A(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...g(A(t.shift(),e.type)),...g(t.shift())],typeidx_dataidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...g(A(t.shift(),e.data)),...g(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...g(A(t.shift(),e.memory)),...g(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...g(A(t.shift(),e.table)),...g(A(t.shift(),e.table))],cont_bind:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.type))],switch_cont:(t,e)=>[...g(A(t.shift(),e.type)),...g(A(t.shift(),e.tag))],resume:(t,e)=>{let r=g(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...g(A(l,e.tag))):i.push(0,...g(A(l,e.tag)),...g(H(n,e.block))),s++}return[...r,...g(s),...i]},resume_throw:(t,e)=>{let r=g(A(t.shift(),e.type)),i=g(A(t.shift(),e.tag)),s=[],l=0;for(;t[0]?.[0]==="on";){let[,n,a]=t.shift();a==="switch"?s.push(1,...g(A(n,e.tag))):s.push(0,...g(A(n,e.tag)),...g(H(a,e.block))),l++}return[...r,...i,...g(l),...s]},resume_throw_ref:(t,e)=>{let r=g(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...g(A(l,e.tag))):i.push(0,...g(A(l,e.tag)),...g(H(n,e.block))),s++}return[...r,...g(s),...i]}},ct={};(function t(e,r){for(let i=0,s,l,n;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([l,n]=s.split(" "),st[l]=r?[r,...g(i)]:[i],n&&(ct[l]=St[n])))})(st);var Ot=(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&&(I.loc=s.loc),I(`Unknown instruction ${s[0]}`));let[...l]=st[s]||I(`Unknown instruction ${s}`);ct[s]&&(s==="select"&&t[0]?.length?l[0]++:ct[s]===St.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&l[l.length-1]++,l.push(...ct[s](t,e,s)));for(let[n,a]of i)(e.meta[n]??=[]).push([r.length,a]);r.push(...l)}return r.push(11),r},et=(t,e)=>Ot(Y([t],e),e),A=(t,e,r)=>(r=O(t)?e[t]:+t,r in e?r:I(`Unknown ${e.name} ${t}`)),H=(t,e,r)=>(r=O(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?I(`Bad label ${t}`):r),le=t=>{let e,r,i,s;for(;bt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:I(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&I(`Bad offset ${r}`),(e<=0||e>4294967295)&&I(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&I(`Bad align ${e}`),[e,r]},Tt=(t,e,r=0)=>{let[i,s]=le(t),l=(i??ne(e))|(r&&64);return r?[...g(l),...g(r),...g(s??0)]:[...g(l),...g(s??0)]},ne=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 l=t.slice(e,e+6).match(/\d+/);return Math.log2(l?l[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)},ae=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 l of r)e==="i8"?i.push(W.parse(l)&511&255):e==="i16"?(s.setInt16(0,W.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,W.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(l),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...Q(l)):e==="f64"&&i.push(...J(l));return i},ot=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let l=!isNaN(parseInt(t[1])),n=(s>=0?8:0)|(e?4:0)|(r?2:0)|(l?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:ut,o=s>=0?g(s):[];return l?[n,...g(a(t.shift())),...g(a(t.shift())),...o]:[n,...g(a(t.shift())),...o]},ut=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?W.parse(t):typeof t=="number"?t:I(`Bad int ${t}`);return r>e?I(`Value out of range ${t}`):r},N=t=>[...g(t.length),...t.flat()];function Ft(t,e={}){typeof t=="string"&&(t=D(t));let{indent:r=" ",newline:i=`
4
- `,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return n(t);return t.filter(a=>s||!l(a)).map(a=>n(a)).join(i);function l(a){return typeof a=="string"&&a[1]===";"}function n(a,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let p=1;for(typeof a[p]=="string"&&a[p][0]==="$"&&(f+=" "+a[p++]),Array.isArray(a[p])&&(a[p][0]==="result"||a[p][0]==="type")&&(f+=" "+n(a[p++],o));Array.isArray(a[p])&&/^catch/.test(a[p][0]);)f+=" "+n(a[p++],o).trim();for(;p<a.length;p++)f+=Array.isArray(a[p])?i+r.repeat(o+1)+n(a[p],o+1):" "+a[p];return`(${f+i+r.repeat(o)})`}let u=!!i&&a.length<4&&!a.some(p=>typeof p=="string"&&p[0]===";"&&p[1]===";"),h=r.repeat(o+1);for(let p=1;p<a.length;p++){let b=a[p].valueOf();if(typeof b=="string"&&b[1]===";"){if(!s)continue;if(b[0]===";")if(i)f+=i+h+b.trimEnd(),c=!0;else{let _=f[f.length-1];_&&_!==" "&&_!=="("&&(f+=" "),f+=b.trimEnd()+`
5
- `}else{let _=f[f.length-1];_&&_!==" "&&_!=="("&&(f+=" "),f+=b.trimEnd()}}else if(Array.isArray(b))u&&(u=b.every(_=>!Array.isArray(_))),f+=i+h+n(b,o+1),c=!1;else if(a[0]==="data")u=!1,(i||f[f.length-1]!==")")&&(f+=i||" "),f+=h+b,c=!1;else{let _=f[f.length-1];c&&i?f+=i+h:_===`
6
- `?f+="":(_&&_!==")"&&_!==" "||i||_===")")&&(f+=" "),f+=b,c=!1}}return u?`(${f.replaceAll(i+h+"("," (")})`:`(${f+i+r.repeat(o)})`}}var Ct={funcref:["ref.func","call_ref","return_call_ref"],sign_ext:["i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s"],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"],bulk_memory:["memory.copy","memory.fill"],return_call:["return_call","return_call_indirect"],i31ref:["ref.i31","i31.get_s","i31.get_u"],extended_const:["global.get"],multi_value:[],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"],ref_cast:["ref.test","ref.cast","br_on_cast","br_on_cast_fail"]},wt=Object.keys(Ct),fe=t=>{if(t===!0)return Object.fromEntries(wt.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(wt.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},S=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)S(t[s],e,t,s)},j=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)j(t[s],e,t,s);e(t,r,i)},oe=t=>{let e=new Set;return S(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(Ct))s.some(l=>r===l||r.startsWith(l+" "))&&e.add(i)}),S(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&S(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),S(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e},Dt=t=>Array.isArray(t)?t.map(Dt):t,Lt=(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},yt=(t,e,r)=>t.splice(e,0,r),ce=0,R=t=>`$__${t}${ce++}`,ue=(t,e)=>{let r=new Set;if(S(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let i=R("fntbl"),s=[...r],l=Object.fromEntries(s.map((f,c)=>[f,c])),n=Lt(t,"func"),a=n.length?n[0].idx:t[0]==="module"?1:0;yt(t,a,["table",i,"funcref",["elem",...s]]);let o={};return S(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let u=[],h=[];for(let p of f){if(Array.isArray(p)&&p[0]==="param")for(let b=1;b<p.length;b++)p[b][0]!=="$"&&u.push(p[b]);if(Array.isArray(p)&&p[0]==="result")for(let b=1;b<p.length;b++)h.push(p[b])}o[c]={params:u,results:h}}),j(t,(f,c,u)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&l[f[1]]!==void 0&&(c[u]=["i32.const",l[f[1]]]),f[0]==="call_ref"){let h=f[1],p=f.slice(2);c[u]=["call_indirect",i,["type",h],...p]}if(f[0]==="return_call_ref"){let h=f[1],p=f.slice(2);c[u]=["return_call_indirect",i,["type",h],...p]}}}),t},P={funcref:ue},me={"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]},_e=(t,e)=>(j(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let l=me[r[0]];if(!l)return;let[n,a]=l,o=r.slice(1);i[s]=[`${n}.shr_s`,[`${n}.shl`,...o,[`${n}.const`,a]],[`${n}.const`,a]]}),t);P.sign_ext=_e;var Wt={"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}},pe=(t,e)=>{let r=new Set;if(S(t,s=>{Array.isArray(s)&&Wt[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:l,ftype:n,signed:a,min:o,max:f}=Wt[s],c=R(`trunc_${l}_${n}_${a?"s":"u"}`);i[s]=c;let u=`${l}.trunc_${n}_${a?"s":"u"}`,h=l==="i64"?0n:0,p=["func",c,["param","$v",n],["result",l],["if",["result",l],[`${n}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${l}.const`,h]],["else",["if",["result",l],[`${n}.lt`,["local.get","$v"],[`${n}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${l}.const`,o]],["else",["if",["result",l],[`${n}.gt`,["local.get","$v"],[`${n}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${l}.const`,f]],["else",[u,["local.get","$v"]]]]]]]]];t.push(p)}return j(t,(s,l,n)=>{!Array.isArray(s)||!l||i[s[0]]&&(l[n]=["call",i[s[0]],...s.slice(1)])}),t};P.nontrapping=pe;var ye=(t,e)=>{let r=new Set,i=new Set;S(t,n=>{if(Array.isArray(n)){if(n[0]==="memory.copy"){let a=typeof n[1]=="number"?n[1]:0,o=typeof n[2]=="number"?n[2]:0;r.add(`${a}_${o}`)}if(n[0]==="memory.fill"){let a=typeof n[1]=="number"?n[1]:0;i.add(a)}}});let s={},l={};for(let n of r){let[a,o]=n.split("_").map(Number),f=R(`memcpy${n==="0_0"?"":"_"+n}`);s[n]=f;let c=a?["i32.store8",a]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...u,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let n of i){let a=R(`memset${n===0?"":"_"+n}`);l[n]=a;let o=n?["i32.store8",n]:["i32.store8"];t.push(["func",a,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return j(t,(n,a,o)=>{if(!(!Array.isArray(n)||!a)){if(n[0]==="memory.copy"){let f=typeof n[1]=="number"?n[1]:0,c=typeof n[2]=="number"?n[2]:0,u=n.filter(h=>Array.isArray(h)||typeof h=="string"&&h[0]==="$");a[o]=["call",s[`${f}_${c}`],...u]}if(n[0]==="memory.fill"){let f=typeof n[1]=="number"?n[1]:0,c=n.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[o]=["call",l[f],...c]}}}),t};P.bulk_memory=ye;var ge=(t,e)=>{let r=!1;return S(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&j(t,(i,s,l)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[l]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[l]=["return",["call_indirect",...i.slice(1)]]))}),t};P.return_call=ge;var xe=(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 l=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...l,["i32.const",1]],["i32.const",1]]}}),t);P.i31ref=xe;var he=(t,e)=>{let r={};S(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n=s.length-1;n>=0;n--){let a=s[n];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[l]={type:a[0].split(".")[0],value:a[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let l=s[0];if(l==="global.get"&&r[s[1]]){let n=r[s[1]];return[`${n.type}.const`,n.value]}if(l==="i32.add"||l==="i64.add"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}if(l==="i32.sub"||l==="i64.sub"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}if(l==="i32.mul"||l==="i64.mul"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}return s};return j(t,(s,l,n)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!l)){for(let a=2;a<s.length;a++)if(Array.isArray(s[a])){let o=i(s[a]);o!==s[a]&&(s[a]=o)}}}),t};P.extended_const=he;var de=(t,e)=>{let r=new Map,i=[];if(S(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let c of a)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)f.push(c[u]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let s=Math.max(...[...r.values()].map(a=>a.length)),l={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(l[c]||(l[c]=[]),l[c].length<f){let u=R(`ret_${c}_${l[c].length}`);l[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let n=t[0]==="module"?1:0;for(let a of i.reverse())yt(t,n,a);return j(t,(a,o,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let h=0;h<a.length;h++)if(Array.isArray(a[h])&&a[h][0]==="result"){a[h]=["result",u[0]];break}}),t};P.multi_value=de;var lt={i32:4,i64:8,f32:4,f64:8},be=(t,e)=>{let r=new Map,i=new Map,s=1;if(S(t,_=>{if(!Array.isArray(_)||_[0]!=="type")return;let x=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null;if(x){for(let m of _)if(Array.isArray(m)){if(m[0]==="struct"){let d=[];for(let y of m)if(Array.isArray(y)&&y[0]==="field"){let v=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:null,w=v?y[2]:y[1],k=Array.isArray(w)&&w[0]==="mut"?w[1]:w;d.push({name:v,type:k})}r.set(x,{kind:"struct",fields:d}),i.set(x,s++)}if(m[0]==="array"){let d=m[1],y=Array.isArray(d)&&d[0]==="mut"?d[1]:d;r.set(x,{kind:"array",elemType:y}),i.set(x,s++)}}}}),!r.size)return t;let l=Lt(t,"memory").length>0,n=R("alloc"),a=R("heap_ptr"),o=t[0]==="module"?1:0;l||yt(t,o,["memory",1]),yt(t,o+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",n,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",a]],["global.set",a,["i32.add",["global.get",a],["local.get","$size"]]],["local.get","$ptr"]];t.push(f);let c=_=>{let x=4;for(let m of _.fields)x+=lt[m.type]||4;return x},u=(_,x)=>{let m=4;for(let d=0;d<x;d++)m+=lt[_.fields[d].type]||4;return m},h=(_,x)=>{for(let m=0;m<_.fields.length;m++)if(_.fields[m].name===x)return m;return-1},p=0,b=()=>`$__gc_tmp${p++}`;return S(t,_=>{if(!Array.isArray(_)||_[0]!=="func")return;let x=!1,m=!1,d=!1,y=!1;if(S(_,w=>{Array.isArray(w)&&((w[0]==="struct.new"||w[0]==="struct.new_default")&&(x=!0),(w[0]==="array.new"||w[0]==="array.new_default")&&(m=!0,d=!0,y=!0))}),!x&&!m)return;let v=1;for(let w=1;w<_.length;w++){let k=_[w];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"||k[0]==="local"||k[0]==="export"||k[0]==="type"))v=w+1;else if(typeof k=="string"&&k[0]==="$")v=w+1;else if(!Array.isArray(k))v=w+1;else break}x&&_.splice(v++,0,["local","$__gc_ptr","i32"]),m&&_.splice(v++,0,["local","$__gc_aptr","i32"]),d&&_.splice(v++,0,["local","$__gc_alen","i32"]),y&&_.splice(v++,0,["local","$__gc_aidx","i32"])}),j(t,(_,x,m)=>{if(!(!Array.isArray(_)||!x)){if(_[0]==="struct.new"||_[0]==="struct.new_default"){let d=_[1],y=r.get(d);if(!y||y.kind!=="struct")return;let v=c(y),w=i.get(d),k=_.slice(2),M="$__gc_ptr",E=[["local.set",M,["call",n,["i32.const",v]]],["i32.store",["local.get",M],["i32.const",w]]];if(_[0]==="struct.new")for(let z=0;z<y.fields.length;z++){let U=y.fields[z],it=u(y,z),X=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";E.push([X,["i32.add",["local.get",M],["i32.const",it]],k[z]||[`${U.type}.const`,0]])}else for(let z=0;z<y.fields.length;z++){let U=y.fields[z],it=u(y,z),X=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store",Yt=U.type==="i64"?["i64.const",0n]:U.type==="f32"?["f32.const",0]:U.type==="f64"?["f64.const",0]:["i32.const",0];E.push([X,["i32.add",["local.get",M],["i32.const",it]],Yt])}E.push(["local.get",M]),x[m]=["block",["result","i32"],...E]}if(_[0]==="struct.get"){let d=_[1],y=_[2],v=_[3],w=r.get(d);if(!w||w.kind!=="struct")return;let k=typeof y=="string"&&y[0]==="$"?h(w,y):parseInt(y);if(k<0)return;let M=w.fields[k],E=u(w,k),z=M.type==="i64"?"i64.load":M.type==="f32"?"f32.load":M.type==="f64"?"f64.load":"i32.load";x[m]=[z,["i32.add",v,["i32.const",E]]]}if(_[0]==="struct.set"){let d=_[1],y=_[2],v=_[3],w=_[4],k=r.get(d);if(!k||k.kind!=="struct")return;let M=typeof y=="string"&&y[0]==="$"?h(k,y):parseInt(y);if(M<0)return;let E=k.fields[M],z=u(k,M),U=E.type==="i64"?"i64.store":E.type==="f32"?"f32.store":E.type==="f64"?"f64.store":"i32.store";x[m]=[U,["i32.add",v,["i32.const",z]],w]}if(_[0]==="array.new"||_[0]==="array.new_default"){let d=_[1],y=r.get(d);if(!y||y.kind!=="array")return;let v=i.get(d),w=lt[y.elemType]||4,k=_[0]==="array.new"?_[2]:null,M=_[0]==="array.new"?_[3]:_[2],E="$__gc_aptr",z="$__gc_alen",U="$__gc_aidx",it=y.elemType==="i64"?"i64.store":y.elemType==="f32"?"f32.store":y.elemType==="f64"?"f64.store":"i32.store",X=[["local.set",z,M],["local.set",E,["call",n,["i32.add",["i32.const",8],["i32.mul",["local.get",z],["i32.const",w]]]]],["i32.store",["local.get",E],["i32.const",v]],["i32.store",["i32.add",["local.get",E],["i32.const",4]],["local.get",z]]];k&&X.push(["local.set",U,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",U],["local.get",z]]],[it,["i32.add",["i32.add",["local.get",E],["i32.const",8]],["i32.mul",["local.get",U],["i32.const",w]]],k],["local.set",U,["i32.add",["local.get",U],["i32.const",1]]],["br","$loop"]]]),X.push(["local.get",E]),x[m]=["block",["result","i32"],...X]}if(_[0]==="array.get"){let d=_[1],y=_[2],v=_[3],w=r.get(d);if(!w||w.kind!=="array")return;let k=lt[w.elemType]||4,M=w.elemType==="i64"?"i64.load":w.elemType==="f32"?"f32.load":w.elemType==="f64"?"f64.load":"i32.load";x[m]=[M,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",v,["i32.const",k]]]]}if(_[0]==="array.set"){let d=_[1],y=_[2],v=_[3],w=_[4],k=r.get(d);if(!k||k.kind!=="array")return;let M=lt[k.elemType]||4,E=k.elemType==="i64"?"i64.store":k.elemType==="f32"?"f32.store":k.elemType==="f64"?"f64.store":"i32.store";x[m]=[E,["i32.add",["i32.add",y,["i32.const",8]],["i32.mul",v,["i32.const",M]]],w]}if(_[0]==="array.len"){let d=_[1];x[m]=["i32.load",["i32.add",d,["i32.const",4]]]}}}),t};P.gc=be;var Ae=(t,e)=>{let r=new Map,i=1;return S(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n of s)Array.isArray(n)&&(n[0]==="struct"||n[0]==="array")&&r.set(l,i++)}),r.size&&j(t,(s,l,n)=>{if(!(!Array.isArray(s)||!l)){if(s[0]==="ref.test"){let a=s[1],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=s[2],c=r.get(o);c!==void 0&&(l[n]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(s[0]==="ref.cast"){let a=s[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=s[2],u=r.get(o);if(u!==void 0){let h=R("cast");f?l[n]=["block",["result","i32"],["local",h,"i32"],["local.set",h,c],["if",["i32.and",["i32.ne",["local.get",h],["i32.const",0]],["i32.ne",["i32.load",["local.get",h]],["i32.const",u]]],["then",["unreachable"]]],["local.get",h]]:l[n]=["block",["result","i32"],["local",h,"i32"],["local.set",h,c],["if",["i32.or",["i32.eqz",["local.get",h]],["i32.ne",["i32.load",["local.get",h]],["i32.const",u]]],["then",["unreachable"]]],["local.get",h]]}}if(s[0]==="br_on_cast"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let h=r.get(u);if(h!==void 0){let p=R("brcast");l[n]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["br_if",a,["i32.and",["i32.ne",["local.get",p],["i32.const",0]],["i32.eq",["i32.load",["local.get",p]],["i32.const",h]]]],["local.get",p]]}}if(s[0]==="br_on_cast_fail"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let h=r.get(u);if(h!==void 0){let p=R("brfail");l[n]=["block",["result","i32"],["local",p,"i32"],["local.set",p,c],["br_if",a,["i32.or",["i32.eqz",["local.get",p]],["i32.ne",["i32.load",["local.get",p]],["i32.const",h]]]],["local.get",p]]}}}}),t};P.ref_cast=Ae;function gt(t,e=!0){typeof t=="string"&&(t=D(t)),t=Dt(t),e=fe(e);let r=oe(t),i={uid:0};for(let s of wt)r.has(s)&&e[s]!==!1&&P[s]&&(t=P[s](t,i));return t}var $t={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0},vt=Object.keys($t),we=t=>{if(t===!0)return{...$t};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&vt.includes([...e][0])?Object.fromEntries(vt.map(r=>[r,e.has(r)])):Object.fromEntries(vt.map(r=>[r,e.has(r)||e.has("all")]))}return{...$t,...t}},F=t=>Array.isArray(t)?t.map(F):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)},K=(t,e,r,i)=>{if(Array.isArray(t))for(let l=0;l<t.length;l++){let n=K(t[l],e,t,l);n!==void 0&&(t[l]=n)}let s=e(t,r,i);return s!==void 0?s:t},ve=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,l=new Map,n=[],a=[],o=0,f=0,c=0,u=0,h=0,p=0;for(let m of t.slice(1)){if(!Array.isArray(m))continue;let d=m[0];if(d==="type"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:c;i.set(y,{node:m,idx:c,used:!1}),typeof y=="string"&&i.set(c,i.get(y)),c++}else if(d==="func"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:o,v=m.some(w=>Array.isArray(w)&&w[0]==="export");e.set(y,{node:m,idx:o,used:v}),typeof y=="string"&&e.set(o,e.get(y)),o++}else if(d==="global"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:f,v=m.some(w=>Array.isArray(w)&&w[0]==="export");r.set(y,{node:m,idx:f,used:v}),typeof y=="string"&&r.set(f,r.get(y)),f++}else if(d==="table"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:u,v=m.some(w=>Array.isArray(w)&&w[0]==="export");s.set(y,{node:m,idx:u,used:v}),typeof y=="string"&&s.set(u,s.get(y)),u++}else if(d==="memory"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:h,v=m.some(w=>Array.isArray(w)&&w[0]==="export");l.set(y,{node:m,idx:h,used:v}),typeof y=="string"&&l.set(h,l.get(y)),h++}else if(d==="import"){for(let y of m)if(Array.isArray(y)&&y[0]==="func"){let v=typeof y[1]=="string"&&y[1][0]==="$"?y[1]:p;e.set(v,{node:m,idx:p,used:!0,isImport:!0}),typeof v=="string"&&e.set(p,e.get(v)),p++,o++}}else d==="export"?n.push(m):d==="start"&&a.push(m)}for(let m of n)for(let d of m){if(!Array.isArray(d))continue;let[y,v]=d;y==="func"&&e.has(v)?e.get(v).used=!0:y==="global"&&r.has(v)?r.get(v).used=!0:y==="table"&&s.has(v)?s.get(v).used=!0:y==="memory"&&l.has(v)&&(l.get(v).used=!0)}for(let m of a){let d=m[1];typeof d=="string"&&d[0]!=="$"&&(d=+d),e.has(d)&&(e.get(d).used=!0)}let b=n.length>0||a.length>0;if(!b){for(let[,m]of e)if(m.used){b=!0;break}if(!b){for(let[,m]of r)if(m.used){b=!0;break}}if(!b){for(let[,m]of s)if(m.used){b=!0;break}}if(!b){for(let[,m]of l)if(m.used){b=!0;break}}}if(!b){for(let[,m]of e)m.used=!0;for(let[,m]of r)m.used=!0;for(let[,m]of s)m.used=!0;for(let[,m]of l)m.used=!0}for(let m of t.slice(1))!Array.isArray(m)||m[0]!=="elem"||G(m,d=>{if(Array.isArray(d)&&d[0]==="ref.func"){let y=d[1];e.has(y)&&(e.get(y).used=!0)}typeof d=="string"&&d[0]==="$"&&e.has(d)&&(e.get(d).used=!0)});let _=!0;for(;_;){_=!1;for(let[,m]of e)!m.used||m.isImport||G(m.node,d=>{if(!Array.isArray(d)){typeof d=="string"&&d[0]==="$"&&e.has(d)&&!e.get(d).used&&(e.get(d).used=!0,_=!0);return}let[y,v]=d;if((y==="call"||y==="return_call"||y==="ref.func")&&e.has(v)&&!e.get(v).used&&(e.get(v).used=!0,_=!0),(y==="global.get"||y==="global.set")&&r.has(v)&&!r.get(v).used&&(r.get(v).used=!0,_=!0),y==="call_indirect"||y==="return_call_indirect")for(let w of d)typeof w=="string"&&w[0]==="$"&&s.has(w)&&!s.get(w).used&&(s.get(w).used=!0,_=!0);y==="type"&&i.has(v)&&!i.get(v).used&&(i.get(v).used=!0,_=!0)})}let x=["module"];for(let m of t.slice(1)){if(!Array.isArray(m)){x.push(m);continue}let d=m[0];if(d==="func"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(y?e.get(y):[...e.values()].find(w=>w.node===m))?.used&&x.push(m)}else if(d==="global"){let y=typeof m[1]=="string"&&m[1][0]==="$"?m[1]:null;(y?r.get(y):[...r.values()].find(w=>w.node===m))?.used&&x.push(m)}else x.push(m)}return x},$e={"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":(t,e)=>t===e?1:0,"i32.ne":(t,e)=>t!==e?1:0,"i32.lt_s":(t,e)=>t<e?1:0,"i32.lt_u":(t,e)=>t>>>0<e>>>0?1:0,"i32.gt_s":(t,e)=>t>e?1:0,"i32.gt_u":(t,e)=>t>>>0>e>>>0?1:0,"i32.le_s":(t,e)=>t<=e?1:0,"i32.le_u":(t,e)=>t>>>0<=e>>>0?1:0,"i32.ge_s":(t,e)=>t>=e?1:0,"i32.ge_u":(t,e)=>t>>>0>=e>>>0?1:0,"i32.eqz":t=>t===0?1:0,"i32.clz":t=>Math.clz32(t),"i32.ctz":t=>t===0?32:31-Math.clz32(t&-t),"i32.popcnt":t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32.wrap_i64":t=>Number(BigInt.asIntN(32,t)),"i64.add":(t,e)=>BigInt.asIntN(64,t+e),"i64.sub":(t,e)=>BigInt.asIntN(64,t-e),"i64.mul":(t,e)=>BigInt.asIntN(64,t*e),"i64.div_s":(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64.div_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64.rem_s":(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64.rem_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64.and":(t,e)=>BigInt.asIntN(64,t&e),"i64.or":(t,e)=>BigInt.asIntN(64,t|e),"i64.xor":(t,e)=>BigInt.asIntN(64,t^e),"i64.shl":(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64.shr_s":(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64.shr_u":(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64.eq":(t,e)=>t===e?1:0,"i64.ne":(t,e)=>t!==e?1:0,"i64.lt_s":(t,e)=>t<e?1:0,"i64.lt_u":(t,e)=>BigInt.asUintN(64,t)<BigInt.asUintN(64,e)?1:0,"i64.gt_s":(t,e)=>t>e?1:0,"i64.gt_u":(t,e)=>BigInt.asUintN(64,t)>BigInt.asUintN(64,e)?1:0,"i64.le_s":(t,e)=>t<=e?1:0,"i64.le_u":(t,e)=>BigInt.asUintN(64,t)<=BigInt.asUintN(64,e)?1:0,"i64.ge_s":(t,e)=>t>=e?1:0,"i64.ge_u":(t,e)=>BigInt.asUintN(64,t)>=BigInt.asUintN(64,e)?1:0,"i64.eqz":t=>t===0n?1:0,"i64.extend_i32_s":t=>BigInt(t),"i64.extend_i32_u":t=>BigInt(t>>>0),"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(Math.round(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":t=>Math.abs(t),"f64.sqrt":t=>Math.sqrt(t),"f64.ceil":t=>Math.ceil(t),"f64.floor":t=>Math.floor(t),"f64.trunc":t=>Math.trunc(t),"f64.nearest":t=>Math.round(t)},$=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;return e==="i32.const"?{type:"i32",value:Number(r)|0}:e==="i64.const"?{type:"i64",value:BigInt(r)}:e==="f32.const"?{type:"f32",value:Math.fround(Number(r))}:e==="f64.const"?{type:"f64",value:Number(r)}:null},Pt=(t,e)=>t==="i32"?["i32.const",e|0]:t==="i64"?["i64.const",e]:t==="f32"?["f32.const",Math.fround(e)]:t==="f64"?["f64.const",e]:null,Ie=t=>K(F(t),e=>{if(!Array.isArray(e))return;let r=e[0],i=$e[r];if(i){if(i.length===1&&e.length===2){let s=$(e[1]);if(!s)return;let l=i(s.value);if(l===null)return;let n=r.startsWith("i64.")&&!r.includes("eqz")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Pt(n,l)}if(i.length===2&&e.length===3){let s=$(e[1]),l=$(e[2]);if(!s||!l)return;let n=i(s.value,l.value);if(n===null)return;let o=/\.(eq|ne|[lg][te])/.test(r)?"i32":r.startsWith("i64.")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Pt(o,n)}}}),ke={"i32.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.sub":(t,e)=>$(e)?.value===0?t:null,"i64.sub":(t,e)=>$(e)?.value===0n?t:null,"i32.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1?e:i?.value===1?t:null},"i64.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1n?e:i?.value===1n?t:null},"i32.div_s":(t,e)=>$(e)?.value===1?t:null,"i32.div_u":(t,e)=>$(e)?.value===1?t:null,"i64.div_s":(t,e)=>$(e)?.value===1n?t:null,"i64.div_u":(t,e)=>$(e)?.value===1n?t:null,"i32.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1?e:i?.value===-1?t:null},"i64.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1n?e:i?.value===-1n?t:null},"i32.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.shl":(t,e)=>$(e)?.value===0?t:null,"i32.shr_s":(t,e)=>$(e)?.value===0?t:null,"i32.shr_u":(t,e)=>$(e)?.value===0?t:null,"i64.shl":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_s":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_u":(t,e)=>$(e)?.value===0n?t:null},Ne=t=>K(F(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=ke[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Be=t=>K(F(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1)){let a=Math.log2(l.value);if(Number.isInteger(a))return["i32.shl",i,["i32.const",a]]}let n=$(i);if(n&&n.value>0&&!(n.value&n.value-1)){let a=Math.log2(n.value);if(Number.isInteger(a))return["i32.shl",s,["i32.const",a]]}}if(r==="i64.mul"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let a=BigInt(l.value.toString(2).length-1);return["i64.shl",i,["i64.const",a]]}let n=$(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let a=BigInt(n.value.toString(2).length-1);return["i64.shl",s,["i64.const",a]]}}if(r==="i32.div_u"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1)){let n=Math.log2(l.value);if(Number.isInteger(n))return["i32.shr_u",i,["i32.const",n]]}}if(r==="i64.div_u"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let n=BigInt(l.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",n]]}}if(r==="i32.rem_u"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1))return["i32.and",i,["i32.const",l.value-1]]}if(r==="i64.rem_u"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n)return["i64.and",i,["i64.const",l.value-1n]]}}),Me=t=>K(F(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let i=1;for(;i<e.length;){let o=e[i];if(Array.isArray(o)&&(o[0]==="then"||o[0]==="else"||o[0]==="result"||o[0]==="param")){i++;continue}break}let s=e[i],l=$(s);if(!l)return;let n=null,a=null;for(let o=i+1;o<e.length;o++){let f=e[o];Array.isArray(f)&&(f[0]==="then"?n=f:f[0]==="else"&&(a=f))}if(l.value!==0&&l.value!==0n){if(n&&n.length>1){let o=n.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}else{if(a&&a.length>1){let o=a.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=$(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=$(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),jt=new Set(["unreachable","return","br","br_table"]),ze=t=>{let e=F(t);return G(e,r=>{if(!Array.isArray(r))return;let i=r[0];if((i==="func"||i==="block"||i==="loop")&&Rt(r),i==="if")for(let s=1;s<r.length;s++)Array.isArray(r[s])&&(r[s][0]==="then"||r[s][0]==="else")&&Rt(r[s])}),e},Rt=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let l=s[0];if(l==="param"||l==="result"||l==="local"||l==="type"||l==="export")continue;e&&r===-1&&(r=i),jt.has(l)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),jt.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},Ue=t=>{let e=F(t);return G(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=[],s=new Map,l=new Set;for(let n=1;n<r.length;n++){let a=r[n];Array.isArray(a)&&(a[0]==="local"&&(i.push({idx:n,node:a}),typeof a[1]=="string"&&a[1][0]==="$"&&s.set(a[1],a[2])),a[0]==="param"&&typeof a[1]=="string"&&a[1][0]==="$"&&(s.set(a[1],a[2]),l.add(a[1])))}G(r,n=>{if(!Array.isArray(n))return;let a=n[0];if(a==="local.get"||a==="local.set"||a==="local.tee"){let o=n[1];typeof o=="string"&&l.add(o)}});for(let n=i.length-1;n>=0;n--){let{idx:a,node:o}=i[n],f=typeof o[1]=="string"&&o[1][0]==="$"?o[1]:null;f&&!l.has(f)&&r.splice(a,1)}}),e},Te=t=>{let e=F(t);return G(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=new Map;((l,n=1)=>{for(let a=n;a<l.length;a++){let o=l[a];if(!Array.isArray(o))continue;let f=o[0];if(f==="local.set"&&o.length===3){let c=o[1],u=o[2];$(u)&&typeof c=="string"?i.set(c,u):typeof c=="string"&&i.delete(c)}else if(f==="local.tee"&&o.length===3){let c=o[1],u=o[2];$(u)&&typeof c=="string"?i.set(c,u):typeof c=="string"&&i.delete(c)}else if(f==="local.get"&&o.length===2){let c=o[1];if(typeof c=="string"&&i.has(c)){let u=i.get(c);o.length=0,o.push(...F(u))}}else(f==="block"||f==="loop"||f==="if"||f==="call"||f==="call_indirect")&&i.clear();K(o,c=>{if(!Array.isArray(c)||c[0]!=="local.get"||c.length!==2)return;let u=c[1];if(typeof u=="string"&&i.has(u)){let h=i.get(u);return F(h)}})}})(r)}),e},Ee=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=F(t),r=new Map;for(let i of e.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 l=[],n=[],a=!1,o=!1;for(let f=1;f<i.length;f++){let c=i[f];if(Array.isArray(c))if(c[0]==="param")if(typeof c[1]=="string"&&c[1][0]==="$")l.push({name:c[1],type:c[2]});else{l=null;break}else c[0]==="local"?a=!0:c[0]==="export"?o=!0:c[0]!=="result"&&c[0]!=="type"&&n.push(c)}if(l&&!a&&!o&&l.length<=2&&n.length===1){let f=new Set(l.map(u=>u.name)),c=!1;G(n[0],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&f.has(u[1])&&(c=!0)}),c||r.set(s,{body:n[0],params:l})}}return r.size===0||K(e,i=>{if(!Array.isArray(i)||i[0]!=="call")return;let s=i[1];if(!r.has(s))return;let{body:l,params:n}=r.get(s),a=i.slice(2);if(n.length===0)return F(l);let o=F(l);return K(o,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let c=f[1],u=n.findIndex(h=>h.name===c);if(u!==-1&&a[u])return F(a[u])}),o}),e};function xt(t,e=!0){return typeof t=="string"&&(t=D(t)),t=F(t),e=we(e),e.fold&&(t=Ie(t)),e.identity&&(t=Ne(t)),e.strength&&(t=Be(t)),e.branch&&(t=Me(t)),e.propagate&&(t=Te(t)),e.inline&&(t=Ee(t)),e.deadcode&&(t=ze(t)),e.locals&&(t=Ue(t)),e.treeshake&&(t=ve(t)),t}var Vt="\uE000",Ht=t=>{if(!t||typeof t!="string")return null;let e=t.split(".")[0];return/^[if](32|64)|v128/.test(e)?e:/\.(eq|ne|[lg][te]|eqz)/.test(t)||t==="memory.size"||t==="memory.grow"?"i32":null},qe=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return Ht(r)?Ht(r):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 It(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=It(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function Se(t,e){let r=[],i=new Map;return It(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let l=s[1];if(!i.has(l)){let a=[];for(let c=2;c<s.length;c++){let u=qe(s[c]);u&&a.push(u)}let o=r.length,f=l.name||`$fn${o}`;i.set(l,{idx:o,name:f.startsWith("$")?f:"$"+f,params:a,fn:l}),r.push(i.get(l))}let n=i.get(l);s[1]=n.name}return s}),r}function Oe(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function Fe(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!(e[e.length-1]instanceof Uint8Array)&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let f=0;f<e.length;f++)i+=Vt+t[f+1];let s=D(i),l=[],n=0;s=It(s,f=>{if(f===Vt){let c=e[n++];if(typeof c=="function")return l.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let u=D(c);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return c instanceof Uint8Array?[...c]:c}return f});let a=null;if(l.length){let f=Se(s,l);if(f.length){let c=Oe(f);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),a={env:{}};for(let u of f)a.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=gt(s,r.polyfill)),r.optimize&&(s=xt(s,r.optimize));let o=rt(s);return a&&(o._imports=a),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?D(t):t;return r.polyfill&&(i=gt(i,r.polyfill)),r.optimize&&(i=xt(i,r.optimize)),rt(i)}return rt(t)}function We(t,...e){let r=Fe(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var fr=We;export{Fe as compile,fr as default,xt as optimize,D as parse,gt as polyfill,Ft as print,We as watr};
1
+ var re=Object.defineProperty;var ie=(t,e)=>{for(var r in e)re(t,r,{get:e[r],enumerable:!0})};var at={};ie(at,{f32:()=>Q,f64:()=>X,i16:()=>fe,i32:()=>F,i64:()=>Z,i8:()=>ae,uleb:()=>x,uleb5:()=>ne,v128:()=>bt});var I=(t,e=I.loc)=>{if(e!=null&&I.src){let r=1,i=1;for(let s=0;s<e&&s<I.src.length;s++)I.src[s]===`
2
+ `?(r++,i=1):i++;t+=` at ${r}:${i}`}throw Error(t)};var Tt=/^_|_$|[^\da-f]_|_[^\da-f]/i,Et=/^[+-]?(?:0x[\da-f]+|\d+)$/i,se=new TextEncoder,le=new TextDecoder("utf-8",{fatal:!0,ignoreBOM:!0}),zt={n:10,r:13,t:9,'"':34,"'":39,"\\":92},nt=t=>{let e=[],r=1,i,s,l="",n=()=>(l&&e.push(...se.encode(l)),l="");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++):zt[t[r]]?i=zt[t[r++]]:isNaN(i=parseInt(t[r]+t[r+1],16))?s+=t[r]:(r++,r++)),i!=null?(n(),e.push(i)):l+=s;return n(),e.valueOf=()=>t,e},Ut=t=>le.decode(new Uint8Array(nt(t)));var x=(t,e=[])=>{if(t==null)return e;if(typeof t=="string"&&(t=/[_x]/i.test(t)?BigInt(t.replaceAll("_","")):F.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),x(t,e))};function ne(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 F(t,e=[]){for(typeof t=="string"&&(t=F.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 St=t=>!Tt.test(t)&&Et.test(t=t.replaceAll("_",""))?t:I(`Bad int ${t}`),ae=F,fe=F;F.parse=t=>(t=parseInt(St(t)),(t<-2147483648||t>4294967295)&&I("i32 constant out of range"),t);function Z(t,e=[]){for(typeof t=="string"?t=Z.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 it=new ArrayBuffer(8),L=new Uint8Array(it),oe=new Int32Array(it),ce=new Float32Array(it),ue=new Float64Array(it),dt=new BigInt64Array(it);Z.parse=t=>(t=St(t),t=t[0]==="-"?-BigInt(t.slice(1)):BigInt(t),(t<-0x8000000000000000n||t>0xffffffffffffffffn)&&I("i64 constant out of range"),dt[0]=t,dt[0]);var me=2147483648,_e=2139095040;function Q(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=F.parse(t.slice(r+4)),e|=_e,t[0]==="-"&&(e|=me),oe[0]=e):(e=typeof t=="string"?Q.parse(t):t,ce[0]=e),[L[0],L[1],L[2],L[3]]}var pe=0x8000000000000000n,ye=0x7ff0000000000000n;function X(t,e,r){return typeof t=="string"&&~(r=t.indexOf("nan:"))?(e=Z.parse(t.slice(r+4)),e|=ye,t[0]==="-"&&(e|=pe),dt[0]=e):(e=typeof t=="string"?X.parse(t):t,ue[0]=e),[L[0],L[1],L[2],L[3],L[4],L[5],L[6],L[7]]}X.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),[l,n=""]=i.split("."),a=n.length??0,o=parseInt(l);isNaN(o)&&I();let f=n?parseInt("0x"+n)/16**a:0;s=parseInt(s,10);let c=r*(o+f)*2**s;return c=Math.max(-e,Math.min(e,c)),c}return t.includes("nan")?r<0?NaN:NaN:t.includes("inf")?r*(1/0):r*parseFloat(t)};Q.parse=t=>X.parse(t,34028234663852886e22);var bt=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.cast 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"],["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"]],B={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},E={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,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},G={func:96,struct:95,array:94,cont:93,sub:80,subfinal:79,rec:78},At={func:0,table:1,memory:2,global:3,tag:4};var C=t=>{let e=0,r=[],i="",s=0,l=0,n=()=>i&&(r.push(i),i=""),a=o=>{r.loc=o;for(let f,c,u;e<t.length;)if(f=t.charCodeAt(e),s===34)i+=t[e++],f===92?i+=t[e++]:f===34&&(n(),s=0);else if(s>59)f===40&&t.charCodeAt(e+1)===59?(s++,i+=t[e++]+t[e++]):f===59&&t.charCodeAt(e+1)===41?(i+=t[e++]+t[e++],--s===59&&(n(),s=0)):i+=t[e++];else if(s<0)f===10||f===13?(i+=t[e++],n(),s=0):s===-2&&f===41?(n(),s=0):i+=t[e++];else if(f===34)i!=="$"&&n(),s=34,i+=t[e++];else if(f===40&&t.charCodeAt(e+1)===59)n(),s=60,i=t[e++]+t[e++];else if(f===59&&t.charCodeAt(e+1)===59)n(),s=t.indexOf(`
3
+ `,e)<0?-2:-1,i=t[e++]+t[e++];else if(f===40&&t.charCodeAt(e+1)===64)n(),u=e,e+=2,i="@",l++,(c=r).push(r=[]),a(u),r=c;else if(f===40)n(),u=e++,l++,(c=r).push(r=[]),a(u),r=c;else{if(f===41)return n(),e++,l--;f<=32?(n(),e++):i+=t[e++]}s<0&&n(),n()};return a(0),s===34&&I("Unclosed quote",e),s>59&&I("Unclosed block comment",e),l>0&&I("Unclosed parenthesis",e),e<t.length&&I("Unexpected closing parenthesis",e),r.length>1?r:r[0]||[]};var Ft=(t,e)=>Array.isArray(t)?t[0]?.[0]==="@"&&t[0]!=="@custom"&&!t[0]?.startsWith?.("@metadata.code.")?null:(e=t.map(Ft).filter(r=>r!=null),e.loc=t.loc,e.length===1&&e[0]?.[0]==="module"?e[0]:e):typeof t!="string"?t:t[0]===";"||t[1]===";"?null:t[0]==="$"&&t[1]==='"'?t.includes("\\")?"$"+Ut(t.slice(1)):"$"+t.slice(2,-1):t[0]==='"'?nt(t):t;function et(t){typeof t=="string"?(I.src=t,t=C(t)||[]):I.src="",I.loc=0,t=Ft(t)||[];let e=0;if(t[0]==="module"?(e++,q(t[e])&&e++):typeof t[0]=="string"&&(t=[t]),t[e]==="binary")return Uint8Array.from(t.slice(++e).flat());if(t[e]==="quote")return et(t.slice(++e).map(u=>u.valueOf().slice(1,-1)).flat().join(""));t=t.flatMap((u,y)=>{if(y<e||!Array.isArray(u)||u[0]!=="import")return[u];let[,m,...h]=u;if(!h.some(d=>Array.isArray(d)&&d[0]==="item"))return[u];if(Array.isArray(h.at(-1))&&h.at(-1)[0]!=="item"){let d=h.at(-1);return h.slice(0,-1).filter(_=>_[0]==="item").map(([,_])=>["import",m,_,d])}return h.filter(d=>d[0]==="item").map(([,d,_])=>["import",m,d,_])});let r=[];for(let u in B)(r[B[u]]=r[u]=[]).name=u;r.metadata={},t.slice(e).filter(u=>{if(!Array.isArray(u)){let h=I.loc,p=I.src,d;for(;(h=p.indexOf(u,h))>=0;){if(d=p.charCodeAt(h-1),h>0&&(d>47&&d<58||d>64&&d<91||d>96&&d<123||d===95||d===36)){h++;continue}if(d=p.charCodeAt(h+u.length),d>47&&d<58||d>64&&d<91||d>96&&d<123||d===95){h++;continue}break}h>=0&&(I.loc=h),I(`Unexpected token ${u}`)}let[y,...m]=u;if(I.loc=u.loc,y==="@custom")r.custom.push(m);else if(y==="rec")for(let h=0;h<m.length;h++){let[,...p]=m[h];wt(p,r.type);let d=[];for(;p[0]?.[0]==="descriptor"||p[0]?.[0]==="describes";)d.push(p.shift());(p=qt(p,r)).push(h?!0:[r.type.length,m.length]),d.length&&(p.desc=p.desc?[...d,...p.desc]:d),r.type.push(p)}else if(y==="type"){wt(m,r.type);let h=[];for(;m[0]?.[0]==="descriptor"||m[0]?.[0]==="describes";)h.push(m.shift());let p=qt(m,r);h.length&&(p.desc=p.desc?[...h,...p.desc]:h),r.type.push(p)}else if(y==="start"||y==="export")r[y].push(m);else return!0}).forEach(u=>{let[y,...m]=u;I.loc=u.loc;let h;y==="import"&&([y,...m]=(h=m).pop());let p=r[y];for(p||I(`Unknown section ${y}`),wt(m,p);m[0]?.[0]==="export";)r.export.push([m.shift()[1],[y,p?.length]]);if(m[0]?.[0]==="import"&&([,...h]=m.shift()),y==="table"){let d=m[0]==="i64",_=d?1:0;if(m[_+1]?.[0]==="elem"){let[b,[,...g]]=[m[_],m[_+1]];m=d?["i64",g.length,g.length,b]:[g.length,g.length,b],r.elem.push([["table",p.length],["offset",[d?"i64.const":"i32.const",d?0n:0]],b,...g])}}else if(y==="memory"){let d=m[0]==="i64",_=d?1:0;if(m[_]?.[0]==="data"){let b=m.find(w=>Array.isArray(w)&&w[0]==="pagesize")?.[1]??65536,[,...g]=m.splice(_,1)[0],v=""+Math.ceil(g.reduce((w,k)=>w+k.length,0)/b);r.data.push([["memory",p.length],[d?"i64.const":"i32.const",d?0n:0],...g]),m=d?["i64",v,v]:[v,v]}}else if(y==="func"){let[d,_,b]=yt(m,r);d??=_t(_,b,r),!h&&r.code.push([[d,_,b],...Y(m,r)]),m=[["type",d]]}else if(y==="tag"){let[d,_]=yt(m,r);d??=_t(_,[],r),m=[["type",d]]}h&&(r.import.push([...h,[y,...m]]),m=null),p.push(m)});let i=(u,y=!0)=>{let m=r[u].filter(Boolean).map(h=>Wt[u](h,r)).filter(Boolean);return u===B.custom?m.flatMap(h=>[u,...N(h)]):m.length?[u,...N(y?N(m):m)]:[]},s=()=>{let u=[];for(let y in r.metadata){let m=N(nt(`"metadata.code.${y}"`)),h=N(r.metadata[y].map(([p,d])=>[...x(p),...N(d.map(([_,b])=>[...x(_),...N(b)]))]));u.push(0,...N([...m,...h]))}return u},l=i(B.global),n=i(B.elem),a=i(B.code),o=s(),f=i(B.data),c=r.strings.length?[B.strings,...N([0,...N(r.strings.map(u=>N(u)))])]:[];return Uint8Array.from([0,97,115,109,1,0,0,0,...i(B.custom),...i(B.type),...i(B.import),...i(B.func),...i(B.table),...i(B.memory),...i(B.tag),...c,...l,...i(B.export),...i(B.start,!1),...n,...i(B.datacount,!1),...a,...o,...f])}var D=t=>t?.[0]==="$"||!isNaN(t),q=t=>t?.[0]==="$",vt=t=>t?.[0]==="a"||t?.[0]==="o";function Y(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")q(t[0])&&r.push(t.shift()),r.push(ft(t,e));else if(i==="else"||i==="end")q(t[0])&&t.shift();else if(i==="select")r.push(pt(t)[1]);else if(i.endsWith("call_indirect")){let s=D(t[0])?t.shift():0,[l,n,a]=yt(t,e);r.push(s,["type",l??_t(n,a,e)])}else i==="table.init"?r.push(D(t[1])?t.shift():0,t.shift()):i==="table.copy"||i==="memory.copy"?r.push(D(t[0])?t.shift():0,D(t[0])?t.shift():0):i.startsWith("table.")?r.push(D(t[0])?t.shift():0):i==="memory.init"?(r.push(...D(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"))&&D(t[0])&&r.push(t.shift());else if(Array.isArray(i)){let s=i[0];if(i.loc!=null&&(I.loc=i.loc),s?.startsWith?.("@metadata.code.")){let n=s.slice(15);r.push(["@metadata",n,i[1]]);continue}if(typeof s!="string"||!Array.isArray(st[s])){r.push(i);continue}let l=i.slice(1);if(s==="block"||s==="loop")r.push(s),q(l[0])&&r.push(l.shift()),r.push(ft(l,e),...Y(l,e),"end");else if(s==="if"){let n=[],a=[];l.at(-1)?.[0]==="else"&&(a=Y(l.pop().slice(1),e)),l.at(-1)?.[0]==="then"&&(n=Y(l.pop().slice(1),e));let o=[s];q(l[0])&&o.push(l.shift()),o.push(ft(l,e)),r.push(...Y(l,e),...o,...n),a.length&&r.push("else",...a),r.push("end")}else if(s==="try_table"){for(r.push(s),q(l[0])&&r.push(l.shift()),r.push(ft(l,e));l[0]?.[0]==="catch"||l[0]?.[0]==="catch_ref"||l[0]?.[0]==="catch_all"||l[0]?.[0]==="catch_all_ref";)r.push(l.shift());r.push(...Y(l,e),"end")}else{let n=[];for(;l.length&&(!Array.isArray(l[0])||l[0].valueOf!==Array.prototype.valueOf||"type,param,result,ref,exact,on".includes(l[0][0]));)n.push(l.shift());r.push(...Y(l,e),s,...n),t.unshift(...r.splice(r.length-1-n.length))}}else r.push(i)}return r}var _t=(t,e,r,i="$"+t+">"+e)=>(r.type[i]??=r.type.push(["func",[t,e]])-1,i),$t=(t,e)=>{let r=[];for(;t[0]?.[0]===e;){let[,...i]=t.shift(),s=q(i[0])&&i.shift();s&&(s in r?(()=>{throw Error(`Duplicate ${e} ${s}`)})():r[s]=r.length),r.push(...i)}return r},pt=t=>{let e=$t(t,"param"),r=$t(t,"result");if(t[0]?.[0]==="param")throw Error("Unexpected param");return[e,r]},yt=(t,e)=>{if(t[0]?.[0]!=="type")return[,...pt(t)];let[,r]=t.shift(),[i,s]=pt(t),l=e.type[typeof r=="string"&&isNaN(r)?e.type[r]:+r];if(!l)throw Error(`Unknown type ${r}`);if((i.length||s.length)&&l[1].join(">")!==i+">"+s)throw Error(`Type ${r} mismatch`);return[r,...l[1]]},ft=(t,e)=>{let[r,i,s]=yt(t,e);if(!(!i.length&&!s.length))return!i.length&&s.length===1?["result",...s]:["type",r??_t(i,s,e)]},wt=(t,e)=>{let r=q(t[0])&&t.shift();return r&&(r in e?I(`Duplicate ${e.name} ${r}`):e[r]=e.length),r},qt=([t],e)=>{let r="subfinal",i=[],s,l=[];t[0]==="sub"&&(r=t.shift(),t[0]==="final"&&(r+=t.shift()),t=(i=t).pop(),i=i.filter(a=>Array.isArray(a)&&(a[0]==="descriptor"||a[0]==="describes")?(l.push(a),!1):!0)),[s,...t]=t,s==="func"?(t=pt(t),e.type["$"+t.join(">")]??=e.type.length):s==="struct"?t=$t(t,"field"):s==="array"&&([t]=t);let n=[s,t,r,i];return l.length&&(n.desc=l),n},Wt=[([t,...e],r)=>{let i=e;return(e[0]?.[0]==="before"||e[0]?.[0]==="after")&&(i=e.slice(1)),[...N(t),...i.flat()]},(t,e)=>{let[r,i,s,l,n]=t;if(n===!0)return;let a=(t.desc??[]).flatMap(([f,c])=>[f==="descriptor"?77:76,...x(A(c,e.type))]),o=(f,c)=>f==="func"?[G.func,...N(c[0].map(u=>W(u,e))),...N(c[1].map(u=>W(u,e)))]:f==="array"?[G.array,...ot(c,e)]:f==="struct"?[G.struct,...N(c.map(u=>ot(u,e)))]:f==="cont"?[G.cont,...x(A(c[0]??c,e.type))]:[G[f]];if(n){let[f,c]=n,u=Array.from({length:c},(y,m)=>{let h=e.type[f+m],p=h.slice(0,4);return h.desc&&(p.desc=h.desc),Wt[B.type](p,e)});return[G.rec,...N(u)]}else if(s==="sub"||l?.length)return[G[s],...N(l.map(f=>A(f,e.type))),...a,...o(r,i)];return[...a,...o(r,i)]},([t,e,[r,...i]],s)=>{let l,n=At[r];if(r==="func"){i[0]==="exact"&&i.shift()&&(n=32);let[[,o]]=i;l=x(A(o,s.type))}else if(r==="tag"){let[[,a]]=i;l=[0,...x(A(a,s.type))]}else r==="memory"?l=ct(i):r==="global"?l=ot(i[0],s):r==="table"?l=[...W(i.pop(),s),...ct(i)]:I(`Unknown kind ${r}`);return[...N(t),...N(e),n,...l]},([[,t]],e)=>x(A(t,e.type)),(t,e)=>{let r=ct(t),i=W(t.shift(),e),[s]=t;return s?[64,0,...i,...r,...tt(s,e)]:[...i,...r]},(t,e)=>ct(t),([t,e],r)=>[...ot(t,r),...tt(e,r)],([t,[e,r]],i)=>[...N(t),At[e],...x(A(r,i[e]))],([t],e)=>x(A(t,e.func)),(t,e)=>{let r=0,i=0,s=0,l=0,n,a,o;t[0]==="declare"&&(t.shift(),i=1),t[0]?.[0]==="table"?([,n]=t.shift(),n=A(n,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"))&&(n=A(t.shift(),e.table)),t[0]?.[0]==="offset"||Array.isArray(t[0])&&t[0][0]!=="item"&&!t[0][0].startsWith("ref")?(a=t.shift(),a[0]==="offset"&&([,a]=a),a=tt(a,e)):i||(r=1),E[t[0]]||t[0]?.[0]==="ref"?o=W(t.shift(),e):t[0]==="func"?o=[E[t.shift()]]:o=[E.func],t=t.map(c=>(c[0]==="item"&&(c=c.length===3&&c[1]==="ref.func"?c[2]:c[1]),c[0]==="ref.func"&&([,c]=c),typeof c!="string"&&(s=1),c)),o[0]!==E.funcref&&(l=1,s=1);let f=s<<2|(r||i?i:!!n||l)<<1|(r||i);return[f,...f===0?a:f===1?[0]:f===2?[...x(n||0),...a,0]:f===3?[0]:f===4?a:f===5?o:f===6?[...x(n||0),...a,...o]:o,...N(t.map(s?c=>tt(typeof c=="string"?["ref.func",c]:c,e):c=>x(A(c,e.func))))]},(t,e)=>{let[r,i]=t.shift();i||([,[i]]=e.type[A(r,e.type)]),e.local=Object.create(i),e.block=[],e.local.name="local",e.block.name="block",e._codeIdx===void 0&&(e._codeIdx=0);let s=e._codeIdx++;for(;t[0]?.[0]==="local";){let[,...o]=t.shift();if(q(o[0])){let f=o.shift();f in e.local?I(`Duplicate local ${f}`):e.local[f]=e.local.length}e.local.push(...o)}e.meta={};let l=Ct(t,e),n=e.import.filter(o=>o[2][0]==="func").length+s;for(let o in e.meta)((e.metadata??={})[o]??=[]).push([n,e.meta[o]]);let a=e.local.slice(i.length).reduce((o,f)=>(f==o[o.length-1]?.[1]?o[o.length-1][0]++:o.push([1,f]),o),[]);return e.local=e.block=e.meta=null,N([...N(a.map(([o,f])=>[...x(o),...W(f,e)])),...l])},(t,e)=>{let r,i=0;return t[0]?.[0]==="memory"?([,i]=t.shift(),i=A(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=A(t.shift(),e.memory)),Array.isArray(t[0])&&typeof t[0]?.[0]=="string"&&(r=t.shift(),r[0]==="offset"&&([,r]=r),r??I("Bad offset",r)),[...i?[2,...x(i),...tt(r,e)]:r?[0,...tt(r,e)]:[1],...N(t.flatMap(s=>he(s)??[...s]))]},(t,e)=>x(e.data.length),([[,t]],e)=>[0,...x(A(t,e.type))]],W=(t,e)=>t[0]==="ref"?t[1]=="null"?Array.isArray(t[2])&&t[2][0]==="exact"?[E.refnull,98,...x(A(t[2][1],e.type))]:E[t[2]]?[E[t[2]]]:[E.refnull,...x(A(t[t.length-1],e.type))]:Array.isArray(t[1])&&t[1][0]==="exact"?[E.ref,98,...x(A(t[1][1],e.type))]:[E.ref,...x(E[t[t.length-1]]||A(t[t.length-1],e.type))]:[E[t]??I(`Unknown type ${t}`)],ot=(t,e,r=t[0]==="mut"?1:0)=>[...W(r?t[1]:t,e),r],Lt={null:()=>[],reversed:(t,e)=>{let r=t.shift(),i=t.shift();return[...x(A(i,e.elem)),...x(A(r,e.table))]},block:(t,e)=>{e.block.push(1),q(t[0])&&(e.block[t.shift()]=e.block.length);let r=t.shift();return r?r[0]==="result"?W(r[1],e):x(A(r[1],e.type)):[E.void]},try_table:(t,e)=>{q(t[0])&&(e.block[t.shift()]=e.block.length+1);let r=t.shift(),i=r?r[0]==="result"?W(r[1],e):x(A(r[1],e.type)):[E.void],s=[],l=0;for(;t[0]?.[0]==="catch"||t[0]?.[0]==="catch_ref"||t[0]?.[0]==="catch_all"||t[0]?.[0]==="catch_all_ref";){let n=t.shift(),a=n[0]==="catch"?0:n[0]==="catch_ref"?1:n[0]==="catch_all"?2:3;a<=1?s.push(a,...x(A(n[1],e.tag)),...x(H(n[2],e.block))):s.push(a,...x(H(n[1],e.block))),l++}return e.block.push(1),[...i,...x(l),...s]},end:(t,e)=>(e.block.pop(),[]),call_indirect:(t,e)=>{let r=t.shift(),[,i]=t.shift();return[...x(A(i,e.type)),...x(A(r,e.table))]},br_table:(t,e)=>{let r=[],i=0;for(;t[0]&&(!isNaN(t[0])||q(t[0]));)r.push(...x(H(t.shift(),e.block))),i++;return[...x(i-1),...r]},select:(t,e)=>{let r=t.shift()||[];return r.length?N(r.map(i=>W(i,e))):[]},ref_null:(t,e)=>{let r=t.shift();return Array.isArray(r)&&r[0]==="exact"?[98,...x(A(r[1],e.type))]:E[r]?[E[r]]:x(A(r,e.type))},memarg:(t,e,r)=>Ot(t,r,D(t[0])&&!vt(t[0])?A(t.shift(),e.memory):0),opt_memory:(t,e)=>x(A(D(t[0])?t.shift():0,e.memory)),reftype:(t,e)=>{let r=W(t.shift(),e);return r.length>1?r.slice(1):r},reftype2:(t,e)=>{let r=H(t.shift(),e.block),i=W(t.shift(),e),s=W(t.shift(),e),l=n=>n.length>1?n.slice(1):n;return[(s[0]!==E.ref)<<1|i[0]!==E.ref,...x(r),...l(i),...l(s)]},v128const:t=>{let[e,r]=t.shift().split("x"),i=+e.slice(1),s=i>>>3;if(r=+r,e[0]==="i"){let n=r===16?new Uint8Array(16):r===8?new Uint16Array(8):r===4?new Uint32Array(4):new BigUint64Array(2);for(let a=0;a<r;a++)n[a]=at[e].parse(t.shift());return[...new Uint8Array(n.buffer)]}let l=new Uint8Array(16);for(let n=0;n<r;n++)l.set(at[e](t.shift()),n*s);return[...l]},shuffle:t=>{let e=[];for(let r=0;r<16;r++)e.push(mt(t.shift(),32));return typeof t[0]=="string"&&!isNaN(t[0])&&I("invalid lane length"),e},memlane:(t,e,r)=>{let i=q(t[0])||D(t[0])&&(vt(t[1])||D(t[1]))?A(t.shift(),e.memory):0;return[...Ot(t,r,i),...x(mt(t.shift()))]},"*":t=>x(t.shift()),labelidx:(t,e)=>x(H(t.shift(),e.block)),laneidx:t=>[mt(t.shift(),255)],funcidx:(t,e)=>x(A(t.shift(),e.func)),typeidx:(t,e)=>x(A(t.shift(),e.type)),tableidx:(t,e)=>x(A(t.shift(),e.table)),memoryidx:(t,e)=>x(A(t.shift(),e.memory)),globalidx:(t,e)=>x(A(t.shift(),e.global)),localidx:(t,e)=>x(A(t.shift(),e.local)),dataidx:(t,e)=>x(A(t.shift(),e.data)),elemidx:(t,e)=>x(A(t.shift(),e.elem)),tagidx:(t,e)=>x(A(t.shift(),e.tag)),"memoryidx?":(t,e)=>x(A(D(t[0])?t.shift():0,e.memory)),stringidx:(t,e)=>{let r=t.shift(),i=r.valueOf(),s=e.strings.findIndex(l=>l.valueOf()===i);return s<0&&(s=e.strings.push(r)-1),x(s)},i32:t=>F(t.shift()),i64:t=>Z(t.shift()),f32:t=>Q(t.shift()),f64:t=>X(t.shift()),v128:t=>bt(t.shift()),typeidx_field:(t,e)=>{let r=A(t.shift(),e.type);return[...x(r),...x(A(t.shift(),e.type[r][1]))]},typeidx_multi:(t,e)=>[...x(A(t.shift(),e.type)),...x(t.shift())],typeidx_dataidx:(t,e)=>[...x(A(t.shift(),e.type)),...x(A(t.shift(),e.data))],typeidx_elemidx:(t,e)=>[...x(A(t.shift(),e.type)),...x(A(t.shift(),e.elem))],typeidx_typeidx:(t,e)=>[...x(A(t.shift(),e.type)),...x(A(t.shift(),e.type))],dataidx_memoryidx:(t,e)=>[...x(A(t.shift(),e.data)),...x(A(t.shift(),e.memory))],memoryidx_memoryidx:(t,e)=>[...x(A(t.shift(),e.memory)),...x(A(t.shift(),e.memory))],tableidx_tableidx:(t,e)=>[...x(A(t.shift(),e.table)),...x(A(t.shift(),e.table))],cont_bind:(t,e)=>[...x(A(t.shift(),e.type)),...x(A(t.shift(),e.type))],switch_cont:(t,e)=>[...x(A(t.shift(),e.type)),...x(A(t.shift(),e.tag))],resume:(t,e)=>{let r=x(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...x(A(l,e.tag))):i.push(0,...x(A(l,e.tag)),...x(H(n,e.block))),s++}return[...r,...x(s),...i]},resume_throw:(t,e)=>{let r=x(A(t.shift(),e.type)),i=x(A(t.shift(),e.tag)),s=[],l=0;for(;t[0]?.[0]==="on";){let[,n,a]=t.shift();a==="switch"?s.push(1,...x(A(n,e.tag))):s.push(0,...x(A(n,e.tag)),...x(H(a,e.block))),l++}return[...r,...i,...x(l),...s]},resume_throw_ref:(t,e)=>{let r=x(A(t.shift(),e.type)),i=[],s=0;for(;t[0]?.[0]==="on";){let[,l,n]=t.shift();n==="switch"?i.push(1,...x(A(l,e.tag))):i.push(0,...x(A(l,e.tag)),...x(H(n,e.block))),s++}return[...r,...x(s),...i]}},ut={};(function t(e,r){for(let i=0,s,l,n;i<e.length;i++)(s=e[i])&&(Array.isArray(s)?t(s,i):([l,n]=s.split(" "),st[l]=r?[r,...x(i)]:[i],n&&(ut[l]=Lt[n])))})(st);var Ct=(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&&(I.loc=s.loc),I(`Unknown instruction ${s[0]}`));let[...l]=st[s]||I(`Unknown instruction ${s}`);ut[s]&&(s==="select"&&t[0]?.length?l[0]++:ut[s]===Lt.reftype&&(t[0][1]==="null"||t[0][0]!=="ref")&&l[l.length-1]++,l.push(...ut[s](t,e,s)));for(let[n,a]of i)(e.meta[n]??=[]).push([r.length,a]);r.push(...l)}return r.push(11),r},tt=(t,e)=>Ct(Y([t],e),e),A=(t,e,r)=>(r=q(t)?e[t]:+t,r in e?r:I(`Unknown ${e.name} ${t}`)),H=(t,e,r)=>(r=q(t)?e.length-e[t]:+t,isNaN(r)||r>e.length?I(`Bad label ${t}`):r),ge=t=>{let e,r,i,s;for(;vt(t[0]);)[i,s]=t.shift().split("="),i==="offset"?r=+s:i==="align"?e=+s:I(`Unknown param ${i}=${s}`);return(r<0||r>4294967295)&&I(`Bad offset ${r}`),(e<=0||e>4294967295)&&I(`Bad align ${e}`),e&&(e=Math.log2(e))%1&&I(`Bad align ${e}`),[e,r]},Ot=(t,e,r=0)=>{let[i,s]=ge(t),l=(i??xe(e))|(r&&64);return r?[...x(l),...x(r),...x(s??0)]:[...x(l),...x(s??0)]},xe=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 l=t.slice(e,e+6).match(/\d+/);return Math.log2(l?l[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)},he=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 l of r)e==="i8"?i.push(F.parse(l)&511&255):e==="i16"?(s.setInt16(0,F.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,2))):e==="i32"?(s.setInt32(0,F.parse(l),!0),i.push(...new Uint8Array(s.buffer,0,4))):e==="i64"?(s.setBigInt64(0,BigInt(l),!0),i.push(...new Uint8Array(s.buffer,0,8))):e==="f32"?i.push(...Q(l)):e==="f64"&&i.push(...X(l));return i},ct=t=>{let e=t[0]==="i64"&&t.shift(),r=t[t.length-1]==="shared"&&t.pop(),i=t.findIndex(f=>Array.isArray(f)&&f[0]==="pagesize"),s=-1;i>=0&&(s=Math.log2(+t.splice(i,1)[0][1]));let l=!isNaN(parseInt(t[1])),n=(s>=0?8:0)|(e?4:0)|(r?2:0)|(l?1:0),a=e?f=>{if(typeof f=="bigint")return f;let c=typeof f=="string"?f.replaceAll("_",""):String(f);return BigInt(c)}:mt,o=s>=0?x(s):[];return l?[n,...x(a(t.shift())),...x(a(t.shift())),...o]:[n,...x(a(t.shift())),...o]},mt=(t,e=4294967295)=>{let r=typeof t=="string"&&t[0]!=="+"?F.parse(t):typeof t=="number"?t:I(`Bad int ${t}`);return r>e?I(`Value out of range ${t}`):r},N=t=>[...x(t.length),...t.flat()];function Dt(t,e={}){typeof t=="string"&&(t=C(t));let{indent:r=" ",newline:i=`
4
+ `,comments:s=!0}=e;if(r||="",i||="",typeof t[0]=="string"&&t[0][0]!==";")return n(t);return t.filter(a=>s||!l(a)).map(a=>n(a)).join(i);function l(a){return typeof a=="string"&&a[1]===";"}function n(a,o=0){if(!Array.isArray(a))return a;let f=a[0];if(!f)return"";let c=!1;if(f==="try_table"){let m=1;for(typeof a[m]=="string"&&a[m][0]==="$"&&(f+=" "+a[m++]),Array.isArray(a[m])&&(a[m][0]==="result"||a[m][0]==="type")&&(f+=" "+n(a[m++],o));Array.isArray(a[m])&&/^catch/.test(a[m][0]);)f+=" "+n(a[m++],o).trim();for(;m<a.length;m++)f+=Array.isArray(a[m])?i+r.repeat(o+1)+n(a[m],o+1):" "+a[m];return`(${f+i+r.repeat(o)})`}let u=!!i&&a.length<4&&!a.some(m=>typeof m=="string"&&m[0]===";"&&m[1]===";"),y=r.repeat(o+1);for(let m=1;m<a.length;m++){let h=a[m].valueOf();if(typeof h=="string"&&h[1]===";"){if(!s)continue;if(h[0]===";")if(i)f+=i+y+h.trimEnd(),c=!0;else{let p=f[f.length-1];p&&p!==" "&&p!=="("&&(f+=" "),f+=h.trimEnd()+`
5
+ `}else{let p=f[f.length-1];p&&p!==" "&&p!=="("&&(f+=" "),f+=h.trimEnd()}}else if(Array.isArray(h))u&&(u=h.every(p=>!Array.isArray(p))),f+=i+y+n(h,o+1),c=!1;else if(a[0]==="data")u=!1,(i||f[f.length-1]!==")")&&(f+=i||" "),f+=y+h,c=!1;else{let p=f[f.length-1];c&&i?f+=i+y:p===`
6
+ `?f+="":(p&&p!==")"&&p!==" "||i||p===")")&&(f+=" "),f+=h,c=!1}}return u?`(${f.replaceAll(i+y+"("," (")})`:`(${f+i+r.repeat(o)})`}}var jt={funcref:["ref.func","call_ref","return_call_ref"],sign_ext:["i32.extend8_s","i32.extend16_s","i64.extend8_s","i64.extend16_s","i64.extend32_s"],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"],bulk_memory:["memory.copy","memory.fill"],return_call:["return_call","return_call_indirect"],i31ref:["ref.i31","i31.get_s","i31.get_u"],extended_const:["global.get"],multi_value:[],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"],ref_cast:["ref.test","ref.cast","br_on_cast","br_on_cast_fail"]},It=Object.keys(jt),de=t=>{if(t===!0)return Object.fromEntries(It.map(e=>[e,!0]));if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return Object.fromEntries(It.map(r=>[r,e.has(r)||e.has("all")]))}return{...t}},S=(t,e,r,i)=>{if(e(t,r,i),Array.isArray(t))for(let s=0;s<t.length;s++)S(t[s],e,t,s)},j=(t,e,r,i)=>{if(Array.isArray(t))for(let s=0;s<t.length;s++)j(t[s],e,t,s);e(t,r,i)},be=t=>{let e=new Set;return S(t,r=>{if(typeof r=="string")for(let[i,s]of Object.entries(jt))s.some(l=>r===l||r.startsWith(l+" "))&&e.add(i)}),S(t,r=>{if(!(!Array.isArray(r)||r[0]!=="global"))for(let i of r)Array.isArray(i)&&(i[0]==="i32.add"||i[0]==="i32.sub"||i[0]==="i32.mul"||i[0]==="i64.add"||i[0]==="i64.sub"||i[0]==="i64.mul")&&S(i,s=>{Array.isArray(s)&&s[0]==="global.get"&&e.add("extended_const")})}),S(t,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=0;for(let s of r)Array.isArray(s)&&s[0]==="result"&&(i+=s.length-1);i>1&&e.add("multi_value")}),e},Rt=t=>Array.isArray(t)?t.map(Rt):t,Vt=(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},gt=(t,e,r)=>t.splice(e,0,r),Ae=0,R=t=>`$__${t}${Ae++}`,we=(t,e)=>{let r=new Set;if(S(t,f=>{Array.isArray(f)&&f[0]==="ref.func"&&r.add(f[1])}),!r.size)return t;let i=R("fntbl"),s=[...r],l=Object.fromEntries(s.map((f,c)=>[f,c])),n=Vt(t,"func"),a=n.length?n[0].idx:t[0]==="module"?1:0;gt(t,a,["table",i,"funcref",["elem",...s]]);let o={};return S(t,f=>{if(!Array.isArray(f)||f[0]!=="func")return;let c=typeof f[1]=="string"&&f[1][0]==="$"?f[1]:null;if(!c)return;let u=[],y=[];for(let m of f){if(Array.isArray(m)&&m[0]==="param")for(let h=1;h<m.length;h++)m[h][0]!=="$"&&u.push(m[h]);if(Array.isArray(m)&&m[0]==="result")for(let h=1;h<m.length;h++)y.push(m[h])}o[c]={params:u,results:y}}),j(t,(f,c,u)=>{if(!(!Array.isArray(f)||!c)){if(f[0]==="ref.func"&&l[f[1]]!==void 0&&(c[u]=["i32.const",l[f[1]]]),f[0]==="call_ref"){let y=f[1],m=f.slice(2);c[u]=["call_indirect",i,["type",y],...m]}if(f[0]==="return_call_ref"){let y=f[1],m=f.slice(2);c[u]=["return_call_indirect",i,["type",y],...m]}}}),t},P={funcref:we},ve={"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]},$e=(t,e)=>(j(t,(r,i,s)=>{if(!Array.isArray(r)||!i)return;let l=ve[r[0]];if(!l)return;let[n,a]=l,o=r.slice(1);i[s]=[`${n}.shr_s`,[`${n}.shl`,...o,[`${n}.const`,a]],[`${n}.const`,a]]}),t);P.sign_ext=$e;var Pt={"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}},Ie=(t,e)=>{let r=new Set;if(S(t,s=>{Array.isArray(s)&&Pt[s[0]]&&r.add(s[0])}),!r.size)return t;let i={};for(let s of r){let{itype:l,ftype:n,signed:a,min:o,max:f}=Pt[s],c=R(`trunc_${l}_${n}_${a?"s":"u"}`);i[s]=c;let u=`${l}.trunc_${n}_${a?"s":"u"}`,y=l==="i64"?0n:0,m=["func",c,["param","$v",n],["result",l],["if",["result",l],[`${n}.ne`,["local.get","$v"],["local.get","$v"]],["then",[`${l}.const`,y]],["else",["if",["result",l],[`${n}.lt`,["local.get","$v"],[`${n}.const`,typeof o=="bigint"?Number(o):o]],["then",[`${l}.const`,o]],["else",["if",["result",l],[`${n}.gt`,["local.get","$v"],[`${n}.const`,typeof f=="bigint"?Number(f):f]],["then",[`${l}.const`,f]],["else",[u,["local.get","$v"]]]]]]]]];t.push(m)}return j(t,(s,l,n)=>{!Array.isArray(s)||!l||i[s[0]]&&(l[n]=["call",i[s[0]],...s.slice(1)])}),t};P.nontrapping=Ie;var ke=(t,e)=>{let r=new Set,i=new Set;S(t,n=>{if(Array.isArray(n)){if(n[0]==="memory.copy"){let a=typeof n[1]=="number"?n[1]:0,o=typeof n[2]=="number"?n[2]:0;r.add(`${a}_${o}`)}if(n[0]==="memory.fill"){let a=typeof n[1]=="number"?n[1]:0;i.add(a)}}});let s={},l={};for(let n of r){let[a,o]=n.split("_").map(Number),f=R(`memcpy${n==="0_0"?"":"_"+n}`);s[n]=f;let c=a?["i32.store8",a]:["i32.store8"],u=o?["i32.load8_u",o]:["i32.load8_u"];t.push(["func",f,["param","$dst","i32"],["param","$src","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...c,["i32.add",["local.get","$dst"],["local.get","$i"]],[...u,["i32.add",["local.get","$src"],["local.get","$i"]]]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}for(let n of i){let a=R(`memset${n===0?"":"_"+n}`);l[n]=a;let o=n?["i32.store8",n]:["i32.store8"];t.push(["func",a,["param","$dst","i32"],["param","$val","i32"],["param","$len","i32"],["local","$i","i32"],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get","$i"],["local.get","$len"]]],[...o,["i32.add",["local.get","$dst"],["local.get","$i"]],["local.get","$val"]],["local.set","$i",["i32.add",["local.get","$i"],["i32.const",1]]],["br","$loop"]]]])}return j(t,(n,a,o)=>{if(!(!Array.isArray(n)||!a)){if(n[0]==="memory.copy"){let f=typeof n[1]=="number"?n[1]:0,c=typeof n[2]=="number"?n[2]:0,u=n.filter(y=>Array.isArray(y)||typeof y=="string"&&y[0]==="$");a[o]=["call",s[`${f}_${c}`],...u]}if(n[0]==="memory.fill"){let f=typeof n[1]=="number"?n[1]:0,c=n.filter(u=>Array.isArray(u)||typeof u=="string"&&u[0]==="$");a[o]=["call",l[f],...c]}}}),t};P.bulk_memory=ke;var Ne=(t,e)=>{let r=!1;return S(t,i=>{Array.isArray(i)&&(i[0]==="return_call"||i[0]==="return_call_indirect")&&(r=!0)}),r&&j(t,(i,s,l)=>{!Array.isArray(i)||!s||(i[0]==="return_call"&&(s[l]=["return",["call",...i.slice(1)]]),i[0]==="return_call_indirect"&&(s[l]=["return",["call_indirect",...i.slice(1)]]))}),t};P.return_call=Ne;var Be=(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 l=r.slice(1);i[s]=["i32.shr_s",["i32.shl",...l,["i32.const",1]],["i32.const",1]]}}),t);P.i31ref=Be;var Me=(t,e)=>{let r={};S(t,s=>{if(!Array.isArray(s)||s[0]!=="global")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n=s.length-1;n>=0;n--){let a=s[n];if(Array.isArray(a)&&(a[0]==="i32.const"||a[0]==="i64.const"||a[0]==="f32.const"||a[0]==="f64.const")){r[l]={type:a[0].split(".")[0],value:a[1]};break}}});let i=s=>{if(!Array.isArray(s))return s;let l=s[0];if(l==="global.get"&&r[s[1]]){let n=r[s[1]];return[`${n.type}.const`,n.value]}if(l==="i32.add"||l==="i64.add"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f+c]}}if(l==="i32.sub"||l==="i64.sub"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f-c]}}if(l==="i32.mul"||l==="i64.mul"){let n=i(s[1]),a=i(s[2]);if(n&&a&&n[0]?.endsWith(".const")&&a[0]?.endsWith(".const")){let o=l.split(".")[0],f=o==="i64"?BigInt(n[1]):Number(n[1]),c=o==="i64"?BigInt(a[1]):Number(a[1]);return[`${o}.const`,f*c]}}return s};return j(t,(s,l,n)=>{if(!(!Array.isArray(s)||s[0]!=="global"||!l)){for(let a=2;a<s.length;a++)if(Array.isArray(s[a])){let o=i(s[a]);o!==s[a]&&(s[a]=o)}}}),t};P.extended_const=Me;var ze=(t,e)=>{let r=new Map,i=[];if(S(t,a=>{if(!Array.isArray(a)||a[0]!=="func")return;let o=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null,f=[];for(let c of a)if(Array.isArray(c)&&c[0]==="result")for(let u=1;u<c.length;u++)f.push(c[u]);f.length>1&&o&&r.set(o,f)}),!r.size)return t;let s=Math.max(...[...r.values()].map(a=>a.length)),l={};for(let[a,o]of r)for(let f=1;f<o.length;f++){let c=o[f];if(l[c]||(l[c]=[]),l[c].length<f){let u=R(`ret_${c}_${l[c].length}`);l[c].push(u),i.push(["global",u,["mut",c],[`${c}.const`,c==="i64"?0n:0]])}}let n=t[0]==="module"?1:0;for(let a of i.reverse())gt(t,n,a);return j(t,(a,o,f)=>{if(!Array.isArray(a)||a[0]!=="func")return;let c=typeof a[1]=="string"&&a[1][0]==="$"?a[1]:null;if(!c||!r.has(c))return;let u=r.get(c);for(let y=0;y<a.length;y++)if(Array.isArray(a[y])&&a[y][0]==="result"){a[y]=["result",u[0]];break}}),t};P.multi_value=ze;var lt={i32:4,i64:8,f32:4,f64:8},Te=(t,e)=>{let r=new Map,i=new Map,s=1;if(S(t,p=>{if(!Array.isArray(p)||p[0]!=="type")return;let d=typeof p[1]=="string"&&p[1][0]==="$"?p[1]:null;if(d){for(let _ of p)if(Array.isArray(_)){if(_[0]==="struct"){let b=[];for(let g of _)if(Array.isArray(g)&&g[0]==="field"){let v=typeof g[1]=="string"&&g[1][0]==="$"?g[1]:null,w=v?g[2]:g[1],k=Array.isArray(w)&&w[0]==="mut"?w[1]:w;b.push({name:v,type:k})}r.set(d,{kind:"struct",fields:b}),i.set(d,s++)}if(_[0]==="array"){let b=_[1],g=Array.isArray(b)&&b[0]==="mut"?b[1]:b;r.set(d,{kind:"array",elemType:g}),i.set(d,s++)}}}}),!r.size)return t;let l=Vt(t,"memory").length>0,n=R("alloc"),a=R("heap_ptr"),o=t[0]==="module"?1:0;l||gt(t,o,["memory",1]),gt(t,o+1,["global",a,["mut","i32"],["i32.const",1024]]);let f=["func",n,["param","$size","i32"],["result","i32"],["local","$ptr","i32"],["local.set","$ptr",["global.get",a]],["global.set",a,["i32.add",["global.get",a],["local.get","$size"]]],["local.get","$ptr"]];t.push(f);let c=p=>{let d=4;for(let _ of p.fields)d+=lt[_.type]||4;return d},u=(p,d)=>{let _=4;for(let b=0;b<d;b++)_+=lt[p.fields[b].type]||4;return _},y=(p,d)=>{for(let _=0;_<p.fields.length;_++)if(p.fields[_].name===d)return _;return-1},m=0,h=()=>`$__gc_tmp${m++}`;return S(t,p=>{if(!Array.isArray(p)||p[0]!=="func")return;let d=!1,_=!1,b=!1,g=!1;if(S(p,w=>{Array.isArray(w)&&((w[0]==="struct.new"||w[0]==="struct.new_default")&&(d=!0),(w[0]==="array.new"||w[0]==="array.new_default")&&(_=!0,b=!0,g=!0))}),!d&&!_)return;let v=1;for(let w=1;w<p.length;w++){let k=p[w];if(Array.isArray(k)&&(k[0]==="param"||k[0]==="result"||k[0]==="local"||k[0]==="export"||k[0]==="type"))v=w+1;else if(typeof k=="string"&&k[0]==="$")v=w+1;else if(!Array.isArray(k))v=w+1;else break}d&&p.splice(v++,0,["local","$__gc_ptr","i32"]),_&&p.splice(v++,0,["local","$__gc_aptr","i32"]),b&&p.splice(v++,0,["local","$__gc_alen","i32"]),g&&p.splice(v++,0,["local","$__gc_aidx","i32"])}),j(t,(p,d,_)=>{if(!(!Array.isArray(p)||!d)){if(p[0]==="struct.new"||p[0]==="struct.new_default"){let b=p[1],g=r.get(b);if(!g||g.kind!=="struct")return;let v=c(g),w=i.get(b),k=p.slice(2),M="$__gc_ptr",U=[["local.set",M,["call",n,["i32.const",v]]],["i32.store",["local.get",M],["i32.const",w]]];if(p[0]==="struct.new")for(let z=0;z<g.fields.length;z++){let T=g.fields[z],rt=u(g,z),K=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store";U.push([K,["i32.add",["local.get",M],["i32.const",rt]],k[z]||[`${T.type}.const`,0]])}else for(let z=0;z<g.fields.length;z++){let T=g.fields[z],rt=u(g,z),K=T.type==="i64"?"i64.store":T.type==="f32"?"f32.store":T.type==="f64"?"f64.store":"i32.store",ee=T.type==="i64"?["i64.const",0n]:T.type==="f32"?["f32.const",0]:T.type==="f64"?["f64.const",0]:["i32.const",0];U.push([K,["i32.add",["local.get",M],["i32.const",rt]],ee])}U.push(["local.get",M]),d[_]=["block",["result","i32"],...U]}if(p[0]==="struct.get"){let b=p[1],g=p[2],v=p[3],w=r.get(b);if(!w||w.kind!=="struct")return;let k=typeof g=="string"&&g[0]==="$"?y(w,g):parseInt(g);if(k<0)return;let M=w.fields[k],U=u(w,k),z=M.type==="i64"?"i64.load":M.type==="f32"?"f32.load":M.type==="f64"?"f64.load":"i32.load";d[_]=[z,["i32.add",v,["i32.const",U]]]}if(p[0]==="struct.set"){let b=p[1],g=p[2],v=p[3],w=p[4],k=r.get(b);if(!k||k.kind!=="struct")return;let M=typeof g=="string"&&g[0]==="$"?y(k,g):parseInt(g);if(M<0)return;let U=k.fields[M],z=u(k,M),T=U.type==="i64"?"i64.store":U.type==="f32"?"f32.store":U.type==="f64"?"f64.store":"i32.store";d[_]=[T,["i32.add",v,["i32.const",z]],w]}if(p[0]==="array.new"||p[0]==="array.new_default"){let b=p[1],g=r.get(b);if(!g||g.kind!=="array")return;let v=i.get(b),w=lt[g.elemType]||4,k=p[0]==="array.new"?p[2]:null,M=p[0]==="array.new"?p[3]:p[2],U="$__gc_aptr",z="$__gc_alen",T="$__gc_aidx",rt=g.elemType==="i64"?"i64.store":g.elemType==="f32"?"f32.store":g.elemType==="f64"?"f64.store":"i32.store",K=[["local.set",z,M],["local.set",U,["call",n,["i32.add",["i32.const",8],["i32.mul",["local.get",z],["i32.const",w]]]]],["i32.store",["local.get",U],["i32.const",v]],["i32.store",["i32.add",["local.get",U],["i32.const",4]],["local.get",z]]];k&&K.push(["local.set",T,["i32.const",0]],["block","$done",["loop","$loop",["br_if","$done",["i32.ge_u",["local.get",T],["local.get",z]]],[rt,["i32.add",["i32.add",["local.get",U],["i32.const",8]],["i32.mul",["local.get",T],["i32.const",w]]],k],["local.set",T,["i32.add",["local.get",T],["i32.const",1]]],["br","$loop"]]]),K.push(["local.get",U]),d[_]=["block",["result","i32"],...K]}if(p[0]==="array.get"){let b=p[1],g=p[2],v=p[3],w=r.get(b);if(!w||w.kind!=="array")return;let k=lt[w.elemType]||4,M=w.elemType==="i64"?"i64.load":w.elemType==="f32"?"f32.load":w.elemType==="f64"?"f64.load":"i32.load";d[_]=[M,["i32.add",["i32.add",g,["i32.const",8]],["i32.mul",v,["i32.const",k]]]]}if(p[0]==="array.set"){let b=p[1],g=p[2],v=p[3],w=p[4],k=r.get(b);if(!k||k.kind!=="array")return;let M=lt[k.elemType]||4,U=k.elemType==="i64"?"i64.store":k.elemType==="f32"?"f32.store":k.elemType==="f64"?"f64.store":"i32.store";d[_]=[U,["i32.add",["i32.add",g,["i32.const",8]],["i32.mul",v,["i32.const",M]]],w]}if(p[0]==="array.len"){let b=p[1];d[_]=["i32.load",["i32.add",b,["i32.const",4]]]}}}),t};P.gc=Te;var Ee=(t,e)=>{let r=new Map,i=1;return S(t,s=>{if(!Array.isArray(s)||s[0]!=="type")return;let l=typeof s[1]=="string"&&s[1][0]==="$"?s[1]:null;if(l)for(let n of s)Array.isArray(n)&&(n[0]==="struct"||n[0]==="array")&&r.set(l,i++)}),r.size&&j(t,(s,l,n)=>{if(!(!Array.isArray(s)||!l)){if(s[0]==="ref.test"){let a=s[1],o=null;Array.isArray(a)&&a[0]==="ref"&&(o=a[1]==="null"?a[2]:a[1]);let f=s[2],c=r.get(o);c!==void 0&&(l[n]=["if",["result","i32"],["i32.eqz",f],["then",["i32.const",0]],["else",["i32.eq",["i32.load",f],["i32.const",c]]]])}if(s[0]==="ref.cast"){let a=s[1],o=null,f=!1;Array.isArray(a)&&a[0]==="ref"&&(a[1]==="null"?(f=!0,o=a[2]):o=a[1]);let c=s[2],u=r.get(o);if(u!==void 0){let y=R("cast");f?l[n]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["if",["i32.and",["i32.ne",["local.get",y],["i32.const",0]],["i32.ne",["i32.load",["local.get",y]],["i32.const",u]]],["then",["unreachable"]]],["local.get",y]]:l[n]=["block",["result","i32"],["local",y,"i32"],["local.set",y,c],["if",["i32.or",["i32.eqz",["local.get",y]],["i32.ne",["i32.load",["local.get",y]],["i32.const",u]]],["then",["unreachable"]]],["local.get",y]]}}if(s[0]==="br_on_cast"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let y=r.get(u);if(y!==void 0){let m=R("brcast");l[n]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["br_if",a,["i32.and",["i32.ne",["local.get",m],["i32.const",0]],["i32.eq",["i32.load",["local.get",m]],["i32.const",y]]]],["local.get",m]]}}if(s[0]==="br_on_cast_fail"){let a=s[1],o=s[2],f=s[3],c=s[4],u=null;Array.isArray(f)&&f[0]==="ref"&&(u=f[1]==="null"?f[2]:f[1]);let y=r.get(u);if(y!==void 0){let m=R("brfail");l[n]=["block",["result","i32"],["local",m,"i32"],["local.set",m,c],["br_if",a,["i32.or",["i32.eqz",["local.get",m]],["i32.ne",["i32.load",["local.get",m]],["i32.const",y]]]],["local.get",m]]}}}}),t};P.ref_cast=Ee;function xt(t,e=!0){typeof t=="string"&&(t=C(t)),t=Rt(t),e=de(e);let r=be(t),i={uid:0};for(let s of It)r.has(s)&&e[s]!==!1&&P[s]&&(t=P[s](t,i));return t}var Nt={treeshake:!0,fold:!0,deadcode:!0,locals:!0,identity:!0,strength:!0,branch:!0,propagate:!0,inline:!0},kt=Object.keys(Nt),Ue=t=>{if(t===!0)return{...Nt};if(t===!1)return{};if(typeof t=="string"){let e=new Set(t.split(/\s+/).filter(Boolean));return e.size===1&&kt.includes([...e][0])?Object.fromEntries(kt.map(r=>[r,e.has(r)])):Object.fromEntries(kt.map(r=>[r,e.has(r)||e.has("all")]))}return{...Nt,...t}},O=t=>Array.isArray(t)?t.map(O):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 l=0;l<t.length;l++){let n=J(t[l],e,t,l);n!==void 0&&(t[l]=n)}let s=e(t,r,i);return s!==void 0?s:t},Se=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=new Map,r=new Map,i=new Map,s=new Map,l=new Map,n=[],a=[],o=0,f=0,c=0,u=0,y=0,m=0;for(let _ of t.slice(1)){if(!Array.isArray(_))continue;let b=_[0];if(b==="type"){let g=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:c;i.set(g,{node:_,idx:c,used:!1}),typeof g=="string"&&i.set(c,i.get(g)),c++}else if(b==="func"){let g=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:o,v=_.some(w=>Array.isArray(w)&&w[0]==="export");e.set(g,{node:_,idx:o,used:v}),typeof g=="string"&&e.set(o,e.get(g)),o++}else if(b==="global"){let g=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:f,v=_.some(w=>Array.isArray(w)&&w[0]==="export");r.set(g,{node:_,idx:f,used:v}),typeof g=="string"&&r.set(f,r.get(g)),f++}else if(b==="table"){let g=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:u,v=_.some(w=>Array.isArray(w)&&w[0]==="export");s.set(g,{node:_,idx:u,used:v}),typeof g=="string"&&s.set(u,s.get(g)),u++}else if(b==="memory"){let g=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:y,v=_.some(w=>Array.isArray(w)&&w[0]==="export");l.set(g,{node:_,idx:y,used:v}),typeof g=="string"&&l.set(y,l.get(g)),y++}else if(b==="import"){for(let g of _)if(Array.isArray(g)&&g[0]==="func"){let v=typeof g[1]=="string"&&g[1][0]==="$"?g[1]:m;e.set(v,{node:_,idx:m,used:!0,isImport:!0}),typeof v=="string"&&e.set(m,e.get(v)),m++,o++}}else b==="export"?n.push(_):b==="start"&&a.push(_)}for(let _ of n)for(let b of _){if(!Array.isArray(b))continue;let[g,v]=b;g==="func"&&e.has(v)?e.get(v).used=!0:g==="global"&&r.has(v)?r.get(v).used=!0:g==="table"&&s.has(v)?s.get(v).used=!0:g==="memory"&&l.has(v)&&(l.get(v).used=!0)}for(let _ of a){let b=_[1];typeof b=="string"&&b[0]!=="$"&&(b=+b),e.has(b)&&(e.get(b).used=!0)}let h=n.length>0||a.length>0;if(!h){for(let[,_]of e)if(_.used){h=!0;break}if(!h){for(let[,_]of r)if(_.used){h=!0;break}}if(!h){for(let[,_]of s)if(_.used){h=!0;break}}if(!h){for(let[,_]of l)if(_.used){h=!0;break}}}if(!h){for(let[,_]of e)_.used=!0;for(let[,_]of r)_.used=!0;for(let[,_]of s)_.used=!0;for(let[,_]of l)_.used=!0}for(let _ of t.slice(1))!Array.isArray(_)||_[0]!=="elem"||V(_,b=>{if(Array.isArray(b)&&b[0]==="ref.func"){let g=b[1];e.has(g)&&(e.get(g).used=!0)}typeof b=="string"&&b[0]==="$"&&e.has(b)&&(e.get(b).used=!0)});let p=!0;for(;p;){p=!1;for(let[,_]of e)!_.used||_.isImport||V(_.node,b=>{if(!Array.isArray(b)){typeof b=="string"&&b[0]==="$"&&e.has(b)&&!e.get(b).used&&(e.get(b).used=!0,p=!0);return}let[g,v]=b;if((g==="call"||g==="return_call"||g==="ref.func")&&e.has(v)&&!e.get(v).used&&(e.get(v).used=!0,p=!0),(g==="global.get"||g==="global.set")&&r.has(v)&&!r.get(v).used&&(r.get(v).used=!0,p=!0),g==="call_indirect"||g==="return_call_indirect")for(let w of b)typeof w=="string"&&w[0]==="$"&&s.has(w)&&!s.get(w).used&&(s.get(w).used=!0,p=!0);g==="type"&&i.has(v)&&!i.get(v).used&&(i.get(v).used=!0,p=!0)})}let d=["module"];for(let _ of t.slice(1)){if(!Array.isArray(_)){d.push(_);continue}let b=_[0];if(b==="func"){let g=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null;(g?e.get(g):[...e.values()].find(w=>w.node===_))?.used&&d.push(_)}else if(b==="global"){let g=typeof _[1]=="string"&&_[1][0]==="$"?_[1]:null;(g?r.get(g):[...r.values()].find(w=>w.node===_))?.used&&d.push(_)}else d.push(_)}return d},Gt=t=>t-Math.floor(t)!==.5?Math.round(t):2*Math.round(t/2),qe={"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":(t,e)=>t===e?1:0,"i32.ne":(t,e)=>t!==e?1:0,"i32.lt_s":(t,e)=>t<e?1:0,"i32.lt_u":(t,e)=>t>>>0<e>>>0?1:0,"i32.gt_s":(t,e)=>t>e?1:0,"i32.gt_u":(t,e)=>t>>>0>e>>>0?1:0,"i32.le_s":(t,e)=>t<=e?1:0,"i32.le_u":(t,e)=>t>>>0<=e>>>0?1:0,"i32.ge_s":(t,e)=>t>=e?1:0,"i32.ge_u":(t,e)=>t>>>0>=e>>>0?1:0,"i32.eqz":t=>t===0?1:0,"i32.clz":t=>Math.clz32(t),"i32.ctz":t=>t===0?32:31-Math.clz32(t&-t),"i32.popcnt":t=>{let e=0;for(;t;)e+=t&1,t>>>=1;return e},"i32.wrap_i64":t=>Number(BigInt.asIntN(32,t)),"i64.add":(t,e)=>BigInt.asIntN(64,t+e),"i64.sub":(t,e)=>BigInt.asIntN(64,t-e),"i64.mul":(t,e)=>BigInt.asIntN(64,t*e),"i64.div_s":(t,e)=>e!==0n?BigInt.asIntN(64,t/e):null,"i64.div_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)/BigInt.asUintN(64,e)):null,"i64.rem_s":(t,e)=>e!==0n?BigInt.asIntN(64,t%e):null,"i64.rem_u":(t,e)=>e!==0n?BigInt.asUintN(64,BigInt.asUintN(64,t)%BigInt.asUintN(64,e)):null,"i64.and":(t,e)=>BigInt.asIntN(64,t&e),"i64.or":(t,e)=>BigInt.asIntN(64,t|e),"i64.xor":(t,e)=>BigInt.asIntN(64,t^e),"i64.shl":(t,e)=>BigInt.asIntN(64,t<<(e&63n)),"i64.shr_s":(t,e)=>BigInt.asIntN(64,t>>(e&63n)),"i64.shr_u":(t,e)=>BigInt.asUintN(64,BigInt.asUintN(64,t)>>(e&63n)),"i64.eq":(t,e)=>t===e?1:0,"i64.ne":(t,e)=>t!==e?1:0,"i64.lt_s":(t,e)=>t<e?1:0,"i64.lt_u":(t,e)=>BigInt.asUintN(64,t)<BigInt.asUintN(64,e)?1:0,"i64.gt_s":(t,e)=>t>e?1:0,"i64.gt_u":(t,e)=>BigInt.asUintN(64,t)>BigInt.asUintN(64,e)?1:0,"i64.le_s":(t,e)=>t<=e?1:0,"i64.le_u":(t,e)=>BigInt.asUintN(64,t)<=BigInt.asUintN(64,e)?1:0,"i64.ge_s":(t,e)=>t>=e?1:0,"i64.ge_u":(t,e)=>BigInt.asUintN(64,t)>=BigInt.asUintN(64,e)?1:0,"i64.eqz":t=>t===0n?1:0,"i64.extend_i32_s":t=>BigInt(t),"i64.extend_i32_u":t=>BigInt(t>>>0),"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(Gt(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":t=>Math.abs(t),"f64.sqrt":t=>Math.sqrt(t),"f64.ceil":t=>Math.ceil(t),"f64.floor":t=>Math.floor(t),"f64.trunc":t=>Math.trunc(t),"f64.nearest":Gt},$=t=>{if(!Array.isArray(t)||t.length!==2)return null;let[e,r]=t;return e==="i32.const"?{type:"i32",value:Number(r)|0}:e==="i64.const"?{type:"i64",value:BigInt(r)}:e==="f32.const"?{type:"f32",value:Math.fround(Number(r))}:e==="f64.const"?{type:"f64",value:Number(r)}:null},Ht=(t,e)=>t==="i32"?["i32.const",e|0]:t==="i64"?["i64.const",e]:t==="f32"?["f32.const",Math.fround(e)]:t==="f64"?["f64.const",e]:null,Oe=t=>J(O(t),e=>{if(!Array.isArray(e))return;let r=e[0],i=qe[r];if(i){if(i.length===1&&e.length===2){let s=$(e[1]);if(!s)return;let l=i(s.value);if(l===null)return;let n=r.startsWith("i64.")&&!r.includes("eqz")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Ht(n,l)}if(i.length===2&&e.length===3){let s=$(e[1]),l=$(e[2]);if(!s||!l)return;let n=i(s.value,l.value);if(n===null)return;let o=/\.(eq|ne|[lg][te])/.test(r)?"i32":r.startsWith("i64.")?"i64":r.startsWith("f32.")?"f32":r.startsWith("f64.")?"f64":"i32";return Ht(o,n)}}}),Fe={"i32.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.add":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.sub":(t,e)=>$(e)?.value===0?t:null,"i64.sub":(t,e)=>$(e)?.value===0n?t:null,"i32.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1?e:i?.value===1?t:null},"i64.mul":(t,e)=>{let r=$(t),i=$(e);return r?.value===1n?e:i?.value===1n?t:null},"i32.div_s":(t,e)=>$(e)?.value===1?t:null,"i32.div_u":(t,e)=>$(e)?.value===1?t:null,"i64.div_s":(t,e)=>$(e)?.value===1n?t:null,"i64.div_u":(t,e)=>$(e)?.value===1n?t:null,"i32.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1?e:i?.value===-1?t:null},"i64.and":(t,e)=>{let r=$(t),i=$(e);return r?.value===-1n?e:i?.value===-1n?t:null},"i32.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.or":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0?e:i?.value===0?t:null},"i64.xor":(t,e)=>{let r=$(t),i=$(e);return r?.value===0n?e:i?.value===0n?t:null},"i32.shl":(t,e)=>$(e)?.value===0?t:null,"i32.shr_s":(t,e)=>$(e)?.value===0?t:null,"i32.shr_u":(t,e)=>$(e)?.value===0?t:null,"i64.shl":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_s":(t,e)=>$(e)?.value===0n?t:null,"i64.shr_u":(t,e)=>$(e)?.value===0n?t:null},We=t=>J(O(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let r=Fe[e[0]];if(!r)return;let i=r(e[1],e[2]);if(i!==null)return i}),Le=t=>J(O(t),e=>{if(!Array.isArray(e)||e.length!==3)return;let[r,i,s]=e;if(r==="i32.mul"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1)){let a=Math.log2(l.value);if(Number.isInteger(a))return["i32.shl",i,["i32.const",a]]}let n=$(i);if(n&&n.value>0&&!(n.value&n.value-1)){let a=Math.log2(n.value);if(Number.isInteger(a))return["i32.shl",s,["i32.const",a]]}}if(r==="i64.mul"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let a=BigInt(l.value.toString(2).length-1);return["i64.shl",i,["i64.const",a]]}let n=$(i);if(n&&n.value>0n&&(n.value&n.value-1n)===0n){let a=BigInt(n.value.toString(2).length-1);return["i64.shl",s,["i64.const",a]]}}if(r==="i32.div_u"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1)){let n=Math.log2(l.value);if(Number.isInteger(n))return["i32.shr_u",i,["i32.const",n]]}}if(r==="i64.div_u"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n){let n=BigInt(l.value.toString(2).length-1);return["i64.shr_u",i,["i64.const",n]]}}if(r==="i32.rem_u"){let l=$(s);if(l&&l.value>0&&!(l.value&l.value-1))return["i32.and",i,["i32.const",l.value-1]]}if(r==="i64.rem_u"){let l=$(s);if(l&&l.value>0n&&(l.value&l.value-1n)===0n)return["i64.and",i,["i64.const",l.value-1n]]}}),Ce=t=>J(O(t),e=>{if(!Array.isArray(e))return;let r=e[0];if(r==="if"){let i=1;for(;i<e.length;){let o=e[i];if(Array.isArray(o)&&(o[0]==="then"||o[0]==="else"||o[0]==="result"||o[0]==="param")){i++;continue}break}let s=e[i],l=$(s);if(!l)return;let n=null,a=null;for(let o=i+1;o<e.length;o++){let f=e[o];Array.isArray(f)&&(f[0]==="then"?n=f:f[0]==="else"&&(a=f))}if(l.value!==0&&l.value!==0n){if(n&&n.length>1){let o=n.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}else{if(a&&a.length>1){let o=a.slice(1);return o.length===1?o[0]:["block",...o]}return["nop"]}}if(r==="br_if"&&e.length>=3){let i=e[e.length-1],s=$(i);return s?s.value===0||s.value===0n?["nop"]:["br",e[1]]:void 0}if(r==="select"&&e.length>=4){let i=e[e.length-1],s=$(i);return s?s.value===0||s.value===0n?e[2]:e[1]:void 0}}),Yt=new Set(["unreachable","return","br","br_table"]),De=t=>{let e=O(t);return V(e,r=>{if(!Array.isArray(r))return;let i=r[0];if((i==="func"||i==="block"||i==="loop")&&Jt(r),i==="if")for(let s=1;s<r.length;s++)Array.isArray(r[s])&&(r[s][0]==="then"||r[s][0]==="else")&&Jt(r[s])}),e},Jt=t=>{let e=!1,r=-1;for(let i=1;i<t.length;i++){let s=t[i];if(Array.isArray(s)){let l=s[0];if(l==="param"||l==="result"||l==="local"||l==="type"||l==="export")continue;e&&r===-1&&(r=i),Yt.has(l)&&(e=!0,r=i+1)}else typeof s=="string"&&(e&&r===-1&&(r=i),Yt.has(s)&&(e=!0,r=i+1))}r>0&&r<t.length&&t.splice(r)},Pe=t=>{let e=O(t);return V(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=[],s=new Map,l=new Set;for(let n=1;n<r.length;n++){let a=r[n];Array.isArray(a)&&(a[0]==="local"&&(i.push({node:a,idx:n}),typeof a[1]=="string"&&a[1][0]==="$"&&s.set(a[1],a[2])),a[0]==="param"&&typeof a[1]=="string"&&a[1][0]==="$"&&(s.set(a[1],a[2]),l.add(a[1])))}V(r,n=>{if(!Array.isArray(n))return;let a=n[0];if(a==="local.get"||a==="local.set"||a==="local.tee"){let o=n[1];typeof o=="string"&&l.add(o)}});for(let n=i.length-1;n>=0;n--){let{idx:a,node:o}=i[n],f=typeof o[1]=="string"&&o[1][0]==="$"?o[1]:null;f&&!l.has(f)&&r.splice(a,1)}}),e},Bt=t=>{if(!Array.isArray(t))return!0;let e=t[0];if(typeof e!="string"||e==="call"||e==="call_indirect"||e==="return_call"||e==="return_call_indirect"||e.includes(".store")||e.includes(".load")||e.includes("memory.")||e==="global.set")return!1;for(let r=1;r<t.length;r++)if(Array.isArray(t[r])&&!Bt(t[r]))return!1;return!0},Kt=t=>{let e=new Map,r=i=>(e.has(i)||e.set(i,{gets:0,sets:0,tees:0}),e.get(i));return V(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},Zt=t=>$(t.val)||t.pure&&t.singleUse,Xt=(t,e)=>J(t,r=>{if(!Array.isArray(r)||r[0]!=="local.get"||r.length!==2)return;let i=typeof r[1]=="string"&&e.get(r[1]);if(i&&Zt(i))return O(i.val)}),je=t=>{let e=O(t);return V(e,r=>{if(!Array.isArray(r)||r[0]!=="func")return;let i=new Set;for(let s of r)Array.isArray(s)&&s[0]==="param"&&typeof s[1]=="string"&&i.add(s[1]);for(let s=0;s<4;s++){let l=!1,n=Kt(r),a=u=>n.get(u)||{gets:0,sets:0,tees:0},o=new Map;for(let u=1;u<r.length;u++){let y=r[u];if(!Array.isArray(y))continue;let m=y[0];if(!(m==="param"||m==="result"||m==="local"||m==="type"||m==="export")){if(m==="local.set"&&y.length===3&&typeof y[1]=="string"){Xt(y[2],o);let h=a(y[1]);o.set(y[1],{val:y[2],pure:Bt(y[2]),singleUse:h.gets<=1&&h.sets<=1&&h.tees===0});continue}if((m==="block"||m==="loop"||m==="if")&&o.clear(),m==="call"||m==="call_indirect"||m==="return_call"||m==="return_call_indirect")for(let[h,p]of o)$(p.val)||o.delete(h);if(m==="local.get"&&y.length===2&&typeof y[1]=="string"){let h=o.get(y[1]);if(h&&Zt(h)){let p=O(h.val);y.length=0,y.push(...Array.isArray(p)?p:[p]),l=!0;continue}}if(m!=="block"&&m!=="loop"&&m!=="if"){let h=JSON.stringify(y);Xt(y,o),JSON.stringify(y)!==h&&(l=!0)}}}let f=Kt(r),c=u=>f.get(u)||{gets:0,sets:0,tees:0};for(let u=r.length-1;u>=1;u--){let y=r[u];if(!Array.isArray(y))continue;let m=typeof y[1]=="string"?y[1]:null;if(!m||i.has(m))continue;let h=c(m);(y[0]==="local.set"&&h.gets===0&&h.tees===0&&Bt(y[2])||y[0]==="local"&&m[0]==="$"&&h.gets===0&&h.sets===0&&h.tees===0)&&(r.splice(u,1),l=!0)}if(!l)break}}),e},Re=t=>{if(!Array.isArray(t)||t[0]!=="module")return t;let e=O(t),r=new Map;for(let i of e.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 l=[],n=[],a=!1,o=!1;for(let f=1;f<i.length;f++){let c=i[f];if(Array.isArray(c))if(c[0]==="param")if(typeof c[1]=="string"&&c[1][0]==="$")l.push({name:c[1],type:c[2]});else{l=null;break}else c[0]==="local"?a=!0:c[0]==="export"?o=!0:c[0]!=="result"&&c[0]!=="type"&&n.push(c)}if(l&&!a&&!o&&l.length<=2&&n.length===1){let f=new Set(l.map(u=>u.name)),c=!1;V(n[0],u=>{Array.isArray(u)&&(u[0]==="local.set"||u[0]==="local.tee")&&f.has(u[1])&&(c=!0)}),c||r.set(s,{body:n[0],params:l})}}return r.size===0||J(e,i=>{if(!Array.isArray(i)||i[0]!=="call")return;let s=i[1];if(!r.has(s))return;let{body:l,params:n}=r.get(s),a=i.slice(2);if(n.length===0)return O(l);let o=O(l);return J(o,f=>{if(!Array.isArray(f)||f[0]!=="local.get")return;let c=f[1],u=n.findIndex(y=>y.name===c);if(u!==-1&&a[u])return O(a[u])}),o}),e};function ht(t,e=!0){return typeof t=="string"&&(t=C(t)),t=O(t),e=Ue(e),e.fold&&(t=Oe(t)),e.identity&&(t=We(t)),e.strength&&(t=Le(t)),e.branch&&(t=Ce(t)),e.propagate&&(t=je(t)),e.inline&&(t=Re(t)),e.deadcode&&(t=De(t)),e.locals&&(t=Pe(t)),e.treeshake&&(t=Se(t)),t}var Qt="\uE000",te=t=>{if(!t||typeof t!="string")return null;let e=t.split(".")[0];return/^[if](32|64)|v128/.test(e)?e:/\.(eq|ne|[lg][te]|eqz)/.test(t)||t==="memory.size"||t==="memory.grow"?"i32":null},Ve=(t,e={})=>{if(!Array.isArray(t))return typeof t=="string"&&t[0]==="$"&&e.locals?.[t]?e.locals[t]:null;let[r,...i]=t;return te(r)?te(r):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 Mt(t,e){if(t=e(t),Array.isArray(t))for(let r=0;r<t.length;r++){let i=Mt(t[r],e);i?._splice?(t.splice(r,1,...i),r+=i.length-1):t[r]=i}return t}function Ge(t,e){let r=[],i=new Map;return Mt(t,s=>{if(!Array.isArray(s))return s;if(s[0]==="call"&&typeof s[1]=="function"){let l=s[1];if(!i.has(l)){let a=[];for(let c=2;c<s.length;c++){let u=Ve(s[c]);u&&a.push(u)}let o=r.length,f=l.name||`$fn${o}`;i.set(l,{idx:o,name:f.startsWith("$")?f:"$"+f,params:a,fn:l}),r.push(i.get(l))}let n=i.get(l);s[1]=n.name}return s}),r}function He(t){return t.map(({name:e,params:r})=>["import",'"env"',`"${e.slice(1)}"`,["func",e,...r.map(i=>["param",i])]])}function Ye(t,...e){let r={};if(!Array.isArray(t)&&e.length&&typeof e[e.length-1]=="object"&&e[e.length-1]!==null&&!e[e.length-1].byteLength&&(r=e.pop()),Array.isArray(t)&&t.raw){let i=t[0];for(let f=0;f<e.length;f++)i+=Qt+t[f+1];let s=C(i),l=[],n=0;s=Mt(s,f=>{if(f===Qt){let c=e[n++];if(typeof c=="function")return l.push(c),c;if(typeof c=="string"&&(c[0]==="("||/^\s*\(/.test(c))){let u=C(c);return Array.isArray(u)&&Array.isArray(u[0])&&(u._splice=!0),u}return c.byteLength!==void 0?[...c]:c}return f});let a=null;if(l.length){let f=Ge(s,l);if(f.length){let c=He(f);s[0]==="module"?s.splice(1,0,...c):typeof s[0]=="string"?s=[...c,s]:s.unshift(...c),a={env:{}};for(let u of f)a.env[u.name.slice(1)]=u.fn}}r.polyfill&&(s=xt(s,r.polyfill)),r.optimize&&(s=ht(s,r.optimize));let o=et(s);return a&&(o._imports=a),o}if(r.polyfill||r.optimize){let i=typeof t=="string"?C(t):t;return r.polyfill&&(i=xt(i,r.polyfill)),r.optimize&&(i=ht(i,r.optimize)),et(i)}return et(t)}function Je(t,...e){let r=Ye(t,...e),i=new WebAssembly.Module(r);return new WebAssembly.Instance(i,r._imports).exports}var dr=Je;export{Ye as compile,dr as default,ht as optimize,C as parse,xt as polyfill,Dt as print,Je as watr};