snarkjs
Version:
zkSNARKs implementation in JavaScript
1 lines • 711 kB
JavaScript
var snarkjs=function(t){"use strict";const a=[0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4];function e(t,a){return a&&10!=a?16==a?"0x"==t.slice(0,2)?BigInt(t):BigInt("0x"+t):void 0:BigInt(t)}const o=e;function i(t){const e=t.toString(16);return 4*(e.length-1)+a[parseInt(e[0],16)]}function n(t){return BigInt(t)<BigInt(0)}function l(t){return!t}function c(t,a){return BigInt(t)<<BigInt(a)}function s(t,a){return BigInt(t)>>BigInt(a)}const r=c,d=s;function u(t){return(BigInt(t)&BigInt(1))==BigInt(1)}function _(t){let a=BigInt(t);const e=[];for(;a;)a&BigInt(1)?e.push(1):e.push(0),a>>=BigInt(1);return e}function g(t){if(t>BigInt(Number.MAX_SAFE_INTEGER))throw new Error("Number too big");return Number(t)}function f(t,a){return BigInt(t)+BigInt(a)}function h(t,a){return BigInt(t)-BigInt(a)}function p(t){return-BigInt(t)}function m(t,a){return BigInt(t)*BigInt(a)}function L(t,a){return BigInt(t)**BigInt(a)}function b(t,a){return BigInt(t)/BigInt(a)}function w(t,a){return BigInt(t)%BigInt(a)}function y(t,a){return BigInt(t)==BigInt(a)}function A(t,a){return BigInt(t)>BigInt(a)}function C(t,a){return BigInt(t)>=BigInt(a)}function x(t,a){return BigInt(t)&BigInt(a)}function F(t,a,e,o){const i="0000000"+e.toString(16),n=new Uint32Array(t.buffer,t.byteOffset+a,o/4),l=1+(4*(i.length-7)-1>>5);for(let t=0;t<l;t++)n[t]=parseInt(i.substring(i.length-8*t-8,i.length-8*t),16);for(let t=l;t<n.length;t++)n[t]=0;for(let a=4*n.length;a<o;a++)t[a]=g(x(s(e,8*a),255))}function I(t,a,e,o){const i="0000000"+e.toString(16),n=new DataView(t.buffer,t.byteOffset+a,o),l=1+(4*(i.length-7)-1>>5);for(let t=0;t<l;t++)n.setUint32(o-4*t-4,parseInt(i.substring(i.length-8*t-8,i.length-8*t),16),!1);for(let t=0;t<o/4-l;t++)n[t]=0}function B(t,a,o){o=o||t.byteLength,a=a||0;const i=new Uint32Array(t.buffer,t.byteOffset+a,o/4),n=new Array(o/4);return i.forEach(((t,a)=>n[n.length-a-1]=t.toString(16).padStart(8,"0"))),e(n.join(""),16)}function E(t,a,o){o=o||t.byteLength,a=a||0;const i=new DataView(t.buffer,t.byteOffset+a,o),n=new Array(o/4);for(let t=0;t<o/4;t++)n[t]=i.getUint32(4*t,!1).toString(16).padStart(8,"0");return e(n.join(""),16)}function v(t,a){return t.toString(a)}function S(t){const a=new Uint8Array(Math.floor((i(t)-1)/8)+1);return F(a,0,t,a.byteLength),a}const P=o(0),O=o(1);var q=Object.freeze({__proto__:null,abs:function(t){return BigInt(t)>=0?BigInt(t):-BigInt(t)},add:f,band:x,bitLength:i,bits:_,bor:function(t,a){return BigInt(t)|BigInt(a)},bxor:function(t,a){return BigInt(t)^BigInt(a)},div:b,e:o,eq:y,exp:function(t,a){return BigInt(t)**BigInt(a)},fromArray:function(t,a){let e=BigInt(0);a=BigInt(a);for(let o=0;o<t.length;o++)e=e*a+BigInt(t[o]);return e},fromRprBE:E,fromRprLE:B,fromString:e,geq:C,gt:A,isNegative:n,isOdd:u,isZero:l,land:function(t,a){return BigInt(t)&&BigInt(a)},leq:function(t,a){return BigInt(t)<=BigInt(a)},lnot:function(t){return!BigInt(t)},lor:function(t,a){return BigInt(t)||BigInt(a)},lt:function(t,a){return BigInt(t)<BigInt(a)},mod:w,mul:m,naf:function(t){let a=BigInt(t);const e=[];for(;a;){if(a&BigInt(1)){const t=2-Number(a%BigInt(4));e.push(t),a-=BigInt(t)}else e.push(0);a>>=BigInt(1)}return e},neg:p,neq:function(t,a){return BigInt(t)!=BigInt(a)},one:O,pow:L,shiftLeft:c,shiftRight:s,shl:r,shr:d,square:function(t){return BigInt(t)*BigInt(t)},sub:h,toArray:function(t,a){const e=[];let o=BigInt(t);for(a=BigInt(a);o;)e.unshift(Number(o%a)),o/=a;return e},toLEBuff:S,toNumber:g,toRprBE:I,toRprLE:F,toString:v,zero:P});function G(t,a,e){if(l(e))return t.one;const o=_(e);if(0==o.length)return t.one;let i=a;for(let e=o.length-2;e>=0;e--)i=t.square(i),o[e]&&(i=t.mul(i,a));return i}function T(t){if(t.m%2==1)if(y(w(t.p,4),1))if(y(w(t.p,8),1))if(y(w(t.p,16),1))!function(t){t.sqrt_q=L(t.p,t.m),t.sqrt_s=0,t.sqrt_t=h(t.sqrt_q,1);for(;!u(t.sqrt_t);)t.sqrt_s=t.sqrt_s+1,t.sqrt_t=b(t.sqrt_t,2);let a=t.one;for(;t.eq(a,t.one);){const e=t.random();t.sqrt_z=t.pow(e,t.sqrt_t),a=t.pow(t.sqrt_z,2**(t.sqrt_s-1))}t.sqrt_tm1d2=b(h(t.sqrt_t,1),2),t.sqrt=function(t){const a=this;if(a.isZero(t))return a.zero;let e=a.pow(t,a.sqrt_tm1d2);const o=a.pow(a.mul(a.square(e),t),2**(a.sqrt_s-1));if(a.eq(o,a.negone))return null;let i=a.sqrt_s,n=a.mul(t,e),l=a.mul(n,e),c=a.sqrt_z;for(;!a.eq(l,a.one);){let t=a.square(l),o=1;for(;!a.eq(t,a.one);)t=a.square(t),o++;e=c;for(let t=0;t<i-o-1;t++)e=a.square(e);c=a.square(e),l=a.mul(l,c),n=a.mul(n,e),i=o}return a.geq(n,a.zero)?n:a.neg(n)}}(t);else{if(!y(w(t.p,16),9))throw new Error("Field withot sqrt");!function(t){t.sqrt=function(){throw new Error("Sqrt alg 4 not implemented")}}(t)}else{if(!y(w(t.p,8),5))throw new Error("Field withot sqrt");!function(t){t.sqrt=function(){throw new Error("Sqrt alg 3 not implemented")}}(t)}else y(w(t.p,4),3)&&function(t){t.sqrt_q=L(t.p,t.m),t.sqrt_e1=b(h(t.sqrt_q,3),4),t.sqrt=function(a){if(this.isZero(a))return this.zero;const e=this.pow(a,this.sqrt_e1),o=this.mul(this.square(e),a);if(this.eq(o,this.negone))return null;const i=this.mul(e,a);return t.geq(i,t.zero)?i:t.neg(i)}}(t);else{const a=w(L(t.p,t.m/2),4);1==a?function(t){t.sqrt=function(){throw new Error("Sqrt alg 10 not implemented")}}(t):3==a?function(t){t.sqrt_q=L(t.p,t.m/2),t.sqrt_e34=b(h(t.sqrt_q,3),4),t.sqrt_e12=b(h(t.sqrt_q,1),2),t.frobenius=function(a,e){return a%2==1?t.conjugate(e):e},t.sqrt=function(t){const a=this,e=a.pow(t,a.sqrt_e34),o=a.mul(a.square(e),t),i=a.mul(a.frobenius(1,o),o);if(a.eq(i,a.negone))return null;const n=a.mul(e,t);let l;if(a.eq(o,a.negone))l=a.mul(n,[a.F.zero,a.F.one]);else{const t=a.pow(a.add(a.one,o),a.sqrt_e12);l=a.mul(t,n)}return a.geq(l,a.zero)?l:a.neg(l)}}(t):function(t){t.sqrt=function(){throw new Error("Sqrt alg 8 not implemented")}}(t)}}function z(t,a,e,o,i){t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<16|t[i]>>>16&65535)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<12|t[e]>>>20&4095)>>>0,t[a]=t[a]+t[e]>>>0,t[i]=(t[i]^t[a])>>>0,t[i]=(t[i]<<8|t[i]>>>24&255)>>>0,t[o]=t[o]+t[i]>>>0,t[e]=(t[e]^t[o])>>>0,t[e]=(t[e]<<7|t[e]>>>25&127)>>>0}class M{constructor(t){t=t||[0,0,0,0,0,0,0,0],this.state=[1634760805,857760878,2036477234,1797285236,t[0],t[1],t[2],t[3],t[4],t[5],t[6],t[7],0,0,0,0],this.idx=16,this.buff=new Array(16)}nextU32(){return 16==this.idx&&this.update(),this.buff[this.idx++]}nextU64(){return f(m(this.nextU32(),4294967296),this.nextU32())}nextBool(){return 1==(1&this.nextU32())}update(){for(let t=0;t<16;t++)this.buff[t]=this.state[t];for(let a=0;a<10;a++)z(t=this.buff,0,4,8,12),z(t,1,5,9,13),z(t,2,6,10,14),z(t,3,7,11,15),z(t,0,5,10,15),z(t,1,6,11,12),z(t,2,7,8,13),z(t,3,4,9,14);var t;for(let t=0;t<16;t++)this.buff[t]=this.buff[t]+this.state[t]>>>0;this.idx=0,this.state[12]=this.state[12]+1>>>0,0==this.state[12]&&(this.state[13]=this.state[13]+1>>>0,0==this.state[13]&&(this.state[14]=this.state[14]+1>>>0,0==this.state[14]&&(this.state[15]=this.state[15]+1>>>0)))}}function U(t){let a=new Uint8Array(t);if(void 0!==globalThis.crypto)globalThis.crypto.getRandomValues(a);else for(let e=0;e<t;e++)a[e]=4294967296*Math.random()>>>0;return a}let Q=null;function k(){return Q||(Q=new M(function(){const t=U(32),a=new Uint32Array(t.buffer),e=[];for(let t=0;t<8;t++)e.push(a[t]);return e}()),Q)}class R{constructor(t,a,e){this.F=a,this.G=t,this.opMulGF=e;let o=a.sqrt_t||a.t,i=a.sqrt_s||a.s,n=a.one;for(;a.eq(a.pow(n,a.half),a.one);)n=a.add(n,a.one);this.w=new Array(i+1),this.wi=new Array(i+1),this.w[i]=this.F.pow(n,o),this.wi[i]=this.F.inv(this.w[i]);let l=i-1;for(;l>=0;)this.w[l]=this.F.square(this.w[l+1]),this.wi[l]=this.F.square(this.wi[l+1]),l--;this.roots=[],this._setRoots(Math.min(i,15))}_setRoots(t){for(let a=t;a>=0&&!this.roots[a];a--){let t=this.F.one;const e=1<<a,o=new Array(e);for(let i=0;i<e;i++)o[i]=t,t=this.F.mul(t,this.w[a]);this.roots[a]=o}}fft(t){if(t.length<=1)return t;const a=N(t.length-1)+1;this._setRoots(a);const e=1<<a;if(t.length!=e)throw new Error("Size must be multiple of 2");return D(this,t,a,0,1)}ifft(t){if(t.length<=1)return t;const a=N(t.length-1)+1;this._setRoots(a);const e=1<<a;if(t.length!=e)throw new Error("Size must be multiple of 2");const o=D(this,t,a,0,1),i=this.F.inv(this.F.mulScalar(this.F.one,e)),n=new Array(e);for(let t=0;t<e;t++)n[t]=this.opMulGF(o[(e-t)%e],i);return n}}function N(t){return(0!=(4294901760&t)?(t&=4294901760,16):0)|(0!=(4278255360&t)?(t&=4278255360,8):0)|(0!=(4042322160&t)?(t&=4042322160,4):0)|(0!=(3435973836&t)?(t&=3435973836,2):0)|0!=(2863311530&t)}function D(t,a,e,o,i){const n=1<<e;if(1==n)return[a[o]];if(2==n)return[t.G.add(a[o],a[o+i]),t.G.sub(a[o],a[o+i])];const l=n>>1,c=D(t,a,e-1,o,2*i),s=D(t,a,e-1,o+i,2*i),r=new Array(n);for(let a=0;a<l;a++)r[a]=t.G.add(c[a],t.opMulGF(s[a],t.roots[e][a])),r[a+l]=t.G.sub(c[a],t.opMulGF(s[a],t.roots[e][a]));return r}class ${constructor(t){this.type="F1",this.one=BigInt(1),this.zero=BigInt(0),this.p=BigInt(t),this.m=1,this.negone=this.p-this.one,this.two=BigInt(2),this.half=this.p>>this.one,this.bitLength=i(this.p),this.mask=(this.one<<BigInt(this.bitLength))-this.one,this.n64=Math.floor((this.bitLength-1)/64)+1,this.n32=2*this.n64,this.n8=8*this.n64,this.R=this.e(this.one<<BigInt(64*this.n64)),this.Ri=this.inv(this.R);const a=this.negone>>this.one;this.nqr=this.two;let e=this.pow(this.nqr,a);for(;!this.eq(e,this.negone);)this.nqr=this.nqr+this.one,e=this.pow(this.nqr,a);for(this.s=0,this.t=this.negone;(this.t&this.one)==this.zero;)this.s=this.s+1,this.t=this.t>>this.one;this.nqr_to_t=this.pow(this.nqr,this.t),T(this),this.FFT=new R(this,this,this.mul.bind(this)),this.fft=this.FFT.fft.bind(this.FFT),this.ifft=this.FFT.ifft.bind(this.FFT),this.w=this.FFT.w,this.wi=this.FFT.wi,this.shift=this.square(this.nqr),this.k=this.exp(this.nqr,2**this.s)}e(t,a){let e;if(a?16==a&&(e=BigInt("0x"+t)):e=BigInt(t),e<0){let t=-e;return t>=this.p&&(t%=this.p),this.p-t}return e>=this.p?e%this.p:e}add(t,a){const e=t+a;return e>=this.p?e-this.p:e}sub(t,a){return t>=a?t-a:this.p-a+t}neg(t){return t?this.p-t:t}mul(t,a){return t*a%this.p}mulScalar(t,a){return t*this.e(a)%this.p}square(t){return t*t%this.p}eq(t,a){return t==a}neq(t,a){return t!=a}lt(t,a){return(t>this.half?t-this.p:t)<(a>this.half?a-this.p:a)}gt(t,a){return(t>this.half?t-this.p:t)>(a>this.half?a-this.p:a)}leq(t,a){return(t>this.half?t-this.p:t)<=(a>this.half?a-this.p:a)}geq(t,a){return(t>this.half?t-this.p:t)>=(a>this.half?a-this.p:a)}div(t,a){return this.mul(t,this.inv(a))}idiv(t,a){if(!a)throw new Error("Division by zero");return t/a}inv(t){if(!t)throw new Error("Division by zero");let a=this.zero,e=this.p,o=this.one,i=t%this.p;for(;i;){let t=e/i;[a,o]=[o,a-t*o],[e,i]=[i,e-t*i]}return a<this.zero&&(a+=this.p),a}mod(t,a){return t%a}pow(t,a){return G(this,t,a)}exp(t,a){return G(this,t,a)}band(t,a){const e=t&a&this.mask;return e>=this.p?e-this.p:e}bor(t,a){const e=(t|a)&this.mask;return e>=this.p?e-this.p:e}bxor(t,a){const e=(t^a)&this.mask;return e>=this.p?e-this.p:e}bnot(t){const a=t^this.mask;return a>=this.p?a-this.p:a}shl(t,a){if(Number(a)<this.bitLength){const e=t<<a&this.mask;return e>=this.p?e-this.p:e}{const e=this.p-a;return Number(e)<this.bitLength?t>>e:this.zero}}shr(t,a){if(Number(a)<this.bitLength)return t>>a;{const e=this.p-a;if(Number(e)<this.bitLength){const a=t<<e&this.mask;return a>=this.p?a-this.p:a}return 0}}land(t,a){return t&&a?this.one:this.zero}lor(t,a){return t||a?this.one:this.zero}lnot(t){return t?this.zero:this.one}sqrt_old(t){if(t==this.zero)return this.zero;if(this.pow(t,this.negone>>this.one)!=this.one)return null;let a=this.s,e=this.nqr_to_t,o=this.pow(t,this.t),i=this.pow(t,this.add(this.t,this.one)>>this.one);for(;o!=this.one;){let t=this.square(o),n=1;for(;t!=this.one;)n++,t=this.square(t);let l=e;for(let t=0;t<a-n-1;t++)l=this.square(l);a=n,e=this.square(l),o=this.mul(o,e),i=this.mul(i,l)}return i>this.p>>this.one&&(i=this.neg(i)),i}normalize(t,a){if((t=BigInt(t,a))<0){let a=-t;return a>=this.p&&(a%=this.p),this.p-a}return t>=this.p?t%this.p:t}random(){const t=2*this.bitLength/8;let a=this.zero;for(let e=0;e<t;e++)a=(a<<BigInt(8))+BigInt(U(1)[0]);return a%this.p}toString(t,a){let e;if(a=a||10,t>this.half&&10==a){e="-"+(this.p-t).toString(a)}else e=t.toString(a);return e}isZero(t){return t==this.zero}fromRng(t){let a;do{a=this.zero;for(let e=0;e<this.n64;e++)a+=t.nextU64()<<BigInt(64*e);a&=this.mask}while(a>=this.p);return a=a*this.Ri%this.p,a}fft(t){return this.FFT.fft(t)}ifft(t){return this.FFT.ifft(t)}toRprLE(t,a,e){F(t,a,e,8*this.n64)}toRprBE(t,a,e){I(t,a,e,8*this.n64)}toRprBEM(t,a,e){return this.toRprBE(t,a,this.mul(this.R,e))}toRprLEM(t,a,e){return this.toRprLE(t,a,this.mul(this.R,e))}fromRprLE(t,a){return B(t,a,this.n8)}fromRprBE(t,a){return E(t,a,this.n8)}fromRprLEM(t,a){return this.mul(this.fromRprLE(t,a),this.Ri)}fromRprBEM(t,a){return this.mul(this.fromRprBE(t,a),this.Ri)}toObject(t){return t}}var j={bigInt2BytesLE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t<a;t++)e[t]=Number(0xFFn&o),o>>=8n;return e},bigInt2U32LE:function(t,a){const e=Array(a);let o=BigInt(t);for(let t=0;t<a;t++)e[t]=Number(0xFFFFFFFFn&o),o>>=32n;return e},isOcamNum:function(t){return!!Array.isArray(t)&&(3==t.length&&("number"==typeof t[0]&&("number"==typeof t[1]&&!!Array.isArray(t[2]))))}},V=function(t,a,e,o,i,n,l){const c=t.addFunction(a);c.addParam("base","i32"),c.addParam("scalar","i32"),c.addParam("scalarLength","i32"),c.addParam("r","i32"),c.addLocal("i","i32"),c.addLocal("b","i32");const s=c.getCodeBuilder(),r=s.i32_const(t.alloc(e));c.addCode(s.if(s.i32_eqz(s.getLocal("scalarLength")),[...s.call(l,s.getLocal("r")),...s.ret([])])),c.addCode(s.call(n,s.getLocal("base"),r)),c.addCode(s.call(l,s.getLocal("r"))),c.addCode(s.setLocal("i",s.getLocal("scalarLength"))),c.addCode(s.block(s.loop(s.setLocal("i",s.i32_sub(s.getLocal("i"),s.i32_const(1))),s.setLocal("b",s.i32_load8_u(s.i32_add(s.getLocal("scalar"),s.getLocal("i")))),...function(){const t=[];for(let a=0;a<8;a++)t.push(...s.call(i,s.getLocal("r"),s.getLocal("r")),...s.if(s.i32_ge_u(s.getLocal("b"),s.i32_const(128>>a)),[...s.setLocal("b",s.i32_sub(s.getLocal("b"),s.i32_const(128>>a))),...s.call(o,s.getLocal("r"),r,s.getLocal("r"))]));return t}(),s.br_if(1,s.i32_eqz(s.getLocal("i"))),s.br(0))))},K=function(t,a){const e=8*t.modules[a].n64,o=t.addFunction(a+"_batchInverse");o.addParam("pIn","i32"),o.addParam("inStep","i32"),o.addParam("n","i32"),o.addParam("pOut","i32"),o.addParam("outStep","i32"),o.addLocal("itAux","i32"),o.addLocal("itIn","i32"),o.addLocal("itOut","i32"),o.addLocal("i","i32");const i=o.getCodeBuilder(),n=i.i32_const(t.alloc(e));o.addCode(i.setLocal("itAux",i.i32_load(i.i32_const(0))),i.i32_store(i.i32_const(0),i.i32_add(i.getLocal("itAux"),i.i32_mul(i.i32_add(i.getLocal("n"),i.i32_const(1)),i.i32_const(e))))),o.addCode(i.call(a+"_one",i.getLocal("itAux")),i.setLocal("itIn",i.getLocal("pIn")),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_const(0)),i.block(i.loop(i.br_if(1,i.i32_eq(i.getLocal("i"),i.getLocal("n"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux")),i.call(a+"_mul",i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),i.getLocal("itAux"))),i.setLocal("itIn",i.i32_add(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_add(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_add(i.getLocal("i"),i.i32_const(1))),i.br(0))),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("itOut",i.i32_add(i.getLocal("pOut"),i.i32_mul(i.i32_sub(i.getLocal("n"),i.i32_const(1)),i.getLocal("outStep")))),i.call(a+"_inverse",i.getLocal("itAux"),i.getLocal("itAux")),i.block(i.loop(i.br_if(1,i.i32_eqz(i.getLocal("i"))),i.if(i.call(a+"_isZero",i.getLocal("itIn")),[...i.call(a+"_copy",i.getLocal("itAux"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_zero",i.getLocal("itOut"))],[...i.call(a+"_copy",i.i32_sub(i.getLocal("itAux"),i.i32_const(e)),n),...i.call(a+"_mul",i.getLocal("itAux"),i.getLocal("itIn"),i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),...i.call(a+"_mul",i.getLocal("itAux"),n,i.getLocal("itOut"))]),i.setLocal("itIn",i.i32_sub(i.getLocal("itIn"),i.getLocal("inStep"))),i.setLocal("itOut",i.i32_sub(i.getLocal("itOut"),i.getLocal("outStep"))),i.setLocal("itAux",i.i32_sub(i.getLocal("itAux"),i.i32_const(e))),i.setLocal("i",i.i32_sub(i.getLocal("i"),i.i32_const(1))),i.br(0)))),o.addCode(i.i32_store(i.i32_const(0),i.getLocal("itAux")))};var H=function(t,a,e,o,i,n){void 0===n&&(n=o<i);const l=t.addFunction(a);l.addParam("pIn","i32"),l.addParam("n","i32"),l.addParam("pOut","i32"),l.addLocal("i","i32"),l.addLocal("itIn","i32"),l.addLocal("itOut","i32");const c=l.getCodeBuilder();n?l.addCode(c.setLocal("itIn",c.i32_add(c.getLocal("pIn"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(o)))),c.setLocal("itOut",c.i32_add(c.getLocal("pOut"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(i)))),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(e,c.getLocal("itIn"),c.getLocal("itOut")),c.setLocal("itIn",c.i32_sub(c.getLocal("itIn"),c.i32_const(o))),c.setLocal("itOut",c.i32_sub(c.getLocal("itOut"),c.i32_const(i))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0)))):l.addCode(c.setLocal("itIn",c.getLocal("pIn")),c.setLocal("itOut",c.getLocal("pOut")),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(e,c.getLocal("itIn"),c.getLocal("itOut")),c.setLocal("itIn",c.i32_add(c.getLocal("itIn"),c.i32_const(o))),c.setLocal("itOut",c.i32_add(c.getLocal("itOut"),c.i32_const(i))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))))};var Z=function(t,a,e,o,i,n){void 0===n&&(n=o<i);const l=t.addFunction(a);l.addParam("pIn1","i32"),l.addParam("pIn2","i32"),l.addParam("n","i32"),l.addParam("pOut","i32"),l.addLocal("i","i32"),l.addLocal("itIn1","i32"),l.addLocal("itIn2","i32"),l.addLocal("itOut","i32");const c=l.getCodeBuilder();n?l.addCode(c.setLocal("itIn1",c.i32_add(c.getLocal("pIn1"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(o)))),c.setLocal("itIn2",c.i32_add(c.getLocal("pIn2"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(o)))),c.setLocal("itOut",c.i32_add(c.getLocal("pOut"),c.i32_mul(c.i32_sub(c.getLocal("n"),c.i32_const(1)),c.i32_const(i)))),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(e,c.getLocal("itIn1"),c.getLocal("itIn2"),c.getLocal("itOut")),c.setLocal("itIn1",c.i32_sub(c.getLocal("itIn1"),c.i32_const(o))),c.setLocal("itIn2",c.i32_sub(c.getLocal("itIn2"),c.i32_const(o))),c.setLocal("itOut",c.i32_sub(c.getLocal("itOut"),c.i32_const(i))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0)))):l.addCode(c.setLocal("itIn1",c.getLocal("pIn1")),c.setLocal("itIn2",c.getLocal("pIn2")),c.setLocal("itOut",c.getLocal("pOut")),c.setLocal("i",c.i32_const(0)),c.block(c.loop(c.br_if(1,c.i32_eq(c.getLocal("i"),c.getLocal("n"))),c.call(e,c.getLocal("itIn1"),c.getLocal("itIn2"),c.getLocal("itOut")),c.setLocal("itIn1",c.i32_add(c.getLocal("itIn1"),c.i32_const(o))),c.setLocal("itIn2",c.i32_add(c.getLocal("itIn2"),c.i32_const(o))),c.setLocal("itOut",c.i32_add(c.getLocal("itOut"),c.i32_const(i))),c.setLocal("i",c.i32_add(c.getLocal("i"),c.i32_const(1))),c.br(0))))};var W={};function Y(t,a){return t===a?0:t>a?1:-1}function J(t){return t*t}function X(t){return t%2n!==0n}function tt(t){return t%2n===0n}function at(t){return t<0n}function et(t){return t>0n}function ot(t){return at(t)?t.toString(2).length-1:t.toString(2).length}function it(t){return t<0n?-t:t}function nt(t){return 1n===it(t)}function lt(t,a){for(var e,o,i,n=0n,l=1n,c=a,s=it(t);0n!==s;)e=c/s,o=n,i=c,n=l,c=s,l=o-e*l,s=i-e*s;if(!nt(c))throw new Error(t.toString()+" and "+a.toString()+" are not co-prime");return-1===Y(n,0n)&&(n+=a),at(t)?-n:n}function ct(t,a,e){if(0n===e)throw new Error("Cannot take modPow with modulus 0");var o=1n,i=t%e;for(at(a)&&(a*=-1n,i=lt(i,e));et(a);){if(0n===i)return 0n;X(a)&&(o=o*i%e),a/=2n,i=J(i)%e}return o}function st(t,a){return 0n!==a&&(!!nt(a)||(0===function(t,a){return(t=t>=0n?t:-t)===(a=a>=0n?a:-a)?0:t>a?1:-1}(a,2n)?tt(t):t%a===0n))}function rt(t,a){for(var e,o,i,n=function(t){return t-1n}(t),l=n,c=0;tt(l);)l/=2n,c++;t:for(o=0;o<a.length;o++)if(!(t<a[o]||nt(i=ct(BigInt(a[o]),l,t))||i===n)){for(e=c-1;0!=e;e--){if(nt(i=J(i)%t))return!1;if(i===n)continue t}return!1}return!0}W.bitLength=ot,W.isOdd=X,W.isNegative=at,W.abs=it,W.isUnit=nt,W.compare=Y,W.modInv=lt,W.modPow=ct,W.isPrime=function(t){var a=function(t){var a=it(t);return!nt(a)&&(2n===a||3n===a||5n===a||!(tt(a)||st(a,3n)||st(a,5n))&&(a<49n||void 0))}(t);if(void 0!==a)return a;var e=it(t),o=ot(e);if(o<=64)return rt(e,[2,3,5,7,11,13,17,19,23,29,31,37]);for(var i=Math.log(2)*Number(o),n=Math.ceil(i),l=[],c=0;c<n;c++)l.push(BigInt(c+2));return rt(e,l)},W.square=J;const dt=function(t,a,e){const o=e||"int";if(t.modules[o])return o;t.modules[o]={};const i=2*a,n=8*a;return function(){const e=t.addFunction(o+"_copy");e.addParam("px","i32"),e.addParam("pr","i32");const i=e.getCodeBuilder();for(let t=0;t<a;t++)e.addCode(i.i64_store(i.getLocal("pr"),8*t,i.i64_load(i.getLocal("px"),8*t)))}(),function(){const e=t.addFunction(o+"_zero");e.addParam("pr","i32");const i=e.getCodeBuilder();for(let t=0;t<a;t++)e.addCode(i.i64_store(i.getLocal("pr"),8*t,i.i64_const(0)))}(),function(){const e=t.addFunction(o+"_isZero");e.addParam("px","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(function t(a){return 0==a?i.ret(i.i64_eqz(i.i64_load(i.getLocal("px")))):i.if(i.i64_eqz(i.i64_load(i.getLocal("px"),8*a)),t(a-1),i.ret(i.i32_const(0)))}(a-1)),e.addCode(i.ret(i.i32_const(0)))}(),function(){const e=t.addFunction(o+"_one");e.addParam("pr","i32");const i=e.getCodeBuilder();e.addCode(i.i64_store(i.getLocal("pr"),0,i.i64_const(1)));for(let t=1;t<a;t++)e.addCode(i.i64_store(i.getLocal("pr"),8*t,i.i64_const(0)))}(),function(){const e=t.addFunction(o+"_eq");e.addParam("px","i32"),e.addParam("py","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(function t(a){return 0==a?i.ret(i.i64_eq(i.i64_load(i.getLocal("px")),i.i64_load(i.getLocal("py")))):i.if(i.i64_eq(i.i64_load(i.getLocal("px"),8*a),i.i64_load(i.getLocal("py"),8*a)),t(a-1),i.ret(i.i32_const(0)))}(a-1)),e.addCode(i.ret(i.i32_const(0)))}(),function(){const e=t.addFunction(o+"_gte");e.addParam("px","i32"),e.addParam("py","i32"),e.setReturnType("i32");const i=e.getCodeBuilder();e.addCode(function t(a){return 0==a?i.ret(i.i64_ge_u(i.i64_load(i.getLocal("px")),i.i64_load(i.getLocal("py")))):i.if(i.i64_lt_u(i.i64_load(i.getLocal("px"),8*a),i.i64_load(i.getLocal("py"),8*a)),i.ret(i.i32_const(0)),i.if(i.i64_gt_u(i.i64_load(i.getLocal("px"),8*a),i.i64_load(i.getLocal("py"),8*a)),i.ret(i.i32_const(1)),t(a-1)))}(a-1)),e.addCode(i.ret(i.i32_const(0)))}(),function(){const a=t.addFunction(o+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.setReturnType("i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_add(e.i64_load32_u(e.getLocal("x")),e.i64_load32_u(e.getLocal("y"))))),a.addCode(e.i64_store32(e.getLocal("r"),e.getLocal("c")));for(let t=1;t<i;t++)a.addCode(e.setLocal("c",e.i64_add(e.i64_add(e.i64_load32_u(e.getLocal("x"),4*t),e.i64_load32_u(e.getLocal("y"),4*t)),e.i64_shr_u(e.getLocal("c"),e.i64_const(32))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal("c")));a.addCode(e.i32_wrap_i64(e.i64_shr_u(e.getLocal("c"),e.i64_const(32))))}(),function(){const a=t.addFunction(o+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.setReturnType("i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_sub(e.i64_load32_u(e.getLocal("x")),e.i64_load32_u(e.getLocal("y"))))),a.addCode(e.i64_store32(e.getLocal("r"),e.i64_and(e.getLocal("c"),e.i64_const("0xFFFFFFFF"))));for(let t=1;t<i;t++)a.addCode(e.setLocal("c",e.i64_add(e.i64_sub(e.i64_load32_u(e.getLocal("x"),4*t),e.i64_load32_u(e.getLocal("y"),4*t)),e.i64_shr_s(e.getLocal("c"),e.i64_const(32))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.i64_and(e.getLocal("c"),e.i64_const("0xFFFFFFFF"))));a.addCode(e.i32_wrap_i64(e.i64_shr_s(e.getLocal("c"),e.i64_const(32))))}(),function(){const a=t.addFunction(o+"_mul");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64");for(let t=0;t<i;t++)a.addLocal("x"+t,"i64"),a.addLocal("y"+t,"i64");const e=a.getCodeBuilder(),n=[],l=[];function c(t,a){let o,i;return n[t]?o=e.getLocal("x"+t):(o=e.teeLocal("x"+t,e.i64_load32_u(e.getLocal("x"),4*t)),n[t]=!0),l[a]?i=e.getLocal("y"+a):(i=e.teeLocal("y"+a,e.i64_load32_u(e.getLocal("y"),4*a)),l[a]=!0),e.i64_mul(o,i)}let s="c0",r="c1";for(let t=0;t<2*i-1;t++){for(let o=Math.max(0,t-i+1);o<=t&&o<i;o++){const i=t-o;a.addCode(e.setLocal(s,e.i64_add(e.i64_and(e.getLocal(s),e.i64_const(4294967295)),c(o,i)))),a.addCode(e.setLocal(r,e.i64_add(e.getLocal(r),e.i64_shr_u(e.getLocal(s),e.i64_const(32)))))}a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(s))),[s,r]=[r,s],a.addCode(e.setLocal(r,e.i64_shr_u(e.getLocal(s),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(s)))}(),function(){const a=t.addFunction(o+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64");for(let t=0;t<i;t++)a.addLocal("x"+t,"i64");const e=a.getCodeBuilder(),n=[];function l(t,a){let o,i;return n[t]?o=e.getLocal("x"+t):(o=e.teeLocal("x"+t,e.i64_load32_u(e.getLocal("x"),4*t)),n[t]=!0),n[a]?i=e.getLocal("x"+a):(i=e.teeLocal("x"+a,e.i64_load32_u(e.getLocal("x"),4*a)),n[a]=!0),e.i64_mul(o,i)}let c="c0",s="c1",r="c0_old",d="c1_old";for(let t=0;t<2*i-1;t++){a.addCode(e.setLocal(c,e.i64_const(0)),e.setLocal(s,e.i64_const(0)));for(let o=Math.max(0,t-i+1);o<t+1>>1&&o<i;o++){const i=t-o;a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),l(o,i)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))}a.addCode(e.setLocal(c,e.i64_shl(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_const(1)))),a.addCode(e.setLocal(s,e.i64_add(e.i64_shl(e.getLocal(s),e.i64_const(1)),e.i64_shr_u(e.getLocal(c),e.i64_const(32))))),t%2==0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),l(t>>1,t>>1)))),a.addCode(e.setLocal(s,e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(c,e.i64_add(e.i64_and(e.getLocal(c),e.i64_const(4294967295)),e.i64_and(e.getLocal(r),e.i64_const(4294967295))))),a.addCode(e.setLocal(s,e.i64_add(e.i64_add(e.getLocal(s),e.i64_shr_u(e.getLocal(c),e.i64_const(32))),e.getLocal(d))))),a.addCode(e.i64_store32(e.getLocal("r"),4*t,e.getLocal(c))),a.addCode(e.setLocal(r,e.getLocal(s)),e.setLocal(d,e.i64_shr_u(e.getLocal(r),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*i*2-4,e.getLocal(r)))}(),function(){const a=t.addFunction(o+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(o+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){!function(){const a=t.addFunction(o+"__mul1");a.addParam("px","i32"),a.addParam("y","i64"),a.addParam("pr","i32"),a.addLocal("c","i64");const e=a.getCodeBuilder();a.addCode(e.setLocal("c",e.i64_mul(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("pr"),0,0,e.getLocal("c")));for(let t=1;t<i;t++)a.addCode(e.setLocal("c",e.i64_add(e.i64_mul(e.i64_load32_u(e.getLocal("px"),4*t,0),e.getLocal("y")),e.i64_shr_u(e.getLocal("c"),e.i64_const(32))))),a.addCode(e.i64_store32(e.getLocal("pr"),4*t,0,e.getLocal("c")))}(),function(){const a=t.addFunction(o+"__add1");a.addParam("x","i32"),a.addParam("y","i64"),a.addLocal("c","i64"),a.addLocal("px","i32");const e=a.getCodeBuilder();a.addCode(e.setLocal("px",e.getLocal("x"))),a.addCode(e.setLocal("c",e.i64_add(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("y")))),a.addCode(e.i64_store32(e.getLocal("px"),0,0,e.getLocal("c"))),a.addCode(e.setLocal("c",e.i64_shr_u(e.getLocal("c"),e.i64_const(32)))),a.addCode(e.block(e.loop(e.br_if(1,e.i64_eqz(e.getLocal("c"))),e.setLocal("px",e.i32_add(e.getLocal("px"),e.i32_const(4))),e.setLocal("c",e.i64_add(e.i64_load32_u(e.getLocal("px"),0,0),e.getLocal("c"))),e.i64_store32(e.getLocal("px"),0,0,e.getLocal("c")),e.setLocal("c",e.i64_shr_u(e.getLocal("c"),e.i64_const(32))),e.br(0))))}();const a=t.addFunction(o+"_div");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("c","i32"),a.addParam("r","i32"),a.addLocal("rr","i32"),a.addLocal("cc","i32"),a.addLocal("eX","i32"),a.addLocal("eY","i32"),a.addLocal("sy","i64"),a.addLocal("sx","i64"),a.addLocal("ec","i32");const e=a.getCodeBuilder(),l=e.i32_const(t.alloc(n)),c=e.i32_const(t.alloc(n)),s=e.i32_const(t.alloc(n)),r=e.getLocal("cc"),d=e.getLocal("rr"),u=t.alloc(2*n),_=e.i32_const(u),g=e.i32_const(u+n);a.addCode(e.if(e.getLocal("c"),e.setLocal("cc",e.getLocal("c")),e.setLocal("cc",c))),a.addCode(e.if(e.getLocal("r"),e.setLocal("rr",e.getLocal("r")),e.setLocal("rr",s))),a.addCode(e.call(o+"_copy",e.getLocal("x"),d)),a.addCode(e.call(o+"_copy",e.getLocal("y"),l)),a.addCode(e.call(o+"_zero",r)),a.addCode(e.call(o+"_zero",_)),a.addCode(e.setLocal("eX",e.i32_const(n-1))),a.addCode(e.setLocal("eY",e.i32_const(n-1))),a.addCode(e.block(e.loop(e.br_if(1,e.i32_or(e.i32_load8_u(e.i32_add(l,e.getLocal("eY")),0,0),e.i32_eq(e.getLocal("eY"),e.i32_const(3)))),e.setLocal("eY",e.i32_sub(e.getLocal("eY"),e.i32_const(1))),e.br(0)))),a.addCode(e.setLocal("sy",e.i64_add(e.i64_load32_u(e.i32_sub(e.i32_add(l,e.getLocal("eY")),e.i32_const(3)),0,0),e.i64_const(1)))),a.addCode(e.if(e.i64_eq(e.getLocal("sy"),e.i64_const(1)),e.drop(e.i64_div_u(e.i64_const(0),e.i64_const(0))))),a.addCode(e.block(e.loop(e.block(e.loop(e.br_if(1,e.i32_or(e.i32_load8_u(e.i32_add(d,e.getLocal("eX")),0,0),e.i32_eq(e.getLocal("eX"),e.i32_const(7)))),e.setLocal("eX",e.i32_sub(e.getLocal("eX"),e.i32_const(1))),e.br(0))),e.setLocal("sx",e.i64_load(e.i32_sub(e.i32_add(d,e.getLocal("eX")),e.i32_const(7)),0,0)),e.setLocal("sx",e.i64_div_u(e.getLocal("sx"),e.getLocal("sy"))),e.setLocal("ec",e.i32_sub(e.i32_sub(e.getLocal("eX"),e.getLocal("eY")),e.i32_const(4))),e.block(e.loop(e.br_if(1,e.i32_and(e.i64_eqz(e.i64_and(e.getLocal("sx"),e.i64_const("0xFFFFFFFF00000000"))),e.i32_ge_s(e.getLocal("ec"),e.i32_const(0)))),e.setLocal("sx",e.i64_shr_u(e.getLocal("sx"),e.i64_const(8))),e.setLocal("ec",e.i32_add(e.getLocal("ec"),e.i32_const(1))),e.br(0))),e.if(e.i64_eqz(e.getLocal("sx")),[...e.br_if(2,e.i32_eqz(e.call(o+"_gte",d,l))),...e.setLocal("sx",e.i64_const(1)),...e.setLocal("ec",e.i32_const(0))]),e.call(o+"__mul1",l,e.getLocal("sx"),g),e.drop(e.call(o+"_sub",d,e.i32_sub(g,e.getLocal("ec")),d)),e.call(o+"__add1",e.i32_add(r,e.getLocal("ec")),e.getLocal("sx")),e.br(0))))}(),function(){const a=t.addFunction(o+"_inverseMod");a.addParam("px","i32"),a.addParam("pm","i32"),a.addParam("pr","i32"),a.addLocal("t","i32"),a.addLocal("newt","i32"),a.addLocal("r","i32"),a.addLocal("qq","i32"),a.addLocal("qr","i32"),a.addLocal("newr","i32"),a.addLocal("swp","i32"),a.addLocal("x","i32"),a.addLocal("signt","i32"),a.addLocal("signnewt","i32"),a.addLocal("signx","i32");const e=a.getCodeBuilder(),i=e.i32_const(t.alloc(n)),l=e.i32_const(t.alloc(n)),c=e.i32_const(t.alloc(n)),s=e.i32_const(t.alloc(n)),r=e.i32_const(t.alloc(n)),d=e.i32_const(t.alloc(n)),u=e.i32_const(t.alloc(2*n)),_=e.i32_const(t.alloc(n));a.addCode(e.setLocal("t",i),e.call(o+"_zero",i),e.setLocal("signt",e.i32_const(0))),a.addCode(e.setLocal("r",l),e.call(o+"_copy",e.getLocal("pm"),l)),a.addCode(e.setLocal("newt",c),e.call(o+"_one",c),e.setLocal("signnewt",e.i32_const(0))),a.addCode(e.setLocal("newr",s),e.call(o+"_copy",e.getLocal("px"),s)),a.addCode(e.setLocal("qq",r)),a.addCode(e.setLocal("qr",d)),a.addCode(e.setLocal("x",_)),a.addCode(e.block(e.loop(e.br_if(1,e.call(o+"_isZero",e.getLocal("newr"))),e.call(o+"_div",e.getLocal("r"),e.getLocal("newr"),e.getLocal("qq"),e.getLocal("qr")),e.call(o+"_mul",e.getLocal("qq"),e.getLocal("newt"),u),e.if(e.getLocal("signt"),e.if(e.getLocal("signnewt"),e.if(e.call(o+"_gte",u,e.getLocal("t")),[...e.drop(e.call(o+"_sub",u,e.getLocal("t"),e.getLocal("x"))),...e.setLocal("signx",e.i32_const(0))],[...e.drop(e.call(o+"_sub",e.getLocal("t"),u,e.getLocal("x"))),...e.setLocal("signx",e.i32_const(1))]),[...e.drop(e.call(o+"_add",u,e.getLocal("t"),e.getLocal("x"))),...e.setLocal("signx",e.i32_const(1))]),e.if(e.getLocal("signnewt"),[...e.drop(e.call(o+"_add",u,e.getLocal("t"),e.getLocal("x"))),...e.setLocal("signx",e.i32_const(0))],e.if(e.call(o+"_gte",e.getLocal("t"),u),[...e.drop(e.call(o+"_sub",e.getLocal("t"),u,e.getLocal("x"))),...e.setLocal("signx",e.i32_const(0))],[...e.drop(e.call(o+"_sub",u,e.getLocal("t"),e.getLocal("x"))),...e.setLocal("signx",e.i32_const(1))]))),e.setLocal("swp",e.getLocal("t")),e.setLocal("t",e.getLocal("newt")),e.setLocal("newt",e.getLocal("x")),e.setLocal("x",e.getLocal("swp")),e.setLocal("signt",e.getLocal("signnewt")),e.setLocal("signnewt",e.getLocal("signx")),e.setLocal("swp",e.getLocal("r")),e.setLocal("r",e.getLocal("newr")),e.setLocal("newr",e.getLocal("qr")),e.setLocal("qr",e.getLocal("swp")),e.br(0)))),a.addCode(e.if(e.getLocal("signt"),e.drop(e.call(o+"_sub",e.getLocal("pm"),e.getLocal("t"),e.getLocal("pr"))),e.call(o+"_copy",e.getLocal("t"),e.getLocal("pr"))))}(),t.exportFunction(o+"_copy"),t.exportFunction(o+"_zero"),t.exportFunction(o+"_one"),t.exportFunction(o+"_isZero"),t.exportFunction(o+"_eq"),t.exportFunction(o+"_gte"),t.exportFunction(o+"_add"),t.exportFunction(o+"_sub"),t.exportFunction(o+"_mul"),t.exportFunction(o+"_square"),t.exportFunction(o+"_squareOld"),t.exportFunction(o+"_div"),t.exportFunction(o+"_inverseMod"),o},ut=j,_t=V,gt=K,ft=H,ht=Z,{bitLength:pt,modInv:mt,modPow:Lt,isPrime:bt,isOdd:wt,square:yt}=W;var At=function(t,a,e,o){const i=BigInt(a),n=Math.floor((pt(i-1n)-1)/64)+1,l=2*n,c=8*n,s=e||"f1m";if(t.modules[s])return s;const r=dt(t,n,o),d=t.alloc(c,ut.bigInt2BytesLE(i,c)),u=t.alloc(ut.bigInt2BytesLE(yt(1n<<BigInt(64*n))%i,c)),_=t.alloc(ut.bigInt2BytesLE((1n<<BigInt(64*n))%i,c)),g=t.alloc(ut.bigInt2BytesLE(0n,c)),f=i-1n,h=f>>1n,p=t.alloc(c,ut.bigInt2BytesLE(h,c)),m=h+1n,L=t.alloc(c,ut.bigInt2BytesLE(m,c));t.modules[s]={pq:d,pR2:u,n64:n,q:i,pOne:_,pZero:g,pePlusOne:L};let b=2n;if(bt(i))for(;Lt(b,h,i)!==f;)b+=1n;let w=0,y=f;for(;!wt(y)&&0n!==y;)w++,y>>=1n;const A=t.alloc(c,ut.bigInt2BytesLE(y,c)),C=Lt(b,y,i),x=t.alloc(ut.bigInt2BytesLE((C<<BigInt(64*n))%i,c)),F=y+1n>>1n,I=t.alloc(c,ut.bigInt2BytesLE(F,c));return t.exportFunction(r+"_copy",s+"_copy"),t.exportFunction(r+"_zero",s+"_zero"),t.exportFunction(r+"_isZero",s+"_isZero"),t.exportFunction(r+"_eq",s+"_eq"),function(){const a=t.addFunction(s+"_isOne");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.ret(e.call(r+"_eq",e.getLocal("x"),e.i32_const(_))))}(),function(){const a=t.addFunction(s+"_add");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_add",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_sub");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.if(e.call(r+"_sub",e.getLocal("x"),e.getLocal("y"),e.getLocal("r")),e.drop(e.call(r+"_add",e.getLocal("r"),e.i32_const(d),e.getLocal("r")))))}(),function(){const a=t.addFunction(s+"_neg");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_sub",e.i32_const(g),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.alloc(l*l*8),e=t.addFunction(s+"_mReduct");e.addParam("t","i32"),e.addParam("r","i32"),e.addLocal("np32","i64"),e.addLocal("c","i64"),e.addLocal("m","i64");const o=e.getCodeBuilder(),n=Number(0x100000000n-mt(i,0x100000000n));e.addCode(o.setLocal("np32",o.i64_const(n)));for(let t=0;t<l;t++){e.addCode(o.setLocal("c",o.i64_const(0))),e.addCode(o.setLocal("m",o.i64_and(o.i64_mul(o.i64_load32_u(o.getLocal("t"),4*t),o.getLocal("np32")),o.i64_const("0xFFFFFFFF"))));for(let a=0;a<l;a++)e.addCode(o.setLocal("c",o.i64_add(o.i64_add(o.i64_load32_u(o.getLocal("t"),4*(t+a)),o.i64_shr_u(o.getLocal("c"),o.i64_const(32))),o.i64_mul(o.i64_load32_u(o.i32_const(d),4*a),o.getLocal("m"))))),e.addCode(o.i64_store32(o.getLocal("t"),4*(t+a),o.getLocal("c")));e.addCode(o.i64_store32(o.i32_const(a),4*t,o.i64_shr_u(o.getLocal("c"),o.i64_const(32))))}e.addCode(o.call(s+"_add",o.i32_const(a),o.i32_add(o.getLocal("t"),o.i32_const(4*l)),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_mul");a.addParam("x","i32"),a.addParam("y","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("np32","i64");for(let t=0;t<l;t++)a.addLocal("x"+t,"i64"),a.addLocal("y"+t,"i64"),a.addLocal("m"+t,"i64"),a.addLocal("q"+t,"i64");const e=a.getCodeBuilder(),o=Number(0x100000000n-mt(i,0x100000000n));a.addCode(e.setLocal("np32",e.i64_const(o)));const n=[],c=[],u=[];function _(t,a){let o,i;return n[t]?o=e.getLocal("x"+t):(o=e.teeLocal("x"+t,e.i64_load32_u(e.getLocal("x"),4*t)),n[t]=!0),c[a]?i=e.getLocal("y"+a):(i=e.teeLocal("y"+a,e.i64_load32_u(e.getLocal("y"),4*a)),c[a]=!0),e.i64_mul(o,i)}function g(t,a){let o,i;return u[t]?o=e.getLocal("q"+t):(o=e.teeLocal("q"+t,e.i64_load32_u(e.i32_const(0),d+4*t)),u[t]=!0),i=e.getLocal("m"+a),e.i64_mul(o,i)}let f="c0",h="c1";for(let t=0;t<2*l-1;t++){for(let o=Math.max(0,t-l+1);o<=t&&o<l;o++){const i=t-o;a.addCode(e.setLocal(f,e.i64_add(e.i64_and(e.getLocal(f),e.i64_const(4294967295)),_(o,i)))),a.addCode(e.setLocal(h,e.i64_add(e.getLocal(h),e.i64_shr_u(e.getLocal(f),e.i64_const(32)))))}for(let o=Math.max(1,t-l+1);o<=t&&o<l;o++){const i=t-o;a.addCode(e.setLocal(f,e.i64_add(e.i64_and(e.getLocal(f),e.i64_const(4294967295)),g(o,i)))),a.addCode(e.setLocal(h,e.i64_add(e.getLocal(h),e.i64_shr_u(e.getLocal(f),e.i64_const(32)))))}t<l&&(a.addCode(e.setLocal("m"+t,e.i64_and(e.i64_mul(e.i64_and(e.getLocal(f),e.i64_const(4294967295)),e.getLocal("np32")),e.i64_const("0xFFFFFFFF")))),a.addCode(e.setLocal(f,e.i64_add(e.i64_and(e.getLocal(f),e.i64_const(4294967295)),g(0,t)))),a.addCode(e.setLocal(h,e.i64_add(e.getLocal(h),e.i64_shr_u(e.getLocal(f),e.i64_const(32)))))),t>=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(f))),[f,h]=[h,f],a.addCode(e.setLocal(h,e.i64_shr_u(e.getLocal(f),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(f))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(h)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32"),a.addLocal("c0","i64"),a.addLocal("c1","i64"),a.addLocal("c0_old","i64"),a.addLocal("c1_old","i64"),a.addLocal("np32","i64");for(let t=0;t<l;t++)a.addLocal("x"+t,"i64"),a.addLocal("m"+t,"i64"),a.addLocal("q"+t,"i64");const e=a.getCodeBuilder(),o=Number(0x100000000n-mt(i,0x100000000n));a.addCode(e.setLocal("np32",e.i64_const(o)));const n=[],c=[];function u(t,a){let o,i;return n[t]?o=e.getLocal("x"+t):(o=e.teeLocal("x"+t,e.i64_load32_u(e.getLocal("x"),4*t)),n[t]=!0),n[a]?i=e.getLocal("x"+a):(i=e.teeLocal("x"+a,e.i64_load32_u(e.getLocal("x"),4*a)),n[a]=!0),e.i64_mul(o,i)}function _(t,a){let o,i;return c[t]?o=e.getLocal("q"+t):(o=e.teeLocal("q"+t,e.i64_load32_u(e.i32_const(0),d+4*t)),c[t]=!0),i=e.getLocal("m"+a),e.i64_mul(o,i)}let g="c0",f="c1",h="c0_old",p="c1_old";for(let t=0;t<2*l-1;t++){a.addCode(e.setLocal(g,e.i64_const(0)),e.setLocal(f,e.i64_const(0)));for(let o=Math.max(0,t-l+1);o<t+1>>1&&o<l;o++){const i=t-o;a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),u(o,i)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))}a.addCode(e.setLocal(g,e.i64_shl(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_const(1)))),a.addCode(e.setLocal(f,e.i64_add(e.i64_shl(e.getLocal(f),e.i64_const(1)),e.i64_shr_u(e.getLocal(g),e.i64_const(32))))),t%2==0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),u(t>>1,t>>1)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>0&&(a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.i64_and(e.getLocal(h),e.i64_const(4294967295))))),a.addCode(e.setLocal(f,e.i64_add(e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32))),e.getLocal(p)))));for(let o=Math.max(1,t-l+1);o<=t&&o<l;o++){const i=t-o;a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),_(o,i)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))}t<l&&(a.addCode(e.setLocal("m"+t,e.i64_and(e.i64_mul(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),e.getLocal("np32")),e.i64_const("0xFFFFFFFF")))),a.addCode(e.setLocal(g,e.i64_add(e.i64_and(e.getLocal(g),e.i64_const(4294967295)),_(0,t)))),a.addCode(e.setLocal(f,e.i64_add(e.getLocal(f),e.i64_shr_u(e.getLocal(g),e.i64_const(32)))))),t>=l&&a.addCode(e.i64_store32(e.getLocal("r"),4*(t-l),e.getLocal(g))),a.addCode(e.setLocal(h,e.getLocal(f)),e.setLocal(p,e.i64_shr_u(e.getLocal(h),e.i64_const(32))))}a.addCode(e.i64_store32(e.getLocal("r"),4*l-4,e.getLocal(h))),a.addCode(e.if(e.i32_wrap_i64(e.getLocal(p)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),e.if(e.call(r+"_gte",e.getLocal("r"),e.i32_const(d)),e.drop(e.call(r+"_sub",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))))))}(),function(){const a=t.addFunction(s+"_squareOld");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_toMontgomery");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.i32_const(u),e.getLocal("r")))}(),function(){const a=t.alloc(2*c),e=t.addFunction(s+"_fromMontgomery");e.addParam("x","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(r+"_copy",o.getLocal("x"),o.i32_const(a))),e.addCode(o.call(r+"_zero",o.i32_const(a+c))),e.addCode(o.call(s+"_mReduct",o.i32_const(a),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.call(r+"_gte",o,e.i32_const(L)))}(),function(){const a=t.addFunction(s+"_sign");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(r+"_isZero",e.getLocal("x")),e.ret(e.i32_const(0))),e.call(s+"_fromMontgomery",e.getLocal("x"),o),e.if(e.call(r+"_gte",o,e.i32_const(L)),e.ret(e.i32_const(-1))),e.ret(e.i32_const(1)))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_fromMontgomery",e.getLocal("x"),e.getLocal("r"))),a.addCode(e.call(r+"_inverseMod",e.getLocal("r"),e.i32_const(d),e.getLocal("r"))),a.addCode(e.call(s+"_toMontgomery",e.getLocal("r"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_one");a.addParam("pr","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_copy",e.i32_const(_),e.getLocal("pr")))}(),function(){const a=t.addFunction(s+"_load");a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32"),a.addLocal("p","i32"),a.addLocal("l","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c)),i=t.alloc(c),n=e.i32_const(i);a.addCode(e.call(r+"_zero",e.getLocal("r")),e.setLocal("i",e.i32_const(c)),e.setLocal("p",e.getLocal("scalar")),e.block(e.loop(e.br_if(1,e.i32_gt_u(e.getLocal("i"),e.getLocal("scalarLen"))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",e.getLocal("p"),o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(c))),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(c))),e.br(0))),e.setLocal("l",e.i32_rem_u(e.getLocal("scalarLen"),e.i32_const(c))),e.if(e.i32_eqz(e.getLocal("l")),e.ret([])),e.call(r+"_zero",n),e.setLocal("j",e.i32_const(0)),e.block(e.loop(e.br_if(1,e.i32_eq(e.getLocal("j"),e.getLocal("l"))),e.i32_store8(e.getLocal("j"),i,e.i32_load8_u(e.getLocal("p"))),e.setLocal("p",e.i32_add(e.getLocal("p"),e.i32_const(1))),e.setLocal("j",e.i32_add(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.if(e.i32_eq(e.getLocal("i"),e.i32_const(c)),e.call(s+"_one",o),e.call(s+"_mul",o,e.i32_const(u),o)),e.call(s+"_mul",n,o,n),e.call(s+"_add",e.getLocal("r"),n,e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_timesScalar");a.addParam("x","i32"),a.addParam("scalar","i32"),a.addParam("scalarLen","i32"),a.addParam("r","i32");const e=a.getCodeBuilder(),o=e.i32_const(t.alloc(c));a.addCode(e.call(s+"_load",e.getLocal("scalar"),e.getLocal("scalarLen"),o),e.call(s+"_toMontgomery",o,o),e.call(s+"_mul",e.getLocal("x"),o,e.getLocal("r")))}(),gt(t,s),ft(t,s+"_batchToMontgomery",s+"_toMontgomery",c,c),ft(t,s+"_batchFromMontgomery",s+"_fromMontgomery",c,c),ft(t,s+"_batchNeg",s+"_neg",c,c),ht(t,s+"_batchAdd",s+"_add",c,c),ht(t,s+"_batchSub",s+"_sub",c,c),ht(t,s+"_batchMul",s+"_mul",c,c),t.exportFunction(s+"_add"),t.exportFunction(s+"_sub"),t.exportFunction(s+"_neg"),t.exportFunction(s+"_isNegative"),t.exportFunction(s+"_isOne"),t.exportFunction(s+"_sign"),t.exportFunction(s+"_mReduct"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_squareOld"),t.exportFunction(s+"_fromMontgomery"),t.exportFunction(s+"_toMontgomery"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_one"),t.exportFunction(s+"_load"),t.exportFunction(s+"_timesScalar"),_t(t,s+"_exp",c,s+"_mul",s+"_square",r+"_copy",s+"_one"),t.exportFunction(s+"_exp"),t.exportFunction(s+"_batchInverse"),bt(i)&&(!function(){const a=t.addFunction(s+"_sqrt");a.addParam("n","i32"),a.addParam("r","i32"),a.addLocal("m","i32"),a.addLocal("i","i32"),a.addLocal("j","i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c)),n=e.i32_const(t.alloc(c)),l=e.i32_const(t.alloc(c)),r=e.i32_const(t.alloc(c)),d=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.call(s+"_zero",e.getLocal("r")))),e.setLocal("m",e.i32_const(w)),e.call(s+"_copy",e.i32_const(x),i),e.call(s+"_exp",e.getLocal("n"),e.i32_const(A),e.i32_const(c),n),e.call(s+"_exp",e.getLocal("n"),e.i32_const(I),e.i32_const(c),l),e.block(e.loop(e.br_if(1,e.call(s+"_eq",n,o)),e.call(s+"_square",n,r),e.setLocal("i",e.i32_const(1)),e.block(e.loop(e.br_if(1,e.call(s+"_eq",r,o)),e.call(s+"_square",r,r),e.setLocal("i",e.i32_add(e.getLocal("i"),e.i32_const(1))),e.br(0))),e.call(s+"_copy",i,d),e.setLocal("j",e.i32_sub(e.i32_sub(e.getLocal("m"),e.getLocal("i")),e.i32_const(1))),e.block(e.loop(e.br_if(1,e.i32_eqz(e.getLocal("j"))),e.call(s+"_square",d,d),e.setLocal("j",e.i32_sub(e.getLocal("j"),e.i32_const(1))),e.br(0))),e.setLocal("m",e.getLocal("i")),e.call(s+"_square",d,i),e.call(s+"_mul",n,i,n),e.call(s+"_mul",l,d,l),e.br(0))),e.if(e.call(s+"_isNegative",l),e.call(s+"_neg",l,e.getLocal("r")),e.call(s+"_copy",l,e.getLocal("r"))))}(),function(){const a=t.addFunction(s+"_isSquare");a.addParam("n","i32"),a.setReturnType("i32");const e=a.getCodeBuilder(),o=e.i32_const(_),i=e.i32_const(t.alloc(c));a.addCode(e.if(e.call(s+"_isZero",e.getLocal("n")),e.ret(e.i32_const(1))),e.call(s+"_exp",e.getLocal("n"),e.i32_const(p),e.i32_const(c),i),e.call(s+"_eq",i,o))}(),t.exportFunction(s+"_sqrt"),t.exportFunction(s+"_isSquare")),t.exportFunction(s+"_batchToMontgomery"),t.exportFunction(s+"_batchFromMontgomery"),s};const Ct=At,{bitLength:xt}=W;var Ft=function(t,a,e,o,i){const n=BigInt(a),l=Math.floor((xt(n-1n)-1)/64)+1,c=8*l,s=e||"f1";if(t.modules[s])return s;t.modules[s]={n64:l};const r=i||"int",d=Ct(t,n,o,r),u=t.modules[d].pR2,_=t.modules[d].pq,g=t.modules[d].pePlusOne;return function(){const a=t.alloc(c),e=t.addFunction(s+"_mul");e.addParam("x","i32"),e.addParam("y","i32"),e.addParam("r","i32");const o=e.getCodeBuilder();e.addCode(o.call(d+"_mul",o.getLocal("x"),o.getLocal("y"),o.i32_const(a))),e.addCode(o.call(d+"_mul",o.i32_const(a),o.i32_const(u),o.getLocal("r")))}(),function(){const a=t.addFunction(s+"_square");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(s+"_mul",e.getLocal("x"),e.getLocal("x"),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_inverse");a.addParam("x","i32"),a.addParam("r","i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_inverseMod",e.getLocal("x"),e.i32_const(_),e.getLocal("r")))}(),function(){const a=t.addFunction(s+"_isNegative");a.addParam("x","i32"),a.setReturnType("i32");const e=a.getCodeBuilder();a.addCode(e.call(r+"_gte",e.getLocal("x"),e.i32_const(g)))}(),t.exportFunction(d+"_add",s+"_add"),t.exportFunction(d+"_sub",s+"_sub"),t.exportFunction(d+"_neg",s+"_neg"),t.exportFunction(s+"_mul"),t.exportFunction(s+"_square"),t.exportFunction(s+"_inverse"),t.exportFunction(s+"_isNegative"),t.exportFunction(d+"_copy",s+"_copy"),t.exportFunction(d+"_zero",s+"_zero"),t.exportFunction(d+"_one",s+"_one"),t.exportFunction(d+"_isZero",s+"_isZero"),t.exportFunction(d+"_eq",s+"_eq"),s};const It=V,Bt=K,Et=j;var vt=function(t,a,e,o){if(t.modules[e])return e;const i=8*t.modules[o].n64,n=t.modules[o].q;return t.modules[e]={n64:2*t.modules[o].