├── .eslintrc.yml ├── .gitignore ├── .travis.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── build ├── stm.js ├── stm.min.js └── stm_web.min.js ├── index.html ├── package-lock.json ├── package.json ├── src ├── stm.js └── stm_vad.js └── test.html /.eslintrc.yml: -------------------------------------------------------------------------------- 1 | env: 2 | browser: true 3 | es6: true 4 | node: true 5 | 6 | extends: 7 | - eslint:recommended 8 | - plugin:mozilla/recommended 9 | 10 | plugins: 11 | - mozilla 12 | 13 | globals: 14 | SpeakToMeVAD: true 15 | SpeakToMe: true 16 | 17 | rules: 18 | eqeqeq: error 19 | no-console: off # TODO: Set back to "warn" 20 | no-unused-vars: [error, {vars: all, args: none, ignoreRestSiblings: false}] 21 | no-warning-comments: warn 22 | prefer-const: error 23 | object-shorthand: off 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | .DS_Store 3 | node_modules/ 4 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - 8 5 | 6 | script: 7 | - npm install 8 | - npm run lint 9 | - npm run build 10 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Community Participation Guidelines 2 | 3 | This repository is governed by Mozilla's code of conduct and etiquette guidelines. 4 | For more details, please read the 5 | [Mozilla Community Participation Guidelines](https://www.mozilla.org/about/governance/policies/participation/). 6 | 7 | ## How to Report 8 | For more information on how to report violations of the Community Participation Guidelines, please read our '[How to Report](https://www.mozilla.org/about/governance/policies/participation/reporting/)' page. 9 | 10 | 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SpeakToMe API 2 | 3 | [![Version](http://img.shields.io/npm/v/speaktome-api.svg?style=flat-square)](https://npmjs.org/package/speaktome-api) 4 | [![License](http://img.shields.io/npm/l/speaktome-api.svg?style=flat-square)](https://npmjs.org/package/speaktome-api) 5 | 6 | JavaScript module for Mozilla's SpeakToMe API. 7 | 8 | ## Installation 9 | 10 | ### Browser 11 | 12 | Install and use by directly including the [browser files](build): 13 | 14 | ```html 15 | 16 | My Speech-enabled Web Page 17 | 18 | 19 | 20 | 21 | 31 | 32 | ``` 33 | -------------------------------------------------------------------------------- /build/stm_web.min.js: -------------------------------------------------------------------------------- 1 | var STT_SERVER_URL="https://speaktome-2.services.mozilla.com/",RECORDING_TIMEOUT=3e3,RECORDING_BITS_PER_SECOND=16e3,RECORDING_MIME_TYPE="audio/ogg";function SpeakToMe(e){var n={vad:!0,timeout:RECORDING_TIMEOUT,continuous:!1,serverURL:STT_SERVER_URL,listener:null,language:"en-US",productTag:null,storeSample:!1,storeTranscription:!1};"object"==typeof e&&("boolean"==typeof e.vad&&(n.vad=e.vad),e.timeout&&(n.timeout=e.timeout),e.listener&&(n.listener=e.listener),e.language&&(n.language=e.language),e.productTag&&(n.productTag=e.productTag),"boolean"==typeof e.storeSample&&(n.storeSample=e.storeSample),"boolean"==typeof e.storeTranscription&&(n.storeTranscription=e.storeTranscription));var t,a,o,l,u,s,f,c,r="ready",d=null;function i(r){if(f=r,M({state:"listening"}),t=new AudioContext,a=t.createMediaStreamSource(r),o=t.createAnalyser(),l=t.createMediaStreamDestination(),a.channelCount=1,o.channelCount=1,l.channelCount=1,a.connect(o),o.connect(l),n.vad){d=SpeakToMeVAD({listener:function(e){c=e,_()}}),c="";(u=t.createScriptProcessor(2048,1,1)).connect(t.destination),u.onaudioprocess=d.onAudioProcessingEvent,a.connect(u)}var e={audioBitsPerSecond:RECORDING_BITS_PER_SECOND,mimeType:RECORDING_MIME_TYPE};(s=new MediaRecorder(l.stream,e)).start(),n.vad||setTimeout(_,n.timeout),s.onstop=function(e){(M({state:"processing"}),n.vad&&"novoice"===c||!i[0].size)?(M({state:"result",data:[]}),M({state:"ready"})):function(e){M({state:"sending"});var r={"Accept-Language-STT":n.language,"Store-Sample":n.storeSample?"1":"0","Store-Transcription":n.storeTranscription?"1":"0"};n.productTag&&(r["Product-Tag"]=n.productTag);fetch(n.serverURL,{method:"POST",body:e,headers:r}).then(function(e){return e.json()}).then(function(e){if("ok"!==e.status)throw e.status?new Error("Received bad status: "+e.status):e.error?new Error("Received server error: "+e.error):new Error("Received invalid result");M({state:"result",data:e.data}),M({state:"ready"})}).catch(function(e){M({state:"error",error:e}),M({state:"ready"})})}(new Blob(i,{type:"audio/ogg; codecs=opus"}));i=[],u=r=l=o=a=t=s=null};var i=[];s.ondataavailable=function(e){i.push(e.data)}}function _(){"listening"===r&&(f.getAudioTracks()[0].stop(),s.stop(),a.disconnect(u),a.disconnect(o),o.disconnect(l),u.disconnect(t.destination),t.close())}function M(e){if(r=e.state,n.listener)try{n.listener(e)}catch(e){console.error("SpeakToMe: Listener error",e)}else console.warn("SpeakToMe: You need to initialize SpeakToMe with an event listener!")}function h(){return f}return{listen:function(){"ready"===r?navigator.mediaDevices.getUserMedia({audio:!0}).then(i).catch(function(e){M({state:"error",error:e}),M({state:"ready"})}):console.warn("Listen() called when not ready")},stop:_,setListener:function(e){n.listener=e},getmediaStream:function(){return console.log("SpeakToMe.getmediaStream(): Deprecated API -","use getMediaStream() instead"),h()},getMediaStream:h}}function SpeakToMeVAD(e){var r={listener:function(){console.error("SpeakToMeVAD: No listener configured!")},maxSilence:500};e&&(void 0!==e.listener&&(r.listener=e.listener),void 0!==e.maxSilence&&(console.log("MAXSILENCE",e.maxSilence),r.maxSilence=e.maxSilence)),Module.cwrap("main")(),Module.cwrap("setmode","number",["number"])(3);var a=Module.cwrap("process_data","number",["number","number","number","number","number","number"]),l=480,u=new Int16Array(l),s=0,f=0,c=0,d=!1,_=!1,M=Date.now(),h=Date.now(),m=!1,T=r.maxSilence;function i(){u=new Int16Array(l),c=f=s=0,_=d=!1,M=Date.now(),h=Date.now(),m=!1}function v(e){var r=e.length*e.BYTES_PER_ELEMENT,i=Module._malloc(r),n=new Uint8Array(Module.HEAPU8.buffer,i,r);n.set(new Uint8Array(e.buffer));var t=a(n.byteOffset,e.length,48e3,e[0],e[100],e[2e3]);return Module._free(n.byteOffset),t}function p(e){try{r.listener(e)}catch(e){console.log("SpeakToMeVAD: onCompleteCallback exception:",e)}i()}return i(),{reset:i,onAudioProcessingEvent:function(e){var r=new Int16Array(e.inputBuffer.getChannelData(0).length);!function(e,r){for(var i=0;ir.length)u.set(r.slice(n)),s=r.length-n;else{0>2],i=-16&(r+e+15|0);if((HEAP32[DYNAMICTOP_PTR>>2]=i,TOTAL_MEMORY<=i)&&!enlargeMemory())return HEAP32[DYNAMICTOP_PTR>>2]=r,0;return r},alignMemory:function(e,r){return e=Math.ceil(e/(r||16))*(r||16)},makeBigInt:function(e,r,i){return i?+(e>>>0)+4294967296*+(r>>>0):+(e>>>0)+4294967296*+(0|r)},GLOBAL_BASE:8,QUANTUM_SIZE:4,__dummy__:0};Module.Runtime=Runtime;var ABORT=0,EXITSTATUS=0,cwrap,ccall;function assert(e,r){e||abort("Assertion failed: "+r)}function getCFunc(ident){var func=Module["_"+ident];if(!func)try{func=eval("_"+ident)}catch(e){}return assert(func,"Cannot call unknown function "+ident+" (perhaps LLVM optimizations or closure removed it?)"),func}function setValue(e,r,i,n){switch("*"===(i=i||"i8").charAt(i.length-1)&&(i="i32"),i){case"i1":case"i8":HEAP8[e>>0]=r;break;case"i16":HEAP16[e>>1]=r;break;case"i32":HEAP32[e>>2]=r;break;case"i64":tempI64=[r>>>0,(tempDouble=r,1<=+Math_abs(tempDouble)?0>>0:~~+Math_ceil((tempDouble-+(~~tempDouble>>>0))/4294967296)>>>0:0)],HEAP32[e>>2]=tempI64[0],HEAP32[e+4>>2]=tempI64[1];break;case"float":HEAPF32[e>>2]=r;break;case"double":HEAPF64[e>>3]=r;break;default:abort("invalid type for setValue: "+i)}}function getValue(e,r,i){switch("*"===(r=r||"i8").charAt(r.length-1)&&(r="i32"),r){case"i1":case"i8":return HEAP8[e>>0];case"i16":return HEAP16[e>>1];case"i32":case"i64":return HEAP32[e>>2];case"float":return HEAPF32[e>>2];case"double":return HEAPF64[e>>3];default:abort("invalid type for setValue: "+r)}return null}!function(){var JSfuncs={stackSave:function(){Runtime.stackSave()},stackRestore:function(){Runtime.stackRestore()},arrayToC:function(e){var r=Runtime.stackAlloc(e.length);return writeArrayToMemory(e,r),r},stringToC:function(e){var r=0;if(null!=e&&0!==e){var i=1+(e.length<<2);stringToUTF8(e,r=Runtime.stackAlloc(i),i)}return r}},toC={string:JSfuncs.stringToC,array:JSfuncs.arrayToC};ccall=function(e,r,i,n,t){var a=getCFunc(e),o=[],l=0;if(n)for(var u=0;u>2]=0;for(u=o+a;n>0]=0;return o}if("i8"===l)return e.subarray||e.slice?HEAPU8.set(e,o):HEAPU8.set(new Uint8Array(e),o),o;for(var s,f,c,d=0;d>0],(0!=i||r)&&(t++,!r||t!=r););r||(r=t);var a="";if(n<128){for(var o;0>0];if(!i)return r;r+=String.fromCharCode(i)}}function stringToAscii(e,r){return writeAsciiToMemory(e,r,!1)}Module.ALLOC_NORMAL=ALLOC_NORMAL,Module.ALLOC_STACK=ALLOC_STACK,Module.ALLOC_STATIC=ALLOC_STATIC,Module.ALLOC_DYNAMIC=ALLOC_DYNAMIC,Module.ALLOC_NONE=ALLOC_NONE,Module.allocate=allocate,Module.getMemory=getMemory,Module.Pointer_stringify=Pointer_stringify,Module.AsciiToString=AsciiToString,Module.stringToAscii=stringToAscii;var UTF8Decoder="undefined"!=typeof TextDecoder?new TextDecoder("utf8"):void 0;function UTF8ArrayToString(e,r){for(var i=r;e[i];)++i;if(16>10,56320|1023&s)}else u+=String.fromCharCode((31&n)<<6|t);else u+=String.fromCharCode(n)}}function UTF8ToString(e){return UTF8ArrayToString(HEAPU8,e)}function stringToUTF8Array(e,r,i,n){if(!(0>6,r[i++]=128|63&l}else if(l<=65535){if(a<=i+2)break;r[i++]=224|l>>12,r[i++]=128|l>>6&63,r[i++]=128|63&l}else if(l<=2097151){if(a<=i+3)break;r[i++]=240|l>>18,r[i++]=128|l>>12&63,r[i++]=128|l>>6&63,r[i++]=128|63&l}else if(l<=67108863){if(a<=i+4)break;r[i++]=248|l>>24,r[i++]=128|l>>18&63,r[i++]=128|l>>12&63,r[i++]=128|l>>6&63,r[i++]=128|63&l}else{if(a<=i+5)break;r[i++]=252|l>>30,r[i++]=128|l>>24&63,r[i++]=128|l>>18&63,r[i++]=128|l>>12&63,r[i++]=128|l>>6&63,r[i++]=128|63&l}}return r[i]=0,i-t}function stringToUTF8(e,r,i){return stringToUTF8Array(e,HEAPU8,r,i)}function lengthBytesUTF8(e){for(var r=0,i=0;i>0]=e.charCodeAt(n);i||(HEAP8[r>>0]=0)}Module.addOnPreRun=addOnPreRun,Module.addOnInit=addOnInit,Module.addOnPreMain=addOnPreMain,Module.addOnExit=addOnExit,Module.addOnPostRun=addOnPostRun,Module.intArrayFromString=intArrayFromString,Module.intArrayToString=intArrayToString,Module.writeStringToMemory=writeStringToMemory,Module.writeArrayToMemory=writeArrayToMemory,Module.writeAsciiToMemory=writeAsciiToMemory,Math.imul&&-5===Math.imul(4294967295,5)||(Math.imul=function(e,r){var i=65535&e,n=65535&r;return i*n+((e>>>16)*n+i*(r>>>16)<<16)|0}),Math.imul=Math.imul,Math.clz32||(Math.clz32=function(e){e>>>=0;for(var r=0;r<32;r++)if(e&1<<31-r)return r;return 32}),Math.clz32=Math.clz32,Math.trunc||(Math.trunc=function(e){return e<0?Math.ceil(e):Math.floor(e)}),Math.trunc=Math.trunc;var Math_abs=Math.abs,Math_cos=Math.cos,Math_sin=Math.sin,Math_tan=Math.tan,Math_acos=Math.acos,Math_asin=Math.asin,Math_atan=Math.atan,Math_atan2=Math.atan2,Math_exp=Math.exp,Math_log=Math.log,Math_sqrt=Math.sqrt,Math_ceil=Math.ceil,Math_floor=Math.floor,Math_pow=Math.pow,Math_imul=Math.imul,Math_fround=Math.fround,Math_round=Math.round,Math_min=Math.min,Math_clz32=Math.clz32,Math_trunc=Math.trunc,runDependencies=0,runDependencyWatcher=null,dependenciesFulfilled=null;function addRunDependency(e){runDependencies++,Module.monitorRunDependencies&&Module.monitorRunDependencies(runDependencies)}function removeRunDependency(e){if(runDependencies--,Module.monitorRunDependencies&&Module.monitorRunDependencies(runDependencies),0==runDependencies&&(null!==runDependencyWatcher&&(clearInterval(runDependencyWatcher),runDependencyWatcher=null),dependenciesFulfilled)){var r=dependenciesFulfilled;dependenciesFulfilled=null,r()}}Module.addRunDependency=addRunDependency,Module.removeRunDependency=removeRunDependency,Module.preloadedImages={},Module.preloadedAudios={};var ASM_CONSTS=[];STATIC_BASE=8,STATICTOP=STATIC_BASE+5408,__ATINIT__.push(),allocate([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,5,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,2,0,0,0,28,17,0,0,0,4,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,10,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,82,26,28,19,153,27,59,26,115,26,41,13,222,29,23,15,140,30,98,28,156,19,10,17,114,32,101,39,94,39,47,46,67,46,165,24,1,37,99,37,127,42,157,29,244,31,59,29,122,1,40,4,237,1,70,2,176,2,81,2,218,1,185,2,219,1,176,2,165,1,199,1,43,2,249,1,55,2,12,2,73,2,207,4,253,1,60,3,236,1,4,6,55,4,82,3,8,0,4,0,3,0,14,0,7,0,5,0,24,0,21,0,24,0,57,0,48,0,57,0,37,0,32,0,37,0,100,0,80,0,100,0,6,0,3,0,2,0,9,0,5,0,3,0,82,0,78,0,82,0,29,1,4,1,29,1,94,0,94,0,94,0,76,4,26,4,76,4,34,0,62,0,72,0,66,0,53,0,25,0,94,0,66,0,56,0,62,0,75,0,103,0,48,0,82,0,45,0,87,0,50,0,47,0,80,0,46,0,83,0,41,0,78,0,81,0,6,0,8,0,10,0,12,0,14,0,16,0,128,2,0,3,32,2,32,2,64,2,64,2,64,2,64,2,128,44,128,44,0,45,0,45,0,45,0,45,0,36,128,35,0,35,128,34,0,34,128,33,0,0,201,0,146,1,91,2,36,3,237,3,182,4,126,5,71,6,16,7,217,7,161,8,106,9,50,10,251,10,195,11,139,12,83,13,27,14,227,14,171,15,114,16,57,17,0,18,199,18,142,19,85,20,27,21,225,21,167,22,109,23,51,24,248,24,189,25,130,26,70,27,11,28,207,28,147,29,86,30,25,31,220,31,159,32,97,33,35,34,228,34,166,35,103,36,39,37,231,37,167,38,103,39,38,40,229,40,163,41,97,42,30,43,219,43,152,44,84,45,16,46,204,46,134,47,65,48,251,48,180,49,109,50,38,51,222,51,150,52,77,53,3,54,185,54,111,55,36,56,216,56,140,57,63,58,242,58,164,59,86,60,7,61,183,61,103,62,22,63,197,63,115,64,32,65,205,65,121,66,37,67,208,67,122,68,35,69,204,69,116,70,28,71,195,71,105,72,14,73,179,73,87,74,250,74,157,75,63,76,224,76,128,77,32,78,191,78,93,79,250,79,151,80,51,81,206,81,104,82,1,83,154,83,50,84,201,84,95,85,244,85,137,86,29,87,176,87,66,88,211,88,99,89,243,89,129,90,15,91,156,91,40,92,179,92,61,93,198,93,79,94,214,94,93,95,226,95,103,96,235,96,110,97,240,97,113,98,241,98,112,99,238,99,107,100,231,100,98,101,221,101,86,102,206,102,69,103,188,103,49,104,165,104,25,105,139,105,252,105,108,106,219,106,74,107,183,107,35,108,142,108,248,108,97,109,201,109,48,110,149,110,250,110,94,111,192,111,34,112,130,112,225,112,64,113,157,113,249,113,84,114,174,114,6,115,94,115,181,115,10,116,94,116,177,116,3,117,84,117,164,117,243,117,64,118,141,118,216,118,34,119,107,119,179,119,249,119,63,120,131,120,198,120,8,121,73,121,137,121,199,121,4,122,65,122,124,122,181,122,238,122,37,123,92,123,145,123,196,123,247,123,41,124,89,124,136,124,182,124,226,124,14,125,56,125,97,125,137,125,176,125,213,125,249,125,28,126,62,126,94,126,126,126,156,126,185,126,212,126,239,126,8,127,32,127,55,127,76,127,97,127,116,127,134,127,150,127,166,127,180,127,193,127,205,127,215,127,224,127,232,127,239,127,245,127,249,127,252,127,254,127,255,127,254,127,252,127,249,127,245,127,239,127,232,127,224,127,215,127,205,127,193,127,180,127,166,127,150,127,134,127,116,127,97,127,76,127,55,127,32,127,8,127,239,126,212,126,185,126,156,126,126,126,94,126,62,126,28,126,249,125,213,125,176,125,137,125,97,125,56,125,14,125,226,124,182,124,136,124,89,124,41,124,247,123,196,123,145,123,92,123,37,123,238,122,181,122,124,122,65,122,4,122,199,121,137,121,73,121,8,121,198,120,131,120,63,120,249,119,179,119,107,119,34,119,216,118,141,118,64,118,243,117,164,117,84,117,3,117,177,116,94,116,10,116,181,115,94,115,6,115,174,114,84,114,249,113,157,113,64,113,225,112,130,112,34,112,192,111,94,111,250,110,149,110,48,110,201,109,97,109,248,108,142,108,35,108,183,107,74,107,219,106,108,106,252,105,139,105,25,105,165,104,49,104,188,103,69,103,206,102,86,102,221,101,98,101,231,100,107,100,238,99,112,99,241,98,113,98,240,97,110,97,235,96,103,96,226,95,93,95,214,94,79,94,198,93,61,93,179,92,40,92,156,91,15,91,129,90,243,89,99,89,211,88,66,88,176,87,29,87,137,86,244,85,95,85,201,84,50,84,154,83,1,83,104,82,206,81,51,81,151,80,250,79,93,79,191,78,32,78,128,77,224,76,63,76,157,75,250,74,87,74,179,73,14,73,105,72,195,71,28,71,116,70,204,69,35,69,122,68,208,67,37,67,121,66,205,65,32,65,115,64,197,63,22,63,103,62,183,61,7,61,86,60,164,59,242,58,63,58,140,57,216,56,36,56,111,55,185,54,3,54,77,53,150,52,222,51,38,51,109,50,180,49,251,48,65,48,134,47,204,46,16,46,84,45,152,44,219,43,30,43,97,42,163,41,229,40,38,40,103,39,167,38,231,37,39,37,103,36,166,35,228,34,35,34,97,33,159,32,220,31,25,31,86,30,147,29,207,28,11,28,70,27,130,26,189,25,248,24,51,24,109,23,167,22,225,21,27,21,85,20,142,19,199,18,0,18,57,17,114,16,171,15,227,14,27,14,83,13,139,12,195,11,251,10,50,10,106,9,161,8,217,7,16,7,71,6,126,5,182,4,237,3,36,3,91,2,146,1,201,0,0,0,55,255,110,254,165,253,220,252,19,252,74,251,130,250,185,249,240,248,39,248,95,247,150,246,206,245,5,245,61,244,117,243,173,242,229,241,29,241,85,240,142,239,199,238,0,238,57,237,114,236,171,235,229,234,31,234,89,233,147,232,205,231,8,231,67,230,126,229,186,228,245,227,49,227,109,226,170,225,231,224,36,224,97,223,159,222,221,221,28,221,90,220,153,219,217,218,25,218,89,217,153,216,218,215,27,215,93,214,159,213,226,212,37,212,104,211,172,210,240,209,52,209,122,208,191,207,5,207,76,206,147,205,218,204,34,204,106,203,179,202,253,201,71,201,145,200,220,199,40,199,116,198,193,197,14,197,92,196,170,195,249,194,73,194,153,193,234,192,59,192,141,191,224,190,51,190,135,189,219,188,48,188,134,187,221,186,52,186,140,185,228,184,61,184,151,183,242,182,77,182,169,181,6,181,99,180,193,179,32,179,128,178,224,177,65,177,163,176,6,176,105,175,205,174,50,174,152,173,255,172,102,172,206,171,55,171,161,170,12,170,119,169,227,168,80,168,190,167,45,167,157,166,13,166,127,165,241,164,100,164,216,163,77,163,195,162,58,162,177,161,42,161,163,160,30,160,153,159,21,159,146,158,16,158,143,157,15,157,144,156,18,156,149,155,25,155,158,154,35,154,170,153,50,153,187,152,68,152,207,151,91,151,231,150,117,150,4,150,148,149,37,149,182,148,73,148,221,147,114,147,8,147,159,146,55,146,208,145,107,145,6,145,162,144,64,144,222,143,126,143,31,143,192,142,99,142,7,142,172,141,82,141,250,140,162,140,75,140,246,139,162,139,79,139,253,138,172,138,92,138,13,138,192,137,115,137,40,137,222,136,149,136,77,136,7,136,193,135,125,135,58,135,248,134,183,134,119,134,57,134,252,133,191,133,132,133,75,133,18,133,219,132,164,132,111,132,60,132,9,132,215,131,167,131,120,131,74,131,30,131,242,130,200,130,159,130,119,130,80,130,43,130,7,130,228,129,194,129,162,129,130,129,100,129,71,129,44,129,17,129,248,128,224,128,201,128,180,128,159,128,140,128,122,128,106,128,90,128,76,128,63,128,51,128,41,128,32,128,24,128,17,128,11,128,7,128,4,128,2,128,1,128,2,128,4,128,7,128,11,128,17,128,24,128,32,128,41,128,51,128,63,128,76,128,90,128,106,128,122,128,140,128,159,128,180,128,201,128,224,128,248,128,17,129,44,129,71,129,100,129,130,129,162,129,194,129,228,129,7,130,43,130,80,130,119,130,159,130,200,130,242,130,30,131,74,131,120,131,167,131,215,131,9,132,60,132,111,132,164,132,219,132,18,133,75,133,132,133,191,133,252,133,57,134,119,134,183,134,248,134,58,135,125,135,193,135,7,136,77,136,149,136,222,136,40,137,115,137,192,137,13,138,92,138,172,138,253,138,79,139,162,139,246,139,75,140,162,140,250,140,82,141,172,141,7,142,99,142,192,142,31,143,126,143,222,143,64,144,162,144,6,145,107,145,208,145,55,146,159,146,8,147,114,147,221,147,73,148,182,148,37,149,148,149,4,150,117,150,231,150,91,151,207,151,68,152,187,152,50,153,170,153,35,154,158,154,25,155,149,155,18,156,144,156,15,157,143,157,16,158,146,158,21,159,153,159,30,160,163,160,42,161,177,161,58,162,195,162,77,163,216,163,100,164,241,164,127,165,13,166,157,166,45,167,190,167,80,168,227,168,119,169,12,170,161,170,55,171,206,171,102,172,255,172,152,173,50,174,205,174,105,175,6,176,163,176,65,177,224,177,128,178,32,179,193,179,99,180,6,181,169,181,77,182,242,182,151,183,61,184,228,184,140,185,52,186,221,186,134,187,48,188,219,188,135,189,51,190,224,190,141,191,59,192,234,192,153,193,73,194,249,194,170,195,92,196,14,197,193,197,116,198,40,199,220,199,145,200,71,201,253,201,179,202,106,203,34,204,218,204,147,205,76,206,5,207,191,207,122,208,52,209,240,209,172,210,104,211,37,212,226,212,159,213,93,214,27,215,218,215,153,216,89,217,25,218,217,218,153,219,90,220,28,221,221,221,159,222,97,223,36,224,231,224,170,225,109,226,49,227,245,227,186,228,126,229,67,230,8,231,205,231,147,232,89,233,31,234,229,234,171,235,114,236,57,237,0,238,199,238,142,239,85,240,29,241,229,241,173,242,117,243,61,244,5,245,206,245,150,246,95,247,39,248,240,248,185,249,130,250,74,251,19,252,220,252,165,253,110,254,55,255,1,0,128,0,2,0,64,0,3,0,192,0,4,0,32,0,5,0,160,0,6,0,96,0,7,0,224,0,8,0,16,0,9,0,144,0,10,0,80,0,11,0,208,0,12,0,48,0,13,0,176,0,14,0,112,0,15,0,240,0,17,0,136,0,18,0,72,0,19,0,200,0,20,0,40,0,21,0,168,0,22,0,104,0,23,0,232,0,25,0,152,0,26,0,88,0,27,0,216,0,28,0,56,0,29,0,184,0,30,0,120,0,31,0,248,0,33,0,132,0,34,0,68,0,35,0,196,0,37,0,164,0,38,0,100,0,39,0,228,0,41,0,148,0,42,0,84,0,43,0,212,0,44,0,52,0,45,0,180,0,46,0,116,0,47,0,244,0,49,0,140,0,50,0,76,0,51,0,204,0,53,0,172,0,54,0,108,0,55,0,236,0,57,0,156,0,58,0,92,0,59,0,220,0,61,0,188,0,62,0,124,0,63,0,252,0,65,0,130,0,67,0,194,0,69,0,162,0,70,0,98,0,71,0,226,0,73,0,146,0,74,0,82,0,75,0,210,0,77,0,178,0,78,0,114,0,79,0,242,0,81,0,138,0,83,0,202,0,85,0,170,0,86,0,106,0,87,0,234,0,89,0,154,0,91,0,218,0,93,0,186,0,94,0,122,0,95,0,250,0,97,0,134,0,99,0,198,0,101,0,166,0,103,0,230,0,105,0,150,0,107,0,214,0,109,0,182,0,110,0,118,0,111,0,246,0,113,0,142,0,115,0,206,0,117,0,174,0,119,0,238,0,121,0,158,0,123,0,222,0,125,0,190,0,127,0,254,0,131,0,193,0,133,0,161,0,135,0,225,0,137,0,145,0,139,0,209,0,141,0,177,0,143,0,241,0,147,0,201,0,149,0,169,0,151,0,233,0,155,0,217,0,157,0,185,0,159,0,249,0,163,0,197,0,167,0,229,0,171,0,213,0,173,0,181,0,175,0,245,0,179,0,205,0,183,0,237,0,187,0,221,0,191,0,253,0,199,0,227,0,203,0,211,0,207,0,243,0,215,0,235,0,223,0,251,0,239,0,247,0,1,0,64,0,2,0,32,0,3,0,96,0,4,0,16,0,5,0,80,0,6,0,48,0,7,0,112,0,9,0,72,0,10,0,40,0,11,0,104,0,12,0,24,0,13,0,88,0,14,0,56,0,15,0,120,0,17,0,68,0,18,0,36,0,19,0,100,0,21,0,84,0,22,0,52,0,23,0,116,0,25,0,76,0,26,0,44,0,27,0,108,0,29,0,92,0,30,0,60,0,31,0,124,0,33,0,66,0,35,0,98,0,37,0,82,0,38,0,50,0,39,0,114,0,41,0,74,0,43,0,106,0,45,0,90,0,46,0,58,0,47,0,122,0,49,0,70,0,51,0,102,0,53,0,86,0,55,0,118,0,57,0,78,0,59,0,110,0,61,0,94,0,63,0,126,0,67,0,97,0,69,0,81,0,71,0,113,0,75,0,105,0,77,0,89,0,79,0,121,0,83,0,101,0,87,0,117,0,91,0,109,0,95,0,125,0,103,0,115,0,111,0,123,0,100,97,116,97,91,48,93,32,61,61,32,118,97,108,48,0,109,97,105,110,46,99,0,112,114,111,99,101,115,115,95,100,97,116,97,0,100,97,116,97,91,49,48,48,93,32,61,61,32,118,97,108,49,48,48,0,100,97,116,97,91,50,48,48,48,93,32,61,61,32,118,97,108,50,48,48,48,0,112,114,111,99,101,115,115,95,100,97,116,97,58,32,100,97,116,97,32,61,61,32,78,85,76,76,32,0,100,97,116,97,95,108,101,110,103,116,104,32,62,61,32,48,0,119,101,98,114,116,99,47,99,111,109,109,111,110,95,97,117,100,105,111,47,118,97,100,47,118,97,100,95,102,105,108,116,101,114,98,97,110,107,46,99,0,87,101,98,82,116,99,86,97,100,95,67,97,108,99,117,108,97,116,101,70,101,97,116,117,114,101,115,0,100,97,116,97,95,108,101,110,103,116,104,32,60,61,32,50,52,48,0,100,97,116,97,95,105,110,32,33,61,32,78,85,76,76,0,76,111,103,79,102,69,110,101,114,103,121,0,100,97,116,97,95,108,101,110,103,116,104,32,62,32,48,0,99,104,97,110,110,101,108,32,60,32,107,78,117,109,67,104,97,110,110,101,108,115,0,119,101,98,114,116,99,47,99,111,109,109,111,110,95,97,117,100,105,111,47,118,97,100,47,118,97,100,95,115,112,46,99,0,87,101,98,82,116,99,86,97,100,95,70,105,110,100,77,105,110,105,109,117,109,0],"i8",ALLOC_NONE,Runtime.GLOBAL_BASE);var tempDoublePtr=STATICTOP;function ___assert_fail(e,r,i,n){throw ABORT=!0,"Assertion failed: "+Pointer_stringify(e)+", at: "+[r?Pointer_stringify(r):"unknown filename",i,n?Pointer_stringify(n):"unknown function"]+" at "+stackTrace()}function ___setErrNo(e){return Module.___errno_location&&(HEAP32[Module.___errno_location()>>2]=e),e}function ___lock(){}function _emscripten_memcpy_big(e,r,i){return HEAPU8.set(HEAPU8.subarray(r,r+i),e),e}function _abort(){Module.abort()}function _pthread_once(e,r){_pthread_once.seen||(_pthread_once.seen={}),e in _pthread_once.seen||(Module.dynCall_v(r),_pthread_once.seen[e]=1)}STATICTOP+=16,Module._sbrk=_sbrk,Module._memset=_memset,Module._memcpy=_memcpy;var SYSCALLS={varargs:0,get:function(e){return SYSCALLS.varargs+=4,HEAP32[SYSCALLS.varargs-4>>2]},getStr:function(){return Pointer_stringify(SYSCALLS.get())},get64:function(){var e=SYSCALLS.get(),r=SYSCALLS.get();return assert(0<=e?0===r:-1===r),e},getZero:function(){assert(0===SYSCALLS.get())}};function ___syscall140(e,r){SYSCALLS.varargs=r;try{var i=SYSCALLS.getStreamFromFD(),n=SYSCALLS.get(),t=SYSCALLS.get(),a=SYSCALLS.get(),o=SYSCALLS.get(),l=t;return assert(0===n),FS.llseek(i,l,o),HEAP32[a>>2]=i.position,i.getdents&&0===l&&0===o&&(i.getdents=null),0}catch(e){return"undefined"!=typeof FS&&e instanceof FS.ErrnoError||abort(e),-e.errno}}function ___syscall146(e,r){SYSCALLS.varargs=r;try{var i=SYSCALLS.get(),n=SYSCALLS.get(),t=SYSCALLS.get(),a=0;___syscall146.buffer||(___syscall146.buffers=[null,[],[]],___syscall146.printChar=function(e,r){var i=___syscall146.buffers[e];assert(i),0===r||10===r?((1===e?Module.print:Module.printErr)(UTF8ArrayToString(i,0)),i.length=0):i.push(r)});for(var o=0;o>2],u=HEAP32[n+(8*o+4)>>2],s=0;s>2]=DYNAMIC_BASE,staticSealed=!0,Module.asmGlobalArg={Math:Math,Int8Array:Int8Array,Int16Array:Int16Array,Int32Array:Int32Array,Uint8Array:Uint8Array,Uint16Array:Uint16Array,Uint32Array:Uint32Array,Float32Array:Float32Array,Float64Array:Float64Array,NaN:NaN,Infinity:1/0},Module.asmLibraryArg={abort:abort,assert:assert,enlargeMemory:enlargeMemory,getTotalMemory:getTotalMemory,abortOnCannotGrowMemory:abortOnCannotGrowMemory,invoke_iiiiiiii:invoke_iiiiiiii,invoke_iiii:invoke_iiii,invoke_vi:invoke_vi,invoke_ii:invoke_ii,invoke_viiiiiii:invoke_viiiiiii,invoke_v:invoke_v,invoke_iiiiiiiii:invoke_iiiiiiiii,invoke_iii:invoke_iii,___lock:___lock,___syscall6:___syscall6,_pthread_once:_pthread_once,_abort:_abort,___syscall140:___syscall140,___setErrNo:___setErrNo,_emscripten_memcpy_big:_emscripten_memcpy_big,___syscall54:___syscall54,___unlock:___unlock,___assert_fail:___assert_fail,___syscall146:___syscall146,DYNAMICTOP_PTR:DYNAMICTOP_PTR,tempDoublePtr:tempDoublePtr,ABORT:ABORT,STACKTOP:STACKTOP,STACK_MAX:STACK_MAX};var asm=function(e,r,i){"use asm";var M=new e.Int8Array(i);var Q=new e.Int16Array(i);var Ee=new e.Int32Array(i);var c=new e.Uint8Array(i);var $=new e.Uint16Array(i);var n=new e.Uint32Array(i);var t=new e.Float32Array(i);var a=new e.Float64Array(i);var o=r.DYNAMICTOP_PTR|0;var l=r.tempDoublePtr|0;var u=r.ABORT|0;var ke=r.STACKTOP|0;var s=r.STACK_MAX|0;var f=0;var d=0;var _=0;var h=0;var m=e.NaN,T=e.Infinity;var v=0,p=0,A=0,S=0,b=0.0,y=0,g=0,E=0,k=0.0;var w=0;var R=e.Math.floor;var C=e.Math.abs;var O=e.Math.sqrt;var P=e.Math.pow;var N=e.Math.cos;var I=e.Math.sin;var L=e.Math.tan;var U=e.Math.acos;var D=e.Math.asin;var F=e.Math.atan;var H=e.Math.atan2;var x=e.Math.exp;var Y=e.Math.log;var V=e.Math.ceil;var ee=e.Math.imul;var B=e.Math.min;var K=e.Math.max;var W=e.Math.clz32;var z=r.abort;var G=r.assert;var j=r.enlargeMemory;var J=r.getTotalMemory;var X=r.abortOnCannotGrowMemory;var q=r.invoke_iiiiiiii;var Z=r.invoke_iiii;var re=r.invoke_vi;var ie=r.invoke_ii;var ne=r.invoke_viiiiiii;var te=r.invoke_v;var ae=r.invoke_iiiiiiiii;var oe=r.invoke_iii;var le=r.___lock;var ue=r.___syscall6;var se=r._pthread_once;var we=r._abort;var fe=r.___syscall140;var ce=r.___setErrNo;var de=r._emscripten_memcpy_big;var _e=r.___syscall54;var Me=r.___unlock;var he=r.___assert_fail;var me=r.___syscall146;var Te=0.0;function ve(e){e=e|0;var r=0;r=ke;ke=ke+e|0;ke=ke+15&-16;return r|0}function pe(){return ke|0}function Ae(e){e=e|0;ke=e}function Se(e,r){e=e|0;r=r|0;ke=e;s=r}function be(e,r){e=e|0;r=r|0;if(!f){f=e;d=r}}function ye(e){e=e|0;w=e}function ge(){return w|0}function Re(){var e=0;if((Pe(3740)|0)==-1){e=0;return e|0}e=(Ne(Ee[935]|0)|0)!=-1&1;return e|0}function Ce(e){e=e|0;return Ie(Ee[935]|0,e)|0}function Oe(e,r,i,n,t,a){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;if(!e)Br(3482)|0;if((Q[e>>1]|0)!=(n|0))he(3404,3420,30,3427);if((Q[e+200>>1]|0)!=(t|0))he(3440,3420,31,3427);if((Q[e+4e3>>1]|0)==(a|0))return Le(Ee[935]|0,i,e,r)|0;else he(3460,3420,32,3427);return 0}function Pe(e){e=e|0;var r=0,i=0;if(!e){r=-1;return r|0}i=Kr(736)|0;Ee[e>>2]=i;if(!i){r=-1;return r|0}je();Ee[i+732>>2]=0;r=0;return r|0}function Ne(e){e=e|0;return Ue(e)|0}function Ie(e,r){e=e|0;r=r|0;var i=0;if((e|0)!=0?(Ee[e+732>>2]|0)==42:0)i=De(e,r)|0;else i=-1;return i|0}function Le(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0;if(!e){t=-1;return t|0}if((i|0)==0?1:(Ee[e+732>>2]|0)!=42){t=-1;return t|0}e:do{if((r|0)>=32e3)if((r|0)<48e3)switch(r|0){case 32e3:{a=32;break e;break}default:{t=-1;return t|0}}else switch(r|0){case 48e3:{a=48;break e;break}default:{t=-1;return t|0}}else{if((r|0)<16e3){switch(r|0){case 8e3:{a=8;break e;break}default:t=-1}return t|0}switch(r|0){case 16e3:{a=16;break e;break}default:{t=-1;return t|0}}}}while(0);if(!((a*30|0)==(n|0)|((a*10|0)==(n|0)|(a*20|0)==(n|0)))){t=-1;return t|0}e:do{if((r|0)<32e3)if((r|0)<16e3){switch(r|0){case 8e3:break;default:{o=-1;break e}}o=He(e,i,n)|0;break}else{switch(r|0){case 16e3:break;default:{o=-1;break e}}o=Ye(e,i,n)|0;break}else if((r|0)<48e3){switch(r|0){case 32e3:break;default:{o=-1;break e}}o=xe(e,i,n)|0;break}else{switch(r|0){case 48e3:break;default:{o=-1;break e}}o=Fe(e,i,n)|0;break}}while(0);t=(o|0)<1?o:1;return t|0}function Ue(e){e=e|0;var r=0,i=0,n=0;if(!e){r=-1;return r|0}Ee[e>>2]=1;i=e+4|0;Ee[i>>2]=0;Ee[i+4>>2]=0;Ee[i+8>>2]=0;Ee[i+12>>2]=0;i=e+276|0;Ee[i>>2]=0;Ee[i+4>>2]=0;Ze(e+20|0);i=0;do{Q[e+180+(i<<1)>>1]=Q[384+(i<<1)>>1]|0;Q[e+204+(i<<1)>>1]=Q[408+(i<<1)>>1]|0;Q[e+228+(i<<1)>>1]=Q[432+(i<<1)>>1]|0;Q[e+252+(i<<1)>>1]=Q[456+(i<<1)>>1]|0;i=i+1|0}while((i|0)!=12);n=0;do{Q[e+476+(n<<1)>>1]=1e4;Q[e+284+(n<<1)>>1]=0;n=n+1|0}while((n|0)!=96);n=e+680|0;Ee[n>>2]=0;Ee[n+4>>2]=0;Ee[n+8>>2]=0;Ee[n+12>>2]=0;Ee[n+16>>2]=0;Ee[n+20>>2]=0;Ee[n+24>>2]=0;Q[e+668>>1]=1600;Q[e+670>>1]=1600;Q[e+672>>1]=1600;Q[e+674>>1]=1600;Q[e+676>>1]=1600;Q[e+678>>1]=1600;n=e+708|0;Q[n>>1]=Q[240]|0;Q[n+2>>1]=Q[241]|0;Q[n+4>>1]=Q[242]|0;n=e+714|0;Q[n>>1]=Q[243]|0;Q[n+2>>1]=Q[244]|0;Q[n+4>>1]=Q[245]|0;n=e+720|0;Q[n>>1]=Q[246]|0;Q[n+2>>1]=Q[247]|0;Q[n+4>>1]=Q[248]|0;n=e+726|0;Q[n>>1]=Q[249]|0;Q[n+2>>1]=Q[250]|0;Q[n+4>>1]=Q[251]|0;Ee[e+732>>2]=42;r=0;return r|0}function De(e,r){e=e|0;r=r|0;var i=0;switch(r|0){case 0:{r=e+708|0;Q[r>>1]=Q[240]|0;Q[r+2>>1]=Q[241]|0;Q[r+4>>1]=Q[242]|0;r=e+714|0;Q[r>>1]=Q[243]|0;Q[r+2>>1]=Q[244]|0;Q[r+4>>1]=Q[245]|0;r=e+720|0;Q[r>>1]=Q[246]|0;Q[r+2>>1]=Q[247]|0;Q[r+4>>1]=Q[248]|0;r=e+726|0;Q[r>>1]=Q[249]|0;Q[r+2>>1]=Q[250]|0;Q[r+4>>1]=Q[251]|0;i=0;return i|0}case 1:{r=e+708|0;Q[r>>1]=Q[240]|0;Q[r+2>>1]=Q[241]|0;Q[r+4>>1]=Q[242]|0;r=e+714|0;Q[r>>1]=Q[243]|0;Q[r+2>>1]=Q[244]|0;Q[r+4>>1]=Q[245]|0;r=e+720|0;Q[r>>1]=Q[252]|0;Q[r+2>>1]=Q[253]|0;Q[r+4>>1]=Q[254]|0;r=e+726|0;Q[r>>1]=Q[255]|0;Q[r+2>>1]=Q[256]|0;Q[r+4>>1]=Q[257]|0;i=0;return i|0}case 2:{r=e+708|0;Q[r>>1]=Q[258]|0;Q[r+2>>1]=Q[259]|0;Q[r+4>>1]=Q[260]|0;r=e+714|0;Q[r>>1]=Q[261]|0;Q[r+2>>1]=Q[262]|0;Q[r+4>>1]=Q[263]|0;r=e+720|0;Q[r>>1]=Q[264]|0;Q[r+2>>1]=Q[265]|0;Q[r+4>>1]=Q[266]|0;r=e+726|0;Q[r>>1]=Q[267]|0;Q[r+2>>1]=Q[268]|0;Q[r+4>>1]=Q[269]|0;i=0;return i|0}case 3:{r=e+708|0;Q[r>>1]=Q[258]|0;Q[r+2>>1]=Q[259]|0;Q[r+4>>1]=Q[260]|0;r=e+714|0;Q[r>>1]=Q[261]|0;Q[r+2>>1]=Q[262]|0;Q[r+4>>1]=Q[263]|0;r=e+720|0;Q[r>>1]=Q[270]|0;Q[r+2>>1]=Q[271]|0;Q[r+4>>1]=Q[272]|0;r=e+726|0;Q[r>>1]=Q[273]|0;Q[r+2>>1]=Q[274]|0;Q[r+4>>1]=Q[275]|0;i=0;return i|0}default:{i=-1;return i|0}}return 0}function Fe(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0;n=ke;ke=ke+3424|0;t=n+2944|0;a=n;jr(a|0,0,2944)|0;o=(i|0)/480|0;if((i|0)>479){l=e+20|0;u=0;do{qe(r,t+(u*80<<1)|0,l,a);u=u+1|0}while((u|0)<(o|0))}o=He(e,t,(i|0)/6|0)|0;ke=n;return o|0}function He(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0,v=0,p=0,A=0,S=0,b=0,y=0,g=0,E=0,k=0,w=0,R=0,C=0,O=0,P=0,N=0,I=0,L=0,U=0,D=0,F=0,H=0,x=0,Y=0,V=0,B=0,K=0,W=0,z=0,G=0,j=0,J=0,X=0,q=0,Z=0;n=ke;ke=ke+112|0;t=n+88|0;a=n+64|0;o=n+40|0;l=n+16|0;u=n;s=Ve(e,r,i,u)|0;r=o;f=r+24|0;do{Q[r>>1]=0;r=r+2|0}while((r|0)<(f|0));r=l;f=r+24|0;do{Q[r>>1]=0;r=r+2|0}while((r|0)<(f|0));r=(i|0)==80?0:(i|0)==160?1:2;i=Q[e+726+(r<<1)>>1]|0;f=Q[e+714+(r<<1)>>1]|0;c=Q[e+708+(r<<1)>>1]|0;if(s<<16>>16>10){s=Q[e+720+(r<<1)>>1]|0;r=0;d=0;_=0;do{M=u+(d<<1)|0;h=We(Q[M>>1]|0,Q[e+180+(d<<1)>>1]|0,Q[e+228+(d<<1)>>1]|0,t+(d<<1)|0)|0;m=ee(Q[552+(d<<1)>>1]|0,h)|0;h=We(Q[M>>1]|0,Q[e+204+(d<<1)>>1]|0,Q[e+252+(d<<1)>>1]|0,a+(d<<1)|0)|0;T=ee(Q[576+(d<<1)>>1]|0,h)|0;h=d+6|0;v=We(Q[M>>1]|0,Q[e+180+(h<<1)>>1]|0,Q[e+228+(h<<1)>>1]|0,t+(h<<1)|0)|0;p=(ee(Q[552+(h<<1)>>1]|0,v)|0)+m|0;v=We(Q[M>>1]|0,Q[e+204+(h<<1)>>1]|0,Q[e+252+(h<<1)>>1]|0,a+(h<<1)|0)|0;M=(ee(Q[576+(h<<1)>>1]|0,v)|0)+T|0;v=(p|0)==0;if(v)A=0;else{S=p>>31^p;b=S>>>0>32767?0:16;y=(-8388608>>>b&S|0)==0?b|8:b;b=(-134217728>>>y&S|0)==0?y|4:y;y=(-536870912>>>b&S|0)==0?b|2:b;A=((-1073741824>>>y&S|0)==0&1)+y|0}y=(M|0)==0;if(y)g=0;else{S=M>>31^M;b=S>>>0>32767?0:16;E=(-8388608>>>b&S|0)==0?b|8:b;b=(-134217728>>>E&S|0)==0?E|4:E;E=(-536870912>>>b&S|0)==0?b|2:b;g=((-1073741824>>>E&S|0)==0&1)+E|0}E=(v?31:A)-(y?31:g)<<16;r=(ee(E>>16,Q[600+(d<<1)>>1]|0)|0)+r|0;_=(E>>14|0)>(s|0)?1:_;E=p>>>12;if((E<<16|0)>0){p=Xe(m<<2&-16384,E&65535)|0;Q[o+(d<<1)>>1]=p;k=16384-p&65535;w=h}else{k=16384;w=d}Q[o+(w<<1)>>1]=k;p=M>>>12;if((p<<16|0)>0){M=Xe(T<<2&-16384,p&65535)|0;Q[l+(d<<1)>>1]=M;Q[l+(h<<1)>>1]=16384-M}d=d+1|0}while((d|0)!=6);d=(r|0)>=(i<<16>>16|0)|_&65535;_=d&65535;i=_<<16>>16!=0;r=12800;k=0;do{w=u+(k<<1)|0;s=Ge(e,Q[w>>1]|0,k)|0;g=e+180+(k<<1)|0;A=552+(k<<1)|0;M=Q[A>>1]|0;h=ee(M,Q[g>>1]|0)|0;p=g+12|0;T=Q[A+12>>1]|0;A=(((s<<16>>16<<4)-(((ee(T,Q[p>>1]|0)|0)+h|0)>>>6)<<16>>16)*19712|0)>>>16;h=72-k|0;s=(r&65535)+640|0;E=s&65535;m=s<<16>>16;s=0;do{y=(s*6|0)+k|0;v=e+180+(y<<1)|0;S=Q[v>>1]|0;b=e+204+(y<<1)|0;R=Q[b>>1]|0;C=e+228+(y<<1)|0;O=Q[C>>1]|0;P=e+252+(y<<1)|0;N=Q[P>>1]|0;if(i)I=S;else I=(((ee(Q[o+(y<<1)>>1]<<5,Q[t+(y<<1)>>1]|0)|0)>>16)*655>>22)+(S&65535)&65535;L=(I&65535)+A|0;U=(s<<7)+640|0;D=(L<<16|0)<(U<<16|0)?U:L;L=s+h|0;Q[v>>1]=(D<<16|0)>(L<<23|0)?L<<7:D;if(i){D=Q[l+(y<<1)>>1]|0;L=Q[a+(y<<1)>>1]|0;v=R<<16>>16;R=(((((ee(D<<5,L)|0)>>16)*6554>>21)+1|0)>>>1)+v|0;U=Q[612+(s<<1)>>1]|0;F=(R<<16>>16|0)<(U<<16>>16|0)?U:R&65535;Q[b>>1]=(F<<16>>16|0)>(m|0)?E:F;F=(ee(((ee(($[w>>1]|0)-((v+4|0)>>>3)<<16>>16,L)|0)>>3)+-4096|0,D>>2)|0)>>4;D=N<<16>>16;N=D*10&65535;if((F|0)>0)H=Xe(F,N)|0;else H=0-(Xe(0-F|0,N)|0)|0;x=((H<<16)+8388608>>24)+D|0;Y=P}else{P=((ee(($[w>>1]|0)-(S<<16>>16>>>3)<<16>>16,Q[t+(y<<1)>>1]|0)|0)>>3)+-4096|0;S=(ee(P,(Q[o+(y<<1)>>1]|0)+2>>2)|0)>>14;if((S|0)>0)V=Xe(S,O)|0;else V=0-(Xe(0-S|0,O)|0)|0;x=((V<<16)+2097152>>22)+(O&65535)|0;Y=C}Q[Y>>1]=(x<<16|0)<25165824?384:x&65535;s=s+1|0}while((s|0)!=2);s=Q[g>>1]|0;w=ee(s<<16>>16,M)|0;E=Q[p>>1]|0;m=(ee(E<<16>>16,T)|0)+w|0;w=e+204+(k<<1)|0;h=576+(k<<1)|0;A=Q[w>>1]|0;C=Q[h>>1]|0;O=ee(C,A<<16>>16)|0;S=w+12|0;y=Q[S>>1]|0;P=Q[h+12>>1]|0;h=(ee(P,y<<16>>16)|0)+O|0;O=(h>>>9)-(m>>>9)<<16>>16;D=Q[616+(k<<1)>>1]|0;if((D|0)>(O|0)){N=D-O<<16>>16;O=(N*13|0)>>>2&65535;D=O+(A&65535)|0;F=D&65535;Q[w>>1]=F;L=ee(D<<16>>16,C)|0;C=O+(y&65535)|0;O=C&65535;Q[S>>1]=O;S=(ee(C<<16>>16,P)|0)+L|0;L=0-((N*49152|0)>>>16)&65535;N=L+(s&65535)|0;P=N&65535;Q[g>>1]=P;C=ee(N<<16>>16,M)|0;N=L+(E&65535)|0;L=N&65535;Q[p>>1]=L;B=S;K=(ee(N<<16>>16,T)|0)+C|0;W=F;z=O;G=P;j=L}else{B=h;K=m;W=A;z=y;G=s;j=E}r=Q[628+(k<<1)>>1]|0;E=B<<9>>16;s=r<<16>>16;if((s|0)<(E|0)){y=s-E|0;Q[w>>1]=y+(W&65535);Q[e+204+(k+6<<1)>>1]=(z&65535)+y}y=K<<9>>16;w=Q[640+(k<<1)>>1]|0;if((w|0)<(y|0)){E=w-y|0;Q[g>>1]=(G&65535)+E;Q[e+180+(k+6<<1)>>1]=(j&65535)+E}k=k+1|0}while((k|0)!=6);k=e+276|0;Ee[k>>2]=(Ee[k>>2]|0)+1;if(_<<16>>16){_=e+282|0;k=(Q[_>>1]|0)+1<<16>>16;j=k<<16>>16>6;Q[_>>1]=j?6:k;Q[e+280>>1]=j?f:c;J=d;X=J<<16;q=X>>16;Ee[e>>2]=q;ke=n;return q|0}}d=e+280|0;c=Q[d>>1]|0;if(c<<16>>16>0){Q[d>>1]=c+-1<<16>>16;Z=(c&65535)+2|0}else Z=0;Q[e+282>>1]=0;J=Z;X=J<<16;q=X>>16;Ee[e>>2]=q;ke=n;return q|0}function xe(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0;n=ke;ke=ke+1440|0;t=n+480|0;a=n;ze(r,t,e+12|0,i);ze(t,a,e+4|0,i>>1);t=He(e,a,i>>2)|0;ke=n;return t|0}function Ye(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0;n=ke;ke=ke+480|0;t=n;ze(r,t,e+4|0,i);r=He(e,t,i>>1)|0;ke=n;return r|0}function Ve(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0;t=ke;ke=ke+736|0;a=t+720|0;o=t+480|0;l=t+240|0;u=t+120|0;s=t;Q[a>>1]=0;f=i>>1;if((i|0)<=-1)he(3510,3527,266,3568);if((i|0)>=241)he(3596,3527,267,3568);Be(r,i,e+680|0,e+690|0,o,l);Be(o,f,e+682|0,e+692|0,u,s);r=i>>>2;Ke(u,r,176,a,n+10|0);Ke(s,r,176,a,n+8|0);Be(l,f,e+684|0,e+694|0,u,s);Ke(u,r,176,a,n+6|0);Be(s,r,e+686|0,e+696|0,o,l);r=i>>>3;Ke(o,r,272,a,n+4|0);Be(l,r,e+688|0,e+698|0,u,s);r=i>>>4;Ke(u,r,368,a,n+2|0);u=e+700|0;if(!r){Ke(o,r,368,a,n);c=Q[a>>1]|0;ke=t;return c|0}i=e+702|0;l=e+704|0;f=e+706|0;e=s;s=0;d=o;while(1){_=Q[e>>1]|0;M=Q[u>>1]|0;h=ee(M<<16>>16,-13262)|0;m=Q[i>>1]|0;Q[i>>1]=M;Q[u>>1]=Q[e>>1]|0;M=Q[l>>1]|0;T=((m+_|0)*6631|0)+h+((M<<16>>16)*7756|0)+(ee(Q[f>>1]|0,-5620)|0)|0;Q[f>>1]=M;M=T>>>14&65535;Q[l>>1]=M;Q[d>>1]=M;s=s+1|0;if((s|0)==(r|0))break;else{e=e+2|0;d=d+2|0}}Ke(o,r,368,a,n);c=Q[a>>1]|0;ke=t;return c|0}function Be(e,r,i,n,t,a){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;var o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0;o=r>>1;r=(o|0)>0;if(r){l=0;u=t;s=e;f=$[i>>1]<<16;while(1){c=((Q[s>>1]|0)*20972|0)+f|0;Q[u>>1]=c>>>16;d=(ee(c>>16,-20972)|0)+(Q[s>>1]<<14)|0;l=l+1|0;if((l|0)==(o|0))break;else{u=u+2|0;s=s+4|0;f=d<<1}}Q[i>>1]=d>>>15;d=$[n>>1]<<16;if(r){i=0;f=a;s=e+2|0;e=d;while(1){u=((Q[s>>1]|0)*5571|0)+e|0;Q[f>>1]=u>>>16;_=(ee(u>>16,-5571)|0)+(Q[s>>1]<<14)|0;i=i+1|0;if((i|0)==(o|0))break;else{f=f+2|0;s=s+4|0;e=_<<1}}Q[n>>1]=_>>>15;if(r){M=a;h=0;m=t}else return;while(1){t=Q[m>>1]|0;Q[m>>1]=t-($[M>>1]|0);Q[M>>1]=($[M>>1]|0)+t;h=h+1|0;if((h|0)==(o|0))break;else{M=M+2|0;m=m+2|0}}return}else T=d}else T=$[n>>1]<<16;Q[n>>1]=T>>>16;return}function Ke(e,r,i,n,t){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;var a=0,o=0,l=0;a=ke;ke=ke+16|0;o=a;Ee[o>>2]=0;if(!e)he(3615,3527,164,3631);if((r|0)<=0)he(3643,3527,165,3631);l=Qe(e,r,o)|0;if(!l){Q[t>>1]=i;ke=a;return}r=l>>>0>65535?0:16;e=(-16777216>>>r&l|0)==0?r|8:r;r=(-268435456>>>e&l|0)==0?e|4:e;e=(-1073741824>>>r&l|0)==0?r|2:r;r=17-e+(((-2147483648>>>e&l|0)==0)<<31>>31)|0;e=(Ee[o>>2]|0)+r|0;Ee[o>>2]=e;o=(r|0)<0?l<<0-r:l>>>r;r=(((e<<16>>16)*24660|0)>>>9)+(((o>>>4&1023|14336)*24660|0)>>>19)|0;Q[t>>1]=((r&32768|0)==0?r:0)+(i&65535);i=Q[n>>1]|0;if(i<<16>>16>=11){ke=a;return}Q[n>>1]=(i&65535)+((e|0)>-1?11:o>>>(0-e|0));ke=a;return}function We(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0,l=0;t=(Xe((i<<16>>16>>1)+131072|0,i)|0)<<16;i=t>>16;a=t>>18;t=((e&65535)<<3)-(r&65535)<<16>>16;r=(ee((ee(a<<14,a)|0)>>16,t)|0)>>>10;Q[n>>1]=r;n=(ee(r<<16>>16,t)|0)>>9;if((n|0)>=22005){o=0;l=ee(o,i)|0;return l|0}t=0-(((n<<16>>16)*94544|0)>>>16)|0;o=(t&1023|1024)>>>(((t<<16^-67108864)>>26)+1|0);l=ee(o,i)|0;return l|0}function ze(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0;t=Ee[i>>2]|0;a=i+4|0;o=Ee[a>>2]|0;l=n>>1;if((l|0)>0){u=0;s=o;f=t;c=r;d=e}else{_=o;M=t;Ee[i>>2]=M;Ee[a>>2]=_;return}while(1){t=(((Q[d>>1]|0)*5243|0)>>>14)+(f>>>1)|0;Q[c>>1]=t;o=d+2|0;e=t<<16>>16;t=(Q[d>>1]|0)-(e*5243>>12)|0;r=(((Q[o>>1]|0)*1392|0)>>>14)+(s>>>1)<<16>>16;Q[c>>1]=r+e;e=(Q[o>>1]|0)-(r*1392>>12)|0;u=u+1|0;if((u|0)==(l|0)){_=e;M=t;break}else{s=e;f=t;c=c+2|0;d=d+4|0}}Ee[i>>2]=M;Ee[a>>2]=_;return}function Ge(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0,v=0,p=0,A=0,S=0,b=0,y=0,g=0,E=0,k=0,w=0,R=0,C=0;n=i<<4;t=e+284+(n<<1)|0;a=e+476+(n<<1)|0;if((i|0)>=6)he(3659,3682,76,3715);n=t+30|0;o=a+30|0;l=0;do{u=t+(l<<1)|0;s=Q[u>>1]|0;if(s<<16>>16==100){f=l;do{c=f;f=f+1|0;Q[a+(c<<1)>>1]=Q[a+(f<<1)>>1]|0;Q[t+(c<<1)>>1]=Q[t+(f<<1)>>1]|0}while((f|0)!=16);Q[n>>1]=101;Q[o>>1]=1e4}else Q[u>>1]=s+1<<16>>16;l=l+1|0}while((l|0)!=16);do{if((Q[a+14>>1]|0)>r<<16>>16)if((Q[a+6>>1]|0)>r<<16>>16)if((Q[a+2>>1]|0)>r<<16>>16){d=(Q[a>>1]|0)<=r<<16>>16&1;_=25;break}else{d=(Q[a+4>>1]|0)>r<<16>>16?2:3;_=25;break}else if((Q[a+10>>1]|0)>r<<16>>16){d=(Q[a+8>>1]|0)>r<<16>>16?4:5;_=25;break}else{d=(Q[a+12>>1]|0)>r<<16>>16?6:7;_=25;break}else if((Q[o>>1]|0)>r<<16>>16)if((Q[a+22>>1]|0)>r<<16>>16)if((Q[a+18>>1]|0)>r<<16>>16){d=(Q[a+16>>1]|0)>r<<16>>16?8:9;_=25;break}else{d=(Q[a+20>>1]|0)>r<<16>>16?10:11;_=25;break}else if((Q[a+26>>1]|0)<=r<<16>>16)if((Q[a+28>>1]|0)>r<<16>>16){d=14;_=25;break}else{M=15;_=27;break}else{d=(Q[a+24>>1]|0)>r<<16>>16?12:13;_=25;break}}while(0);if((_|0)==25){o=15;do{l=o;o=o+-1|0;Q[a+(l<<1)>>1]=Q[a+(o<<1)>>1]|0;Q[t+(l<<1)>>1]=Q[t+(o<<1)>>1]|0}while((o|0)>(d|0));M=d;_=27}if((_|0)==27){Q[a+(M<<1)>>1]=r;Q[t+(M<<1)>>1]=1}M=Ee[e+276>>2]|0;if((M|0)<=2)if((M|0)>0)h=a;else{M=e+668+(i<<1)|0;m=0;T=1600;v=M;p=Q[M>>1]|0;A=m+1|0;S=p<<16>>16;b=ee(S,A)|0;y=m^32767;g=T<<16>>16;E=ee(y,g)|0;k=E+16384|0;w=k+b|0;R=w>>>15;C=R&65535;Q[v>>1]=C;return C|0}else h=a+4|0;a=Q[h>>1]|0;h=e+668+(i<<1)|0;i=Q[h>>1]|0;m=a<<16>>16>16?6553:32439;T=a;v=h;p=i;A=m+1|0;S=p<<16>>16;b=ee(S,A)|0;y=m^32767;g=T<<16>>16;E=ee(y,g)|0;k=E+16384|0;w=k+b|0;R=w>>>15;C=R&65535;Q[v>>1]=C;return C|0}function je(){se(3796,1)|0;return}function Je(){Ee[936]=1;Ee[937]=2;Ee[938]=3;Ee[939]=4;Ee[940]=5;Ee[941]=6;Ee[942]=1;Ee[943]=1;Ee[944]=1;Ee[945]=2;Ee[946]=1;Ee[947]=3;Ee[948]=4;return}function Xe(e,r){e=e|0;r=r|0;var i=0;if(!(r<<16>>16)){i=2147483647;return i|0}i=(e|0)/(r<<16>>16|0)|0;return i|0}function qe(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0;t=n+1024|0;rr(e,480,t,i);ir(t,240,n+64|0,i+32|0);t=n+32|0;e=i+96|0;Ee[t>>2]=Ee[e>>2];Ee[t+4>>2]=Ee[e+4>>2];Ee[t+8>>2]=Ee[e+8>>2];Ee[t+12>>2]=Ee[e+12>>2];Ee[t+16>>2]=Ee[e+16>>2];Ee[t+20>>2]=Ee[e+20>>2];Ee[t+24>>2]=Ee[e+24>>2];Ee[t+28>>2]=Ee[e+28>>2];a=n+992|0;Ee[e>>2]=Ee[a>>2];Ee[e+4>>2]=Ee[a+4>>2];Ee[e+8>>2]=Ee[a+8>>2];Ee[e+12>>2]=Ee[a+12>>2];Ee[e+16>>2]=Ee[a+16>>2];Ee[e+20>>2]=Ee[a+20>>2];Ee[e+24>>2]=Ee[a+24>>2];Ee[e+28>>2]=Ee[a+28>>2];$e(t,n,80);er(n,160,r,i+128|0);return}function Ze(e){e=e|0;jr(e|0,0,160)|0;return}function Qe(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0;n=ur(e,r,r)|0;if((r|0)>0){t=0;a=0;o=e}else{l=0;Ee[i>>2]=n;return l|0}while(1){e=Q[o>>1]|0;u=((ee(e,e)|0)>>>n)+t|0;a=a+1|0;if((a|0)==(r|0)){l=u;break}else{t=u;o=o+2|0}}Ee[i>>2]=n;return l|0}function $e(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0;if((i|0)>0){n=e;t=r;a=0}else return;while(1){r=n+4|0;e=((Ee[n>>2]|0)*778|0)+16384+(ee(Ee[r>>2]|0,-2050)|0)|0;o=n+8|0;l=n;n=n+12|0;u=l+16|0;s=l+20|0;f=e+((Ee[o>>2]|0)*1087|0)+((Ee[n>>2]|0)*23285|0)+((Ee[u>>2]|0)*12903|0)+(ee(Ee[s>>2]|0,-3783)|0)|0;e=l+24|0;c=l+28|0;Ee[t>>2]=f+((Ee[e>>2]|0)*441|0)+((Ee[c>>2]|0)*222|0);f=((Ee[r>>2]|0)*222|0)+16384+((Ee[o>>2]|0)*441|0)+(ee(Ee[n>>2]|0,-3783)|0)|0;o=f+((Ee[u>>2]|0)*12903|0)+((Ee[s>>2]|0)*23285|0)+((Ee[e>>2]|0)*1087|0)+(ee(Ee[c>>2]|0,-2050)|0)|0;Ee[t+4>>2]=o+((Ee[l+32>>2]|0)*778|0);a=a+1|0;if((a|0)==(i|0))break;else t=t+8|0}return}function er(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0;t=r>>1;r=(t|0)>0;if(!r)return;a=n+4|0;o=n+8|0;l=n+12|0;u=0;do{s=e+(u<<1<<2)|0;f=Ee[s>>2]|0;c=Ee[a>>2]|0;d=((f+8192-c>>14)*3050|0)+(Ee[n>>2]|0)|0;Ee[n>>2]=f;f=Ee[o>>2]|0;_=d-f>>14;M=(((_>>>31)+_|0)*9368|0)+c|0;Ee[a>>2]=d;d=M-(Ee[l>>2]|0)>>14;c=(((d>>>31)+d|0)*15063|0)+f|0;Ee[l>>2]=c;Ee[o>>2]=M;Ee[s>>2]=c>>1;u=u+1|0}while((u|0)!=(t|0));u=e+4|0;if(!r)return;o=n+20|0;l=n+16|0;a=n+24|0;c=n+28|0;n=0;do{s=u+(n<<1<<2)|0;M=Ee[s>>2]|0;f=Ee[o>>2]|0;d=((M+8192-f>>14)*821|0)+(Ee[l>>2]|0)|0;Ee[l>>2]=M;M=Ee[a>>2]|0;_=d-M>>14;h=(((_>>>31)+_|0)*6110|0)+f|0;Ee[o>>2]=d;d=h-(Ee[c>>2]|0)>>14;f=(((d>>>31)+d|0)*12382|0)+M|0;Ee[c>>2]=f;Ee[a>>2]=h;Ee[s>>2]=f>>1;n=n+1|0}while((n|0)!=(t|0));if(r)m=0;else return;do{r=m<<1;n=(Ee[e+((r|1)<<2)>>2]|0)+(Ee[e+(r<<2)>>2]|0)>>15;a=(Ee[e+((r|3)<<2)>>2]|0)+(Ee[e+((r|2)<<2)>>2]|0)>>15;r=(n|0)<32767?n:32767;Q[i+(m<<1)>>1]=(r|0)>-32768?r:-32768;r=(a|0)<32767?a:32767;Q[i+((m|1)<<1)>>1]=(r|0)>-32768?r:-32768;m=m+2|0}while((m|0)<(t|0));return}function rr(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0;t=r>>1;r=(t|0)>0;if(!r)return;a=n+4|0;o=n+8|0;l=n+12|0;u=0;do{s=Q[e+(u<<1<<1)>>1]<<15|16384;f=Ee[a>>2]|0;c=((8192-f+s>>14)*3050|0)+(Ee[n>>2]|0)|0;Ee[n>>2]=s;s=Ee[o>>2]|0;d=c-s>>14;_=(((d>>>31)+d|0)*9368|0)+f|0;Ee[a>>2]=c;c=_-(Ee[l>>2]|0)>>14;f=(((c>>>31)+c|0)*15063|0)+s|0;Ee[l>>2]=f;Ee[o>>2]=_;Ee[i+(u<<2)>>2]=f>>1;u=u+1|0}while((u|0)!=(t|0));u=e+2|0;if(!r)return;r=n+20|0;e=n+16|0;o=n+24|0;l=n+28|0;n=0;do{a=Q[u+(n<<1<<1)>>1]<<15|16384;f=Ee[r>>2]|0;_=((8192-f+a>>14)*821|0)+(Ee[e>>2]|0)|0;Ee[e>>2]=a;a=Ee[o>>2]|0;s=_-a>>14;c=(((s>>>31)+s|0)*6110|0)+f|0;Ee[r>>2]=_;_=c-(Ee[l>>2]|0)>>14;f=(((_>>>31)+_|0)*12382|0)+a|0;Ee[l>>2]=f;Ee[o>>2]=c;c=i+(n<<2)|0;Ee[c>>2]=(f>>1)+(Ee[c>>2]|0);n=n+1|0}while((n|0)!=(t|0));return}function ir(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0;t=r>>1;r=e+4|0;a=n+48|0;o=(t|0)>0;if(!o)return;l=n+4|0;u=n+8|0;s=n+12|0;f=a;c=0;while(1){d=Ee[f>>2]|0;_=Ee[l>>2]|0;M=((d+8192-_>>14)*3050|0)+(Ee[n>>2]|0)|0;Ee[n>>2]=d;d=Ee[u>>2]|0;h=M-d>>14;m=(((h>>>31)+h|0)*9368|0)+_|0;Ee[l>>2]=M;M=m-(Ee[s>>2]|0)>>14;_=(((M>>>31)+M|0)*15063|0)+d|0;Ee[s>>2]=_;Ee[u>>2]=m;m=c<<1;Ee[i+(m<<2)>>2]=_>>1;c=c+1|0;if((c|0)==(t|0))break;else f=r+(m<<2)|0}if(!o)return;f=n+20|0;c=n+16|0;u=n+24|0;s=n+28|0;l=0;do{m=l<<1;_=Ee[e+(m<<2)>>2]|0;d=Ee[f>>2]|0;M=((_+8192-d>>14)*821|0)+(Ee[c>>2]|0)|0;Ee[c>>2]=_;_=Ee[u>>2]|0;h=M-_>>14;T=(((h>>>31)+h|0)*6110|0)+d|0;Ee[f>>2]=M;M=T-(Ee[s>>2]|0)>>14;d=(((M>>>31)+M|0)*12382|0)+_|0;Ee[s>>2]=d;Ee[u>>2]=T;T=i+(m<<2)|0;Ee[T>>2]=(d>>1)+(Ee[T>>2]|0)>>15;l=l+1|0}while((l|0)!=(t|0));l=i+4|0;if(!o)return;i=n+36|0;u=n+32|0;s=n+40|0;f=n+44|0;c=0;do{T=c<<1;d=Ee[e+(T<<2)>>2]|0;m=Ee[i>>2]|0;_=((d+8192-m>>14)*3050|0)+(Ee[u>>2]|0)|0;Ee[u>>2]=d;d=Ee[s>>2]|0;M=_-d>>14;h=(((M>>>31)+M|0)*9368|0)+m|0;Ee[i>>2]=_;_=h-(Ee[f>>2]|0)>>14;m=(((_>>>31)+_|0)*15063|0)+d|0;Ee[f>>2]=m;Ee[s>>2]=h;Ee[l+(T<<2)>>2]=m>>1;c=c+1|0}while((c|0)!=(t|0));if(!o)return;o=n+52|0;c=n+56|0;s=n+60|0;n=0;do{f=n<<1;i=Ee[r+(f<<2)>>2]|0;u=Ee[o>>2]|0;e=((i+8192-u>>14)*821|0)+(Ee[a>>2]|0)|0;Ee[a>>2]=i;i=Ee[c>>2]|0;m=e-i>>14;T=(((m>>>31)+m|0)*6110|0)+u|0;Ee[o>>2]=e;e=T-(Ee[s>>2]|0)>>14;u=(((e>>>31)+e|0)*12382|0)+i|0;Ee[s>>2]=u;Ee[c>>2]=T;T=l+(f<<2)|0;Ee[T>>2]=(u>>1)+(Ee[T>>2]|0)>>15;n=n+1|0}while((n|0)!=(t|0));return}function nr(e,r,i,n,t,a,o){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;var l=0,u=0,s=0,f=0;l=1<>1;if((t|0)<0|((e|0)==0|(i|0)==0|(a|0)==0|(o|0)<1)){u=-1;return u|0}if((o|0)<=0){u=0;return u|0}s=r<<16>>16;r=n<<16>>16;n=0;do{f=ee(Q[e+(n<<1)>>1]|0,s)|0;Q[a+(n<<1)>>1]=f+l+(ee(Q[i+(n<<1)>>1]|0,r)|0)>>t;n=n+1|0}while((n|0)!=(o|0));u=0;return u|0}function tr(e){e=e|0;var r=0,i=0;if(e>>>0<=10?(r=Kr(4)|0,(r|0)!=0):0){Ee[r>>2]=e;i=r}else i=0;return i|0}function ar(e){e=e|0;if(e|0)Wr(e);return}function or(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0;n=ke;ke=ke+4096|0;t=n;a=Ee[e>>2]|0;o=1<>1]=Q[r+(u<<1)>>1]|0;Q[t+((l|1)<<1)>>1]=0;u=u+1|0;if((u|0)>=(o|0))break;else l=l+2|0}}_r(t,a);a=fr(t,Ee[e>>2]|0,1)|0;Jr(i|0,t|0,(o<<1)+4|0)|0;ke=n;return a|0}function lr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0;n=ke;ke=ke+4096|0;t=n;a=Ee[e>>2]|0;o=1<(l|0)){s=l;do{l=u-s|0;Q[t+(s<<1)>>1]=Q[r+(l<<1)>>1]|0;Q[t+(s+1<<1)>>1]=0-($[r+(l+1<<1)>>1]|0);s=s+2|0}while((u|0)>(s|0))}_r(t,a);s=cr(t,Ee[e>>2]|0,1)|0;if((a|0)==31){ke=n;return s|0}else{f=0;c=0}while(1){Q[i+(c<<1)>>1]=Q[t+(f<<1)>>1]|0;c=c+1|0;if((c|0)>=(o|0))break;else f=f+2|0}ke=n;return s|0}function ur(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0;n=i>>>0>65535?16:0;t=(65280<>16;if((r|0)>0){n=r;r=e;e=-1;i=-1;while(1){a=Q[r>>1]|0;o=a<<16>>16;l=a<<16>>16>0?o:0-o|0;o=(l<<16>>16|0)>(i|0)?l&65535:e;l=o<<16>>16;if((n|0)>1){n=n+-1|0;r=r+2|0;e=o;i=l}else{u=o;s=l;break}}}else{u=-1;s=-1}i=ee(s,s)|0;if(!i){f=0;c=u<<16>>16==0;d=(t|0)<(f|0);_=t-f|0;M=c|d;h=M?0:_;return h|0}s=i>>>0>32767?0:16;e=(-8388608>>>s&i|0)==0?s|8:s;s=(-134217728>>>e&i|0)==0?e|4:e;e=(-536870912>>>s&i|0)==0?s|2:s;f=((-1073741824>>>e&i|0)==0&1)+e|0;c=u<<16>>16==0;d=(t|0)<(f|0);_=t-f|0;M=c|d;h=M?0:_;return h|0}function sr(e,r,i,n,t,a,o,l){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;l=l|0;var u=0,s=0,f=0,c=0,d=0;u=ee(n+-1|0,o)|0;s=u+l|0;if(!((n|0)>0&(a|0)>0&(s|0)<(r|0))){f=-1;return f|0}if((u|0)<0){f=0;return f|0}else{c=l;d=i}while(1){i=2048;l=0;do{i=(ee(Q[e+(c-l<<1)>>1]|0,Q[t+(l<<1)>>1]|0)|0)+i|0;l=l+1|0}while((l|0)!=(a|0));l=i>>12;Q[d>>1]=(l|0)>32767?32767:((l|0)>-32768?l:-32768)&65535;c=c+o|0;if((c|0)>(s|0)){f=0;break}else d=d+2|0}return f|0}function fr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0,v=0,p=0,A=0;n=1<1024){t=-1;return t|0}r=(n|0)>1;if(!i){if(r){a=9;o=1}else{t=0;return t|0}while(1){i=o;o=o<<1;if((i|0)>0){l=0;do{u=l<>1]|0;f=0-($[652+(u<<1)>>1]|0)<<16>>16;u=l;do{c=u+i<<1;d=e+(c<<1)|0;_=Q[d>>1]|0;M=ee(_,s)|0;h=e+((c|1)<<1)|0;c=Q[h>>1]|0;m=M-(ee(c,f)|0)>>15;M=(ee(c,s)|0)+(ee(_,f)|0)>>15;_=u<<1;c=e+(_<<1)|0;T=Q[c>>1]|0;v=e+((_|1)<<1)|0;_=Q[v>>1]|0;Q[d>>1]=(T-m|0)>>>1;Q[h>>1]=(_-M|0)>>>1;Q[c>>1]=(m+T|0)>>>1;Q[v>>1]=(M+_|0)>>>1;u=u+o|0}while((u|0)<(n|0))}l=l+1|0}while((l|0)!=(i|0))}if((o|0)>=(n|0)){t=0;break}else a=a+-1|0}return t|0}else{if(r){p=9;A=1}else{t=0;return t|0}while(1){r=A;A=A<<1;if((r|0)>0){a=0;do{o=a<>1]|0;l=0-($[652+(o<<1)>>1]|0)<<16>>16;o=a;do{u=o+r<<1;f=e+(u<<1)|0;s=Q[f>>1]|0;_=ee(s,i)|0;M=e+((u|1)<<1)|0;u=Q[M>>1]|0;v=_+1-(ee(u,l)|0)>>1;_=(ee(s,l)|0)+1+(ee(u,i)|0)>>1;u=o<<1;s=e+(u<<1)|0;T=e+((u|1)<<1)|0;u=Q[T>>1]<<14;m=(Q[s>>1]<<14)+16384|0;Q[f>>1]=(m-v|0)>>>15;f=u+16384|0;Q[M>>1]=(f-_|0)>>>15;Q[s>>1]=(m+v|0)>>>15;Q[T>>1]=(f+_|0)>>>15;o=o+A|0}while((o|0)<(n|0))}a=a+1|0}while((a|0)!=(r|0))}if((A|0)>=(n|0)){t=0;break}else p=p+-1|0}return t|0}return 0}function cr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0,v=0,p=0,A=0,S=0,b=0,y=0,g=0,E=0;n=1<1024){t=-1;return t|0}if((n|0)<=1){t=0;return t|0}r=n<<1;a=(i|0)==0;i=0;o=9;l=1;while(1){u=vi[Ee[936]&7](e,r)|0;s=u<<16>>16>13573;f=s&1;c=u<<16>>16>27146;u=c&1;d=f+i+u|0;_=c?s?2:1:f;f=(s?16384:8192)<0;if(a){if(s){c=0;do{M=c<>1]|0;m=Q[652+(M<<1)>>1]|0;M=c;do{T=M+u<<1;v=e+(T<<1)|0;p=Q[v>>1]|0;A=ee(p,h)|0;S=e+((T|1)<<1)|0;T=Q[S>>1]|0;b=A-(ee(T,m)|0)>>15;A=(ee(T,h)|0)+(ee(p,m)|0)>>15;p=M<<1;T=e+(p<<1)|0;y=Q[T>>1]|0;g=e+((p|1)<<1)|0;p=Q[g>>1]|0;Q[v>>1]=y-b>>_;Q[S>>1]=p-A>>_;Q[T>>1]=b+y>>_;Q[g>>1]=A+p>>_;M=M+l|0}while((M|0)<(n|0))}c=c+1|0}while((c|0)!=(u|0))}}else if(s){c=_+14|0;M=0;do{m=M<>1]|0;p=Q[652+(m<<1)>>1]|0;m=M;do{A=m+u<<1;g=e+(A<<1)|0;y=Q[g>>1]|0;b=ee(y,h)|0;T=e+((A|1)<<1)|0;A=Q[T>>1]|0;S=b+1-(ee(A,p)|0)>>1;b=(ee(y,p)|0)+1+(ee(A,h)|0)>>1;A=m<<1;y=e+(A<<1)|0;v=e+((A|1)<<1)|0;A=Q[v>>1]<<14;E=(Q[y>>1]<<14)+f|0;Q[g>>1]=E-S>>c;g=A+f|0;Q[T>>1]=g-b>>c;Q[y>>1]=E+S>>c;Q[v>>1]=g+b>>c;m=m+l|0}while((m|0)<(n|0))}M=M+1|0}while((M|0)!=(u|0))}if((l|0)>=(n|0)){t=d;break}else{i=d;o=o+-1|0}}return t|0}function dr(e,r,i,n,t,a,o){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;var l=0,u=0,s=0,f=0;l=t<<16>>16;if(t<<16>>16<=0)return;t=n<<16>>16;u=o<<16>>16;o=a<<16>>16;if(n<<16>>16>0){s=0;f=e}else{jr(e|0,0,l<<2|0)|0;return}while(1){Ee[f>>2]=0;e=ee(s,u)|0;n=0;a=0;do{a=((ee(Q[i+(n+e<<1)>>1]|0,Q[r+(n<<1)>>1]|0)|0)>>o)+a|0;n=n+1|0}while((n|0)!=(t|0));Ee[f>>2]=a;s=s+1|0;if((s|0)==(l|0))break;else f=f+4|0}return}function _r(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0,l=0,u=0;if((r+-7|0)>>>0<2){i=(r|0)==8;n=i?2700:3180;t=i?240:112;i=0;do{a=e+(Q[n+(i<<1)>>1]<<2)|0;o=Ee[a>>2]|0;l=e+(Q[n+((i|1)<<1)>>1]<<2)|0;Ee[a>>2]=Ee[l>>2];Ee[l>>2]=o;i=i+2|0}while((i|0)<(t|0));return}t=1<>1}while((l|0)>(o|0));i=(l+-1&i)+l|0;o=e+(n<<2)|0;a=e+(i<<2)|0;if((i|0)>(n|0)){u=Ee[o>>2]|0;Ee[o>>2]=Ee[a>>2];Ee[a>>2]=u}n=n+1|0}while((n|0)!=(t|0));return}function Mr(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0,l=0,u=0;if((e|0)==0|(r|0)<1){i=-1;return i|0}if((r|0)>0){n=0;t=0;while(1){a=Q[e+(n<<1)>>1]|0;o=a<<16>>16;l=a<<16>>16>-1?o:0-o|0;o=(l|0)>(t|0)?l:t;n=n+1|0;if((n|0)==(r|0)){u=o;break}else t=o}}else u=0;i=((u|0)<32767?u:32767)&65535;return i|0}function hr(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0,l=0;if((e|0)==0|(r|0)<1){i=-1;return i|0}if((r|0)>0){n=0;t=0;while(1){a=Ee[e+(t<<2)>>2]|0;o=(a|0)>-1?a:0-a|0;a=o>>>0>n>>>0?o:n;t=t+1|0;if((t|0)==(r|0)){l=a;break}else n=a}}else l=0;i=l>>>0<2147483647?l:2147483647;return i|0}function mr(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0;if((r|0)>0&(e|0)!=0){i=-32768;n=0}else{t=-32768;return t|0}while(1){a=Q[e+(n<<1)>>1]|0;o=a<<16>>16>i<<16>>16?a:i;n=n+1|0;if((n|0)==(r|0)){t=o;break}else i=o}return t|0}function Tr(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0;if((r|0)>0&(e|0)!=0){i=-2147483648;n=0}else{t=-2147483648;return t|0}while(1){a=Ee[e+(n<<2)>>2]|0;o=(a|0)>(i|0)?a:i;n=n+1|0;if((n|0)==(r|0)){t=o;break}else i=o}return t|0}function vr(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0;if((r|0)>0&(e|0)!=0){i=32767;n=0}else{t=32767;return t|0}while(1){a=Q[e+(n<<1)>>1]|0;o=a<<16>>16>16?a:i;n=n+1|0;if((n|0)==(r|0)){t=o;break}else i=o}return t|0}function pr(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0;if((r|0)>0&(e|0)!=0){i=2147483647;n=0}else{t=2147483647;return t|0}while(1){a=Ee[e+(n<<2)>>2]|0;o=(a|0)<(i|0)?a:i;n=n+1|0;if((n|0)==(r|0)){t=o;break}else i=o}return t|0}function Ar(){return 3800}function Sr(e){e=e|0;var r=0,i=0;r=ke;ke=ke+16|0;i=r;Ee[i>>2]=Rr(Ee[e+60>>2]|0)|0;e=gr(ue(6,i|0)|0)|0;ke=r;return e|0}function br(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0,v=0,p=0,A=0;n=ke;ke=ke+48|0;t=n+16|0;a=n;o=n+32|0;l=e+28|0;u=Ee[l>>2]|0;Ee[o>>2]=u;s=e+20|0;f=(Ee[s>>2]|0)-u|0;Ee[o+4>>2]=f;Ee[o+8>>2]=r;Ee[o+12>>2]=i;r=f+i|0;f=e+60|0;Ee[a>>2]=Ee[f>>2];Ee[a+4>>2]=o;Ee[a+8>>2]=2;u=gr(me(146,a|0)|0)|0;e:do{if((r|0)!=(u|0)){a=2;c=r;d=o;_=u;while(1){if((_|0)<0)break;c=c-_|0;M=Ee[d+4>>2]|0;h=_>>>0>M>>>0;m=h?d+8|0:d;T=(h<<31>>31)+a|0;v=_-(h?M:0)|0;Ee[m>>2]=(Ee[m>>2]|0)+v;M=m+4|0;Ee[M>>2]=(Ee[M>>2]|0)-v;Ee[t>>2]=Ee[f>>2];Ee[t+4>>2]=m;Ee[t+8>>2]=T;_=gr(me(146,t|0)|0)|0;if((c|0)==(_|0)){p=3;break e}else{a=T;d=m}}Ee[e+16>>2]=0;Ee[l>>2]=0;Ee[s>>2]=0;Ee[e>>2]=Ee[e>>2]|32;if((a|0)==2)A=0;else A=i-(Ee[d+4>>2]|0)|0}else p=3}while(0);if((p|0)==3){p=Ee[e+44>>2]|0;Ee[e+16>>2]=p+(Ee[e+48>>2]|0);Ee[l>>2]=p;Ee[s>>2]=p;A=i}ke=n;return A|0}function yr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0;n=ke;ke=ke+32|0;t=n;a=n+20|0;Ee[t>>2]=Ee[e+60>>2];Ee[t+4>>2]=0;Ee[t+8>>2]=r;Ee[t+12>>2]=a;Ee[t+16>>2]=i;if((gr(fe(140,t|0)|0)|0)<0){Ee[a>>2]=-1;o=-1}else o=Ee[a>>2]|0;ke=n;return o|0}function gr(e){e=e|0;var r=0;if(e>>>0>4294963200){Ee[(Er()|0)>>2]=0-e;r=-1}else r=e;return r|0}function Er(){return(kr()|0)+64|0}function kr(){return wr()|0}function wr(){return 8}function Rr(e){e=e|0;return e|0}function Cr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0;n=ke;ke=ke+32|0;t=n;Ee[e+36>>2]=5;if((Ee[e>>2]&64|0)==0?(Ee[t>>2]=Ee[e+60>>2],Ee[t+4>>2]=21523,Ee[t+8>>2]=n+16,_e(54,t|0)|0):0)M[e+75>>0]=-1;t=br(e,r,i)|0;ke=n;return t|0}function Or(e){e=e|0;return 0}function Pr(e){e=e|0;return}function Nr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0;n=i+16|0;t=Ee[n>>2]|0;if(!t)if(!(Ir(i)|0)){a=Ee[n>>2]|0;o=5}else l=0;else{a=t;o=5}e:do{if((o|0)==5){t=i+20|0;n=Ee[t>>2]|0;u=n;if((a-n|0)>>>0>>0){l=di[Ee[i+36>>2]&7](i,e,r)|0;break}r:do{if((M[i+75>>0]|0)>-1){n=r;while(1){if(!n){s=0;f=e;c=r;d=u;break r}_=n+-1|0;if((M[e+_>>0]|0)==10)break;else n=_}_=di[Ee[i+36>>2]&7](i,e,n)|0;if(_>>>0>>0){l=_;break e}s=n;f=e+n|0;c=r-n|0;d=Ee[t>>2]|0}else{s=0;f=e;c=r;d=u}}while(0);Jr(d|0,f|0,c|0)|0;Ee[t>>2]=(Ee[t>>2]|0)+c;l=s+c|0}}while(0);return l|0}function Ir(e){e=e|0;var r=0,i=0,n=0;r=e+74|0;i=M[r>>0]|0;M[r>>0]=i+255|i;i=Ee[e>>2]|0;if(!(i&8)){Ee[e+8>>2]=0;Ee[e+4>>2]=0;r=Ee[e+44>>2]|0;Ee[e+28>>2]=r;Ee[e+20>>2]=r;Ee[e+16>>2]=r+(Ee[e+48>>2]|0);n=0}else{Ee[e>>2]=i|32;n=-1}return n|0}function Lr(e){e=e|0;var r=0,i=0,n=0,t=0,a=0,o=0,l=0,u=0,s=0;r=e;e:do{if(!(r&3)){i=e;n=4}else{t=e;a=r;while(1){if(!(M[t>>0]|0)){o=a;break e}l=t+1|0;a=l;if(!(a&3)){i=l;n=4;break}else t=l}}}while(0);if((n|0)==4){n=i;while(1){u=Ee[n>>2]|0;if(!((u&-2139062144^-2139062144)&u+-16843009))n=n+4|0;else break}if(!((u&255)<<24>>24))s=n;else{u=n;while(1){n=u+1|0;if(!(M[n>>0]|0)){s=n;break}else u=n}}o=s}return o-r|0}function Ur(e,r){e=e|0;r=r|0;var i=0;i=Lr(e)|0;return((Dr(e,1,i,r)|0)!=(i|0))<<31>>31|0}function Dr(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;var t=0,a=0,o=0,l=0,u=0;t=ee(i,r)|0;a=(r|0)==0?0:i;if((Ee[n+76>>2]|0)>-1){i=(Or(n)|0)==0;o=Nr(e,t,n)|0;if(i)l=o;else{Pr(n);l=o}}else l=Nr(e,t,n)|0;if((l|0)==(t|0))u=a;else u=(l>>>0)/(r>>>0)|0;return u|0}function Fr(e,r){e=e|0;r=r|0;var i=0,n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0;i=ke;ke=ke+16|0;n=i;t=r&255;M[n>>0]=t;a=e+16|0;o=Ee[a>>2]|0;if(!o)if(!(Ir(e)|0)){l=Ee[a>>2]|0;u=4}else s=-1;else{l=o;u=4}do{if((u|0)==4){o=e+20|0;a=Ee[o>>2]|0;if(a>>>0>>0?(f=r&255,(f|0)!=(M[e+75>>0]|0)):0){Ee[o>>2]=a+1;M[a>>0]=t;s=f;break}if((di[Ee[e+36>>2]&7](e,n,1)|0)==1)s=c[n>>0]|0;else s=-1}}while(0);ke=i;return s|0}function Hr(){le(3864);return 3872}function xr(){Me(3864);return}function Yr(e){e=e|0;var r=0,i=0,n=0,t=0,a=0,o=0,l=0;do{if(e){if((Ee[e+76>>2]|0)<=-1){r=Vr(e)|0;break}i=(Or(e)|0)==0;n=Vr(e)|0;if(i)r=n;else{Pr(e);r=n}}else{if(!(Ee[95]|0))t=0;else t=Yr(Ee[95]|0)|0;n=Ee[(Hr()|0)>>2]|0;if(!n)a=t;else{i=n;n=t;while(1){if((Ee[i+76>>2]|0)>-1)o=Or(i)|0;else o=0;if((Ee[i+20>>2]|0)>>>0>(Ee[i+28>>2]|0)>>>0)l=Vr(i)|0|n;else l=n;if(o|0)Pr(i);i=Ee[i+56>>2]|0;if(!i){a=l;break}else n=l}}xr();r=a}}while(0);return r|0}function Vr(e){e=e|0;var r=0,i=0,n=0,t=0,a=0,o=0,l=0;r=e+20|0;i=e+28|0;if((Ee[r>>2]|0)>>>0>(Ee[i>>2]|0)>>>0?(di[Ee[e+36>>2]&7](e,0,0)|0,(Ee[r>>2]|0)==0):0)n=-1;else{t=e+4|0;a=Ee[t>>2]|0;o=e+8|0;l=Ee[o>>2]|0;if(a>>>0>>0)di[Ee[e+40>>2]&7](e,a-l|0,1)|0;Ee[e+16>>2]=0;Ee[i>>2]=0;Ee[r>>2]=0;Ee[o>>2]=0;Ee[t>>2]=0;n=0}return n|0}function Br(e){e=e|0;var r=0,i=0,n=0,t=0,a=0;r=Ee[63]|0;if((Ee[r+76>>2]|0)>-1)i=Or(r)|0;else i=0;do{if((Ur(e,r)|0)<0)n=1;else{if((M[r+75>>0]|0)!=10?(t=r+20|0,a=Ee[t>>2]|0,a>>>0<(Ee[r+16>>2]|0)>>>0):0){Ee[t>>2]=a+1;M[a>>0]=10;n=0;break}n=(Fr(r,10)|0)<0}}while(0);if(i|0)Pr(r);return n<<31>>31|0}function Kr(e){e=e|0;var r=0,i=0,n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0,v=0,p=0,A=0,S=0,b=0,y=0,g=0,E=0,k=0,w=0,R=0,C=0,O=0,P=0,N=0,I=0,L=0,U=0,D=0,F=0,H=0,x=0,Y=0,V=0,B=0,K=0,W=0,z=0,G=0,j=0,J=0,X=0,q=0,Z=0,Q=0,$=0,ee=0,re=0,ie=0,ne=0,te=0,ae=0,oe=0,le=0,ue=0,se=0,fe=0,ce=0,de=0,_e=0,Me=0,he=0,me=0,Te=0,ve=0,pe=0,Ae=0,Se=0,be=0,ye=0,ge=0;r=ke;ke=ke+16|0;i=r;do{if(e>>>0<245){n=e>>>0<11?16:e+11&-8;t=n>>>3;a=Ee[969]|0;o=a>>>t;if(o&3|0){l=(o&1^1)+t|0;u=3916+(l<<1<<2)|0;s=u+8|0;f=Ee[s>>2]|0;c=f+8|0;d=Ee[c>>2]|0;do{if((u|0)!=(d|0)){if(d>>>0<(Ee[973]|0)>>>0)we();_=d+12|0;if((Ee[_>>2]|0)==(f|0)){Ee[_>>2]=u;Ee[s>>2]=d;break}else we()}else Ee[969]=a&~(1<>2]=d|3;s=f+d+4|0;Ee[s>>2]=Ee[s>>2]|1;M=c;ke=r;return M|0}s=Ee[971]|0;if(n>>>0>s>>>0){if(o|0){d=2<>>12&16;_=d>>>u;d=_>>>5&8;h=_>>>d;_=h>>>2&4;m=h>>>_;h=m>>>1&2;T=m>>>h;m=T>>>1&1;v=(d|u|_|h|m)+(T>>>m)|0;m=3916+(v<<1<<2)|0;T=m+8|0;h=Ee[T>>2]|0;_=h+8|0;u=Ee[_>>2]|0;do{if((m|0)!=(u|0)){if(u>>>0<(Ee[973]|0)>>>0)we();d=u+12|0;if((Ee[d>>2]|0)==(h|0)){Ee[d>>2]=m;Ee[T>>2]=u;p=a;break}else we()}else{d=a&~(1<>2]=n|3;T=h+n|0;Ee[T+4>>2]=u|1;Ee[T+u>>2]=u;if(s|0){m=Ee[974]|0;t=s>>>3;o=3916+(t<<1<<2)|0;c=1<>2]|0;if(f>>>0<(Ee[973]|0)>>>0)we();else{A=f;S=t}}else{Ee[969]=p|c;A=o;S=o+8|0}Ee[S>>2]=m;Ee[A+12>>2]=m;Ee[m+8>>2]=A;Ee[m+12>>2]=o}Ee[971]=u;Ee[974]=T;M=_;ke=r;return M|0}T=Ee[970]|0;if(T){u=(T&0-T)+-1|0;o=u>>>12&16;m=u>>>o;u=m>>>5&8;c=m>>>u;m=c>>>2&4;t=c>>>m;c=t>>>1&2;f=t>>>c;t=f>>>1&1;l=Ee[4180+((u|o|m|c|t)+(f>>>t)<<2)>>2]|0;t=(Ee[l+4>>2]&-8)-n|0;f=Ee[l+16+(((Ee[l+16>>2]|0)==0&1)<<2)>>2]|0;if(!f){b=l;y=t}else{c=l;l=t;t=f;while(1){f=(Ee[t+4>>2]&-8)-n|0;m=f>>>0>>0;o=m?f:l;f=m?t:c;t=Ee[t+16+(((Ee[t+16>>2]|0)==0&1)<<2)>>2]|0;if(!t){b=f;y=o;break}else{c=f;l=o}}}l=Ee[973]|0;if(b>>>0>>0)we();c=b+n|0;if(b>>>0>=c>>>0)we();t=Ee[b+24>>2]|0;_=Ee[b+12>>2]|0;do{if((_|0)==(b|0)){h=b+20|0;v=Ee[h>>2]|0;if(!v){o=b+16|0;f=Ee[o>>2]|0;if(!f){g=0;break}else{E=f;k=o}}else{E=v;k=h}while(1){h=E+20|0;v=Ee[h>>2]|0;if(v|0){E=v;k=h;continue}h=E+16|0;v=Ee[h>>2]|0;if(!v)break;else{E=v;k=h}}if(k>>>0>>0)we();else{Ee[k>>2]=0;g=E;break}}else{h=Ee[b+8>>2]|0;if(h>>>0>>0)we();v=h+12|0;if((Ee[v>>2]|0)!=(b|0))we();o=_+8|0;if((Ee[o>>2]|0)==(b|0)){Ee[v>>2]=_;Ee[o>>2]=h;g=_;break}else we()}}while(0);e:do{if(t|0){_=Ee[b+28>>2]|0;l=4180+(_<<2)|0;do{if((b|0)==(Ee[l>>2]|0)){Ee[l>>2]=g;if(!g){Ee[970]=T&~(1<<_);break e}}else if(t>>>0>=(Ee[973]|0)>>>0){Ee[t+16+(((Ee[t+16>>2]|0)!=(b|0)&1)<<2)>>2]=g;if(!g)break e;else break}else we()}while(0);_=Ee[973]|0;if(g>>>0<_>>>0)we();Ee[g+24>>2]=t;l=Ee[b+16>>2]|0;do{if(l|0)if(l>>>0<_>>>0)we();else{Ee[g+16>>2]=l;Ee[l+24>>2]=g;break}}while(0);l=Ee[b+20>>2]|0;if(l|0)if(l>>>0<(Ee[973]|0)>>>0)we();else{Ee[g+20>>2]=l;Ee[l+24>>2]=g;break}}}while(0);if(y>>>0<16){t=y+n|0;Ee[b+4>>2]=t|3;T=b+t+4|0;Ee[T>>2]=Ee[T>>2]|1}else{Ee[b+4>>2]=n|3;Ee[c+4>>2]=y|1;Ee[c+y>>2]=y;if(s|0){T=Ee[974]|0;t=s>>>3;l=3916+(t<<1<<2)|0;_=1<>2]|0;if(h>>>0<(Ee[973]|0)>>>0)we();else{w=h;R=t}}else{Ee[969]=a|_;w=l;R=l+8|0}Ee[R>>2]=T;Ee[w+12>>2]=T;Ee[T+8>>2]=w;Ee[T+12>>2]=l}Ee[971]=y;Ee[974]=c}M=b+8|0;ke=r;return M|0}else C=n}else C=n}else if(e>>>0<=4294967231){l=e+11|0;T=l&-8;_=Ee[970]|0;if(_){t=0-T|0;h=l>>>8;if(h)if(T>>>0>16777215)O=31;else{l=(h+1048320|0)>>>16&8;o=h<>>16&4;v=o<>>16&2;f=14-(h|l|o)+(v<>>15)|0;O=T>>>(f+7|0)&1|f<<1}else O=0;f=Ee[4180+(O<<2)>>2]|0;e:do{if(!f){P=0;N=0;I=t;L=81}else{o=0;v=t;l=f;h=T<<((O|0)==31?0:25-(O>>>1)|0);m=0;while(1){u=(Ee[l+4>>2]&-8)-T|0;if(u>>>0>>0)if(!u){U=l;D=0;F=l;L=85;break e}else{H=l;x=u}else{H=o;x=v}u=Ee[l+20>>2]|0;l=Ee[l+16+(h>>>31<<2)>>2]|0;d=(u|0)==0|(u|0)==(l|0)?m:u;u=(l|0)==0;if(u){P=d;N=H;I=x;L=81;break}else{o=H;v=x;h=h<<((u^1)&1);m=d}}}}while(0);if((L|0)==81){if((P|0)==0&(N|0)==0){f=2<>>12&16;n=f>>>t;f=n>>>5&8;c=n>>>f;n=c>>>2&4;a=c>>>n;c=a>>>1&2;s=a>>>c;a=s>>>1&1;Y=0;V=Ee[4180+((f|t|n|c|a)+(s>>>a)<<2)>>2]|0}else{Y=N;V=P}if(!V){B=Y;K=I}else{U=Y;D=I;F=V;L=85}}if((L|0)==85)while(1){L=0;a=(Ee[F+4>>2]&-8)-T|0;s=a>>>0>>0;c=s?a:D;a=s?F:U;F=Ee[F+16+(((Ee[F+16>>2]|0)==0&1)<<2)>>2]|0;if(!F){B=a;K=c;break}else{U=a;D=c;L=85}}if((B|0)!=0?K>>>0<((Ee[971]|0)-T|0)>>>0:0){c=Ee[973]|0;if(B>>>0>>0)we();a=B+T|0;if(B>>>0>=a>>>0)we();s=Ee[B+24>>2]|0;n=Ee[B+12>>2]|0;do{if((n|0)==(B|0)){t=B+20|0;f=Ee[t>>2]|0;if(!f){m=B+16|0;h=Ee[m>>2]|0;if(!h){W=0;break}else{z=h;G=m}}else{z=f;G=t}while(1){t=z+20|0;f=Ee[t>>2]|0;if(f|0){z=f;G=t;continue}t=z+16|0;f=Ee[t>>2]|0;if(!f)break;else{z=f;G=t}}if(G>>>0>>0)we();else{Ee[G>>2]=0;W=z;break}}else{t=Ee[B+8>>2]|0;if(t>>>0>>0)we();f=t+12|0;if((Ee[f>>2]|0)!=(B|0))we();m=n+8|0;if((Ee[m>>2]|0)==(B|0)){Ee[f>>2]=n;Ee[m>>2]=t;W=n;break}else we()}}while(0);e:do{if(s){n=Ee[B+28>>2]|0;c=4180+(n<<2)|0;do{if((B|0)==(Ee[c>>2]|0)){Ee[c>>2]=W;if(!W){t=_&~(1<>>0>=(Ee[973]|0)>>>0){Ee[s+16+(((Ee[s+16>>2]|0)!=(B|0)&1)<<2)>>2]=W;if(!W){j=_;break e}else break}else we()}while(0);n=Ee[973]|0;if(W>>>0>>0)we();Ee[W+24>>2]=s;c=Ee[B+16>>2]|0;do{if(c|0)if(c>>>0>>0)we();else{Ee[W+16>>2]=c;Ee[c+24>>2]=W;break}}while(0);c=Ee[B+20>>2]|0;if(c)if(c>>>0<(Ee[973]|0)>>>0)we();else{Ee[W+20>>2]=c;Ee[c+24>>2]=W;j=_;break}else j=_}else j=_}while(0);do{if(K>>>0>=16){Ee[B+4>>2]=T|3;Ee[a+4>>2]=K|1;Ee[a+K>>2]=K;_=K>>>3;if(K>>>0<256){s=3916+(_<<1<<2)|0;c=Ee[969]|0;n=1<<_;if(c&n){_=s+8|0;t=Ee[_>>2]|0;if(t>>>0<(Ee[973]|0)>>>0)we();else{J=t;X=_}}else{Ee[969]=c|n;J=s;X=s+8|0}Ee[X>>2]=a;Ee[J+12>>2]=a;Ee[a+8>>2]=J;Ee[a+12>>2]=s;break}s=K>>>8;if(s)if(K>>>0>16777215)q=31;else{n=(s+1048320|0)>>>16&8;c=s<>>16&4;_=c<>>16&2;t=14-(s|n|c)+(_<>>15)|0;q=K>>>(t+7|0)&1|t<<1}else q=0;t=4180+(q<<2)|0;Ee[a+28>>2]=q;c=a+16|0;Ee[c+4>>2]=0;Ee[c>>2]=0;c=1<>2]=a;Ee[a+24>>2]=t;Ee[a+12>>2]=a;Ee[a+8>>2]=a;break}c=K<<((q|0)==31?0:25-(q>>>1)|0);_=Ee[t>>2]|0;while(1){if((Ee[_+4>>2]&-8|0)==(K|0)){L=139;break}Z=_+16+(c>>>31<<2)|0;t=Ee[Z>>2]|0;if(!t){L=136;break}else{c=c<<1;_=t}}if((L|0)==136)if(Z>>>0<(Ee[973]|0)>>>0)we();else{Ee[Z>>2]=a;Ee[a+24>>2]=_;Ee[a+12>>2]=a;Ee[a+8>>2]=a;break}else if((L|0)==139){c=_+8|0;t=Ee[c>>2]|0;n=Ee[973]|0;if(t>>>0>=n>>>0&_>>>0>=n>>>0){Ee[t+12>>2]=a;Ee[c>>2]=a;Ee[a+8>>2]=t;Ee[a+12>>2]=_;Ee[a+24>>2]=0;break}else we()}}else{t=K+T|0;Ee[B+4>>2]=t|3;c=B+t+4|0;Ee[c>>2]=Ee[c>>2]|1}}while(0);M=B+8|0;ke=r;return M|0}else C=T}else C=T}else C=-1}while(0);B=Ee[971]|0;if(B>>>0>=C>>>0){K=B-C|0;Z=Ee[974]|0;if(K>>>0>15){q=Z+C|0;Ee[974]=q;Ee[971]=K;Ee[q+4>>2]=K|1;Ee[q+K>>2]=K;Ee[Z+4>>2]=C|3}else{Ee[971]=0;Ee[974]=0;Ee[Z+4>>2]=B|3;K=Z+B+4|0;Ee[K>>2]=Ee[K>>2]|1}M=Z+8|0;ke=r;return M|0}Z=Ee[972]|0;if(Z>>>0>C>>>0){K=Z-C|0;Ee[972]=K;B=Ee[975]|0;q=B+C|0;Ee[975]=q;Ee[q+4>>2]=K|1;Ee[B+4>>2]=C|3;M=B+8|0;ke=r;return M|0}if(!(Ee[1087]|0)){Ee[1089]=4096;Ee[1088]=4096;Ee[1090]=-1;Ee[1091]=-1;Ee[1092]=0;Ee[1080]=0;B=i&-16^1431655768;Ee[i>>2]=B;Ee[1087]=B;Q=4096}else Q=Ee[1089]|0;B=C+48|0;i=C+47|0;K=Q+i|0;q=0-Q|0;Q=K&q;if(Q>>>0<=C>>>0){M=0;ke=r;return M|0}j=Ee[1079]|0;if(j|0?(J=Ee[1077]|0,X=J+Q|0,X>>>0<=J>>>0|X>>>0>j>>>0):0){M=0;ke=r;return M|0}e:do{if(!(Ee[1080]&4)){j=Ee[975]|0;r:do{if(j){X=4324;while(1){J=Ee[X>>2]|0;if(J>>>0<=j>>>0?($=X+4|0,(J+(Ee[$>>2]|0)|0)>>>0>j>>>0):0)break;J=Ee[X+8>>2]|0;if(!J){L=163;break r}else X=J}_=K-Z&q;if(_>>>0<2147483647){J=Gr(_|0)|0;if((J|0)==((Ee[X>>2]|0)+(Ee[$>>2]|0)|0))if((J|0)==(-1|0))ee=_;else{re=_;ie=J;L=180;break e}else{ne=J;te=_;L=171}}else ee=0}else L=163}while(0);do{if((L|0)==163){j=Gr(0)|0;if((j|0)!=(-1|0)?(T=j,_=Ee[1088]|0,J=_+-1|0,W=((J&T|0)==0?0:(J+T&0-_)-T|0)+Q|0,T=Ee[1077]|0,_=W+T|0,W>>>0>C>>>0&W>>>0<2147483647):0){J=Ee[1079]|0;if(J|0?_>>>0<=T>>>0|_>>>0>J>>>0:0){ee=0;break}J=Gr(W|0)|0;if((J|0)==(j|0)){re=W;ie=j;L=180;break e}else{ne=J;te=W;L=171}}else ee=0}}while(0);do{if((L|0)==171){W=0-te|0;if(!(B>>>0>te>>>0&(te>>>0<2147483647&(ne|0)!=(-1|0))))if((ne|0)==(-1|0)){ee=0;break}else{re=te;ie=ne;L=180;break e}J=Ee[1089]|0;j=i-te+J&0-J;if(j>>>0>=2147483647){re=te;ie=ne;L=180;break e}if((Gr(j|0)|0)==(-1|0)){Gr(W|0)|0;ee=0;break}else{re=j+te|0;ie=ne;L=180;break e}}}while(0);Ee[1080]=Ee[1080]|4;ae=ee;L=178}else{ae=0;L=178}}while(0);if(((L|0)==178?Q>>>0<2147483647:0)?(ee=Gr(Q|0)|0,Q=Gr(0)|0,ne=Q-ee|0,te=ne>>>0>(C+40|0)>>>0,!((ee|0)==(-1|0)|te^1|ee>>>0>>0&((ee|0)!=(-1|0)&(Q|0)!=(-1|0))^1)):0){re=te?ne:ae;ie=ee;L=180}if((L|0)==180){ee=(Ee[1077]|0)+re|0;Ee[1077]=ee;if(ee>>>0>(Ee[1078]|0)>>>0)Ee[1078]=ee;ee=Ee[975]|0;do{if(ee){ae=4324;while(1){oe=Ee[ae>>2]|0;le=ae+4|0;ue=Ee[le>>2]|0;if((ie|0)==(oe+ue|0)){L=190;break}ne=Ee[ae+8>>2]|0;if(!ne)break;else ae=ne}if(((L|0)==190?(Ee[ae+12>>2]&8|0)==0:0)?ee>>>0>>0&ee>>>0>=oe>>>0:0){Ee[le>>2]=ue+re;ne=ee+8|0;te=(ne&7|0)==0?0:0-ne&7;ne=ee+te|0;Q=(Ee[972]|0)+(re-te)|0;Ee[975]=ne;Ee[972]=Q;Ee[ne+4>>2]=Q|1;Ee[ne+Q+4>>2]=40;Ee[976]=Ee[1091];break}Q=Ee[973]|0;if(ie>>>0>>0){Ee[973]=ie;se=ie}else se=Q;Q=ie+re|0;ne=4324;while(1){if((Ee[ne>>2]|0)==(Q|0)){L=198;break}te=Ee[ne+8>>2]|0;if(!te)break;else ne=te}if((L|0)==198?(Ee[ne+12>>2]&8|0)==0:0){Ee[ne>>2]=ie;ae=ne+4|0;Ee[ae>>2]=(Ee[ae>>2]|0)+re;ae=ie+8|0;te=ie+((ae&7|0)==0?0:0-ae&7)|0;ae=Q+8|0;i=Q+((ae&7|0)==0?0:0-ae&7)|0;ae=te+C|0;B=i-te-C|0;Ee[te+4>>2]=C|3;do{if((i|0)!=(ee|0)){if((i|0)==(Ee[974]|0)){$=(Ee[971]|0)+B|0;Ee[971]=$;Ee[974]=ae;Ee[ae+4>>2]=$|1;Ee[ae+$>>2]=$;break}$=Ee[i+4>>2]|0;if(($&3|0)==1){q=$&-8;Z=$>>>3;e:do{if($>>>0>=256){K=Ee[i+24>>2]|0;j=Ee[i+12>>2]|0;do{if((j|0)==(i|0)){W=i+16|0;J=W+4|0;_=Ee[J>>2]|0;if(!_){T=Ee[W>>2]|0;if(!T){fe=0;break}else{ce=T;de=W}}else{ce=_;de=J}while(1){J=ce+20|0;_=Ee[J>>2]|0;if(_|0){ce=_;de=J;continue}J=ce+16|0;_=Ee[J>>2]|0;if(!_)break;else{ce=_;de=J}}if(de>>>0>>0)we();else{Ee[de>>2]=0;fe=ce;break}}else{J=Ee[i+8>>2]|0;if(J>>>0>>0)we();_=J+12|0;if((Ee[_>>2]|0)!=(i|0))we();W=j+8|0;if((Ee[W>>2]|0)==(i|0)){Ee[_>>2]=j;Ee[W>>2]=J;fe=j;break}else we()}}while(0);if(!K)break;j=Ee[i+28>>2]|0;J=4180+(j<<2)|0;do{if((i|0)!=(Ee[J>>2]|0))if(K>>>0>=(Ee[973]|0)>>>0){Ee[K+16+(((Ee[K+16>>2]|0)!=(i|0)&1)<<2)>>2]=fe;if(!fe)break e;else break}else we();else{Ee[J>>2]=fe;if(fe|0)break;Ee[970]=Ee[970]&~(1<>>0>>0)we();Ee[fe+24>>2]=K;J=i+16|0;W=Ee[J>>2]|0;do{if(W|0)if(W>>>0>>0)we();else{Ee[fe+16>>2]=W;Ee[W+24>>2]=fe;break}}while(0);W=Ee[J+4>>2]|0;if(!W)break;if(W>>>0<(Ee[973]|0)>>>0)we();else{Ee[fe+20>>2]=W;Ee[W+24>>2]=fe;break}}else{W=Ee[i+8>>2]|0;j=Ee[i+12>>2]|0;K=3916+(Z<<1<<2)|0;do{if((W|0)!=(K|0)){if(W>>>0>>0)we();if((Ee[W+12>>2]|0)==(i|0))break;we()}}while(0);if((j|0)==(W|0)){Ee[969]=Ee[969]&~(1<>>0>>0)we();J=j+8|0;if((Ee[J>>2]|0)==(i|0)){_e=J;break}we()}}while(0);Ee[W+12>>2]=j;Ee[_e>>2]=W}}while(0);Me=i+q|0;he=q+B|0}else{Me=i;he=B}Z=Me+4|0;Ee[Z>>2]=Ee[Z>>2]&-2;Ee[ae+4>>2]=he|1;Ee[ae+he>>2]=he;Z=he>>>3;if(he>>>0<256){$=3916+(Z<<1<<2)|0;X=Ee[969]|0;K=1<>2]|0;if(J>>>0>=(Ee[973]|0)>>>0){me=J;Te=Z;break}we()}}while(0);Ee[Te>>2]=ae;Ee[me+12>>2]=ae;Ee[ae+8>>2]=me;Ee[ae+12>>2]=$;break}K=he>>>8;do{if(!K)ve=0;else{if(he>>>0>16777215){ve=31;break}X=(K+1048320|0)>>>16&8;q=K<>>16&4;J=q<>>16&2;_=14-(Z|X|q)+(J<>>15)|0;ve=he>>>(_+7|0)&1|_<<1}}while(0);K=4180+(ve<<2)|0;Ee[ae+28>>2]=ve;$=ae+16|0;Ee[$+4>>2]=0;Ee[$>>2]=0;$=Ee[970]|0;_=1<>2]=ae;Ee[ae+24>>2]=K;Ee[ae+12>>2]=ae;Ee[ae+8>>2]=ae;break}_=he<<((ve|0)==31?0:25-(ve>>>1)|0);$=Ee[K>>2]|0;while(1){if((Ee[$+4>>2]&-8|0)==(he|0)){L=265;break}pe=$+16+(_>>>31<<2)|0;K=Ee[pe>>2]|0;if(!K){L=262;break}else{_=_<<1;$=K}}if((L|0)==262)if(pe>>>0<(Ee[973]|0)>>>0)we();else{Ee[pe>>2]=ae;Ee[ae+24>>2]=$;Ee[ae+12>>2]=ae;Ee[ae+8>>2]=ae;break}else if((L|0)==265){_=$+8|0;K=Ee[_>>2]|0;q=Ee[973]|0;if(K>>>0>=q>>>0&$>>>0>=q>>>0){Ee[K+12>>2]=ae;Ee[_>>2]=ae;Ee[ae+8>>2]=K;Ee[ae+12>>2]=$;Ee[ae+24>>2]=0;break}else we()}}else{K=(Ee[972]|0)+B|0;Ee[972]=K;Ee[975]=ae;Ee[ae+4>>2]=K|1}}while(0);M=te+8|0;ke=r;return M|0}ae=4324;while(1){B=Ee[ae>>2]|0;if(B>>>0<=ee>>>0?(Ae=B+(Ee[ae+4>>2]|0)|0,Ae>>>0>ee>>>0):0)break;ae=Ee[ae+8>>2]|0}ae=Ae+-47|0;te=ae+8|0;B=ae+((te&7|0)==0?0:0-te&7)|0;te=ee+16|0;ae=B>>>0>>0?ee:B;B=ae+8|0;i=ie+8|0;Q=(i&7|0)==0?0:0-i&7;i=ie+Q|0;ne=re+-40-Q|0;Ee[975]=i;Ee[972]=ne;Ee[i+4>>2]=ne|1;Ee[i+ne+4>>2]=40;Ee[976]=Ee[1091];ne=ae+4|0;Ee[ne>>2]=27;Ee[B>>2]=Ee[1081];Ee[B+4>>2]=Ee[1082];Ee[B+8>>2]=Ee[1083];Ee[B+12>>2]=Ee[1084];Ee[1081]=ie;Ee[1082]=re;Ee[1084]=0;Ee[1083]=B;B=ae+24|0;do{i=B;B=B+4|0;Ee[B>>2]=7}while((i+8|0)>>>0>>0);if((ae|0)!=(ee|0)){B=ae-ee|0;Ee[ne>>2]=Ee[ne>>2]&-2;Ee[ee+4>>2]=B|1;Ee[ae>>2]=B;i=B>>>3;if(B>>>0<256){Q=3916+(i<<1<<2)|0;K=Ee[969]|0;_=1<>2]|0;if(q>>>0<(Ee[973]|0)>>>0)we();else{Se=q;be=i}}else{Ee[969]=K|_;Se=Q;be=Q+8|0}Ee[be>>2]=ee;Ee[Se+12>>2]=ee;Ee[ee+8>>2]=Se;Ee[ee+12>>2]=Q;break}Q=B>>>8;if(Q)if(B>>>0>16777215)ye=31;else{_=(Q+1048320|0)>>>16&8;K=Q<<_;Q=(K+520192|0)>>>16&4;i=K<>>16&2;q=14-(Q|_|K)+(i<>>15)|0;ye=B>>>(q+7|0)&1|q<<1}else ye=0;q=4180+(ye<<2)|0;Ee[ee+28>>2]=ye;Ee[ee+20>>2]=0;Ee[te>>2]=0;K=Ee[970]|0;i=1<>2]=ee;Ee[ee+24>>2]=q;Ee[ee+12>>2]=ee;Ee[ee+8>>2]=ee;break}i=B<<((ye|0)==31?0:25-(ye>>>1)|0);K=Ee[q>>2]|0;while(1){if((Ee[K+4>>2]&-8|0)==(B|0)){L=292;break}ge=K+16+(i>>>31<<2)|0;q=Ee[ge>>2]|0;if(!q){L=289;break}else{i=i<<1;K=q}}if((L|0)==289)if(ge>>>0<(Ee[973]|0)>>>0)we();else{Ee[ge>>2]=ee;Ee[ee+24>>2]=K;Ee[ee+12>>2]=ee;Ee[ee+8>>2]=ee;break}else if((L|0)==292){i=K+8|0;B=Ee[i>>2]|0;te=Ee[973]|0;if(B>>>0>=te>>>0&K>>>0>=te>>>0){Ee[B+12>>2]=ee;Ee[i>>2]=ee;Ee[ee+8>>2]=B;Ee[ee+12>>2]=K;Ee[ee+24>>2]=0;break}else we()}}}else{B=Ee[973]|0;if((B|0)==0|ie>>>0>>0)Ee[973]=ie;Ee[1081]=ie;Ee[1082]=re;Ee[1084]=0;Ee[978]=Ee[1087];Ee[977]=-1;B=0;do{i=3916+(B<<1<<2)|0;Ee[i+12>>2]=i;Ee[i+8>>2]=i;B=B+1|0}while((B|0)!=32);B=ie+8|0;K=(B&7|0)==0?0:0-B&7;B=ie+K|0;i=re+-40-K|0;Ee[975]=B;Ee[972]=i;Ee[B+4>>2]=i|1;Ee[B+i+4>>2]=40;Ee[976]=Ee[1091]}}while(0);re=Ee[972]|0;if(re>>>0>C>>>0){ie=re-C|0;Ee[972]=ie;re=Ee[975]|0;ee=re+C|0;Ee[975]=ee;Ee[ee+4>>2]=ie|1;Ee[re+4>>2]=C|3;M=re+8|0;ke=r;return M|0}}Ee[(Er()|0)>>2]=12;M=0;ke=r;return M|0}function Wr(e){e=e|0;var r=0,i=0,n=0,t=0,a=0,o=0,l=0,u=0,s=0,f=0,c=0,d=0,_=0,M=0,h=0,m=0,T=0,v=0,p=0,A=0,S=0,b=0,y=0,g=0,E=0,k=0,w=0,R=0,C=0,O=0,P=0;if(!e)return;r=e+-8|0;i=Ee[973]|0;if(r>>>0>>0)we();n=Ee[e+-4>>2]|0;e=n&3;if((e|0)==1)we();t=n&-8;a=r+t|0;e:do{if(!(n&1)){o=Ee[r>>2]|0;if(!e)return;l=r+(0-o)|0;u=o+t|0;if(l>>>0>>0)we();if((l|0)==(Ee[974]|0)){s=a+4|0;f=Ee[s>>2]|0;if((f&3|0)!=3){c=l;d=u;_=l;break}Ee[971]=u;Ee[s>>2]=f&-2;Ee[l+4>>2]=u|1;Ee[l+u>>2]=u;return}f=o>>>3;if(o>>>0<256){o=Ee[l+8>>2]|0;s=Ee[l+12>>2]|0;M=3916+(f<<1<<2)|0;if((o|0)!=(M|0)){if(o>>>0>>0)we();if((Ee[o+12>>2]|0)!=(l|0))we()}if((s|0)==(o|0)){Ee[969]=Ee[969]&~(1<>>0>>0)we();M=s+8|0;if((Ee[M>>2]|0)==(l|0))h=M;else we()}else h=s+8|0;Ee[o+12>>2]=s;Ee[h>>2]=o;c=l;d=u;_=l;break}o=Ee[l+24>>2]|0;s=Ee[l+12>>2]|0;do{if((s|0)==(l|0)){M=l+16|0;f=M+4|0;m=Ee[f>>2]|0;if(!m){T=Ee[M>>2]|0;if(!T){v=0;break}else{p=T;A=M}}else{p=m;A=f}while(1){f=p+20|0;m=Ee[f>>2]|0;if(m|0){p=m;A=f;continue}f=p+16|0;m=Ee[f>>2]|0;if(!m)break;else{p=m;A=f}}if(A>>>0>>0)we();else{Ee[A>>2]=0;v=p;break}}else{f=Ee[l+8>>2]|0;if(f>>>0>>0)we();m=f+12|0;if((Ee[m>>2]|0)!=(l|0))we();M=s+8|0;if((Ee[M>>2]|0)==(l|0)){Ee[m>>2]=s;Ee[M>>2]=f;v=s;break}else we()}}while(0);if(o){s=Ee[l+28>>2]|0;f=4180+(s<<2)|0;do{if((l|0)==(Ee[f>>2]|0)){Ee[f>>2]=v;if(!v){Ee[970]=Ee[970]&~(1<>>0>=(Ee[973]|0)>>>0){Ee[o+16+(((Ee[o+16>>2]|0)!=(l|0)&1)<<2)>>2]=v;if(!v){c=l;d=u;_=l;break e}else break}else we()}while(0);s=Ee[973]|0;if(v>>>0>>0)we();Ee[v+24>>2]=o;f=l+16|0;M=Ee[f>>2]|0;do{if(M|0)if(M>>>0>>0)we();else{Ee[v+16>>2]=M;Ee[M+24>>2]=v;break}}while(0);M=Ee[f+4>>2]|0;if(M)if(M>>>0<(Ee[973]|0)>>>0)we();else{Ee[v+20>>2]=M;Ee[M+24>>2]=v;c=l;d=u;_=l;break}else{c=l;d=u;_=l}}else{c=l;d=u;_=l}}else{c=r;d=t;_=r}}while(0);if(_>>>0>=a>>>0)we();r=a+4|0;t=Ee[r>>2]|0;if(!(t&1))we();if(!(t&2)){v=Ee[974]|0;if((a|0)==(Ee[975]|0)){i=(Ee[972]|0)+d|0;Ee[972]=i;Ee[975]=c;Ee[c+4>>2]=i|1;if((c|0)!=(v|0))return;Ee[974]=0;Ee[971]=0;return}if((a|0)==(v|0)){v=(Ee[971]|0)+d|0;Ee[971]=v;Ee[974]=_;Ee[c+4>>2]=v|1;Ee[_+v>>2]=v;return}v=(t&-8)+d|0;i=t>>>3;e:do{if(t>>>0>=256){p=Ee[a+24>>2]|0;A=Ee[a+12>>2]|0;do{if((A|0)==(a|0)){h=a+16|0;e=h+4|0;n=Ee[e>>2]|0;if(!n){M=Ee[h>>2]|0;if(!M){S=0;break}else{b=M;y=h}}else{b=n;y=e}while(1){e=b+20|0;n=Ee[e>>2]|0;if(n|0){b=n;y=e;continue}e=b+16|0;n=Ee[e>>2]|0;if(!n)break;else{b=n;y=e}}if(y>>>0<(Ee[973]|0)>>>0)we();else{Ee[y>>2]=0;S=b;break}}else{e=Ee[a+8>>2]|0;if(e>>>0<(Ee[973]|0)>>>0)we();n=e+12|0;if((Ee[n>>2]|0)!=(a|0))we();h=A+8|0;if((Ee[h>>2]|0)==(a|0)){Ee[n>>2]=A;Ee[h>>2]=e;S=A;break}else we()}}while(0);if(p|0){A=Ee[a+28>>2]|0;l=4180+(A<<2)|0;do{if((a|0)==(Ee[l>>2]|0)){Ee[l>>2]=S;if(!S){Ee[970]=Ee[970]&~(1<>>0>=(Ee[973]|0)>>>0){Ee[p+16+(((Ee[p+16>>2]|0)!=(a|0)&1)<<2)>>2]=S;if(!S)break e;else break}else we()}while(0);A=Ee[973]|0;if(S>>>0>>0)we();Ee[S+24>>2]=p;l=a+16|0;u=Ee[l>>2]|0;do{if(u|0)if(u>>>0>>0)we();else{Ee[S+16>>2]=u;Ee[u+24>>2]=S;break}}while(0);u=Ee[l+4>>2]|0;if(u|0)if(u>>>0<(Ee[973]|0)>>>0)we();else{Ee[S+20>>2]=u;Ee[u+24>>2]=S;break}}}else{u=Ee[a+8>>2]|0;A=Ee[a+12>>2]|0;p=3916+(i<<1<<2)|0;if((u|0)!=(p|0)){if(u>>>0<(Ee[973]|0)>>>0)we();if((Ee[u+12>>2]|0)!=(a|0))we()}if((A|0)==(u|0)){Ee[969]=Ee[969]&~(1<>>0<(Ee[973]|0)>>>0)we();p=A+8|0;if((Ee[p>>2]|0)==(a|0))g=p;else we()}else g=A+8|0;Ee[u+12>>2]=A;Ee[g>>2]=u}}while(0);Ee[c+4>>2]=v|1;Ee[_+v>>2]=v;if((c|0)==(Ee[974]|0)){Ee[971]=v;return}else E=v}else{Ee[r>>2]=t&-2;Ee[c+4>>2]=d|1;Ee[_+d>>2]=d;E=d}d=E>>>3;if(E>>>0<256){_=3916+(d<<1<<2)|0;t=Ee[969]|0;r=1<>2]|0;if(v>>>0<(Ee[973]|0)>>>0)we();else{k=v;w=d}}else{Ee[969]=t|r;k=_;w=_+8|0}Ee[w>>2]=c;Ee[k+12>>2]=c;Ee[c+8>>2]=k;Ee[c+12>>2]=_;return}_=E>>>8;if(_)if(E>>>0>16777215)R=31;else{k=(_+1048320|0)>>>16&8;w=_<>>16&4;r=w<<_;w=(r+245760|0)>>>16&2;t=14-(_|k|w)+(r<>>15)|0;R=E>>>(t+7|0)&1|t<<1}else R=0;t=4180+(R<<2)|0;Ee[c+28>>2]=R;Ee[c+20>>2]=0;Ee[c+16>>2]=0;w=Ee[970]|0;r=1<>>1)|0);_=Ee[t>>2]|0;while(1){if((Ee[_+4>>2]&-8|0)==(E|0)){C=124;break}O=_+16+(k>>>31<<2)|0;d=Ee[O>>2]|0;if(!d){C=121;break}else{k=k<<1;_=d}}if((C|0)==121)if(O>>>0<(Ee[973]|0)>>>0)we();else{Ee[O>>2]=c;Ee[c+24>>2]=_;Ee[c+12>>2]=c;Ee[c+8>>2]=c;break}else if((C|0)==124){k=_+8|0;l=Ee[k>>2]|0;d=Ee[973]|0;if(l>>>0>=d>>>0&_>>>0>=d>>>0){Ee[l+12>>2]=c;Ee[k>>2]=c;Ee[c+8>>2]=l;Ee[c+12>>2]=_;Ee[c+24>>2]=0;break}else we()}}else{Ee[970]=w|r;Ee[t>>2]=c;Ee[c+24>>2]=t;Ee[c+12>>2]=c;Ee[c+8>>2]=c}}while(0);c=(Ee[977]|0)+-1|0;Ee[977]=c;if(!c)P=4332;else return;while(1){c=Ee[P>>2]|0;if(!c)break;else P=c+8|0}Ee[977]=-1;return}function zr(){}function Gr(e){e=e|0;var r=0,i=0;e=e+15&-16|0;r=Ee[o>>2]|0;i=r+e|0;if((e|0)>0&(i|0)<(r|0)|(i|0)<0){X()|0;ce(12);return-1}Ee[o>>2]=i;if((i|0)>(J()|0)?(j()|0)==0:0){ce(12);Ee[o>>2]=r;return-1}return r|0}function jr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0,o=0;n=e+i|0;r=r&255;if((i|0)>=67){while(e&3){M[e>>0]=r;e=e+1|0}t=n&-4|0;a=t-64|0;o=r|r<<8|r<<16|r<<24;while((e|0)<=(a|0)){Ee[e>>2]=o;Ee[e+4>>2]=o;Ee[e+8>>2]=o;Ee[e+12>>2]=o;Ee[e+16>>2]=o;Ee[e+20>>2]=o;Ee[e+24>>2]=o;Ee[e+28>>2]=o;Ee[e+32>>2]=o;Ee[e+36>>2]=o;Ee[e+40>>2]=o;Ee[e+44>>2]=o;Ee[e+48>>2]=o;Ee[e+52>>2]=o;Ee[e+56>>2]=o;Ee[e+60>>2]=o;e=e+64|0}while((e|0)<(t|0)){Ee[e>>2]=o;e=e+4|0}}while((e|0)<(n|0)){M[e>>0]=r;e=e+1|0}return n-i|0}function Jr(e,r,i){e=e|0;r=r|0;i=i|0;var n=0,t=0,a=0;if((i|0)>=8192)return de(e|0,r|0,i|0)|0;n=e|0;t=e+i|0;if((e&3)==(r&3)){while(e&3){if(!i)return n|0;M[e>>0]=M[r>>0]|0;e=e+1|0;r=r+1|0;i=i-1|0}a=t&-4|0;i=a-64|0;while((e|0)<=(i|0)){Ee[e>>2]=Ee[r>>2];Ee[e+4>>2]=Ee[r+4>>2];Ee[e+8>>2]=Ee[r+8>>2];Ee[e+12>>2]=Ee[r+12>>2];Ee[e+16>>2]=Ee[r+16>>2];Ee[e+20>>2]=Ee[r+20>>2];Ee[e+24>>2]=Ee[r+24>>2];Ee[e+28>>2]=Ee[r+28>>2];Ee[e+32>>2]=Ee[r+32>>2];Ee[e+36>>2]=Ee[r+36>>2];Ee[e+40>>2]=Ee[r+40>>2];Ee[e+44>>2]=Ee[r+44>>2];Ee[e+48>>2]=Ee[r+48>>2];Ee[e+52>>2]=Ee[r+52>>2];Ee[e+56>>2]=Ee[r+56>>2];Ee[e+60>>2]=Ee[r+60>>2];e=e+64|0;r=r+64|0}while((e|0)<(a|0)){Ee[e>>2]=Ee[r>>2];e=e+4|0;r=r+4|0}}else{a=t-4|0;while((e|0)<(a|0)){M[e>>0]=M[r>>0]|0;M[e+1>>0]=M[r+1>>0]|0;M[e+2>>0]=M[r+2>>0]|0;M[e+3>>0]=M[r+3>>0]|0;e=e+4|0;r=r+4|0}}while((e|0)<(t|0)){M[e>>0]=M[r>>0]|0;e=e+1|0;r=r+1|0}return n|0}function Xr(e,r,i,n,t,a,o,l){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;l=l|0;return ci[e&1](r|0,i|0,n|0,t|0,a|0,o|0,l|0)|0}function qr(e,r,i,n){e=e|0;r=r|0;i=i|0;n=n|0;return di[e&7](r|0,i|0,n|0)|0}function Zr(e,r){e=e|0;r=r|0;_i[e&1](r|0)}function Qr(e,r){e=e|0;r=r|0;return Mi[e&3](r|0)|0}function $r(e,r,i,n,t,a,o,l){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;l=l|0;hi[e&1](r|0,i|0,n|0,t|0,a|0,o|0,l|0)}function ei(e){e=e|0;mi[e&1]()}function ri(e,r,i,n,t,a,o,l,u){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;l=l|0;u=u|0;return Ti[e&1](r|0,i|0,n|0,t|0,a|0,o|0,l|0,u|0)|0}function ii(e,r,i){e=e|0;r=r|0;i=i|0;return vi[e&7](r|0,i|0)|0}function ni(e,r,i,n,t,a,o){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;z(0);return 0}function ti(e,r,i){e=e|0;r=r|0;i=i|0;z(1);return 0}function ai(e){e=e|0;z(2)}function oi(e){e=e|0;z(3);return 0}function li(e,r,i,n,t,a,o){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;z(4)}function ui(){z(5)}function si(e,r,i,n,t,a,o,l){e=e|0;r=r|0;i=i|0;n=n|0;t=t|0;a=a|0;o=o|0;l=l|0;z(6);return 0}function fi(e,r){e=e|0;r=r|0;z(7);return 0}var ci=[ni,nr];var di=[ti,Cr,yr,or,lr,br,ti,ti];var _i=[ai,ar];var Mi=[oi,Sr,tr,oi];var hi=[li,dr];var mi=[ui,Je];var Ti=[si,sr];var vi=[fi,Mr,hr,mr,Tr,vr,pr,fi];return{_sbrk:Gr,_fflush:Yr,_main:Re,_process_data:Oe,_memset:jr,_malloc:Kr,_emscripten_get_global_libc:Ar,_memcpy:Jr,_setmode:Ce,_free:Wr,___errno_location:Er,runPostSets:zr,stackAlloc:ve,stackSave:pe,stackRestore:Ae,establishStackSpace:Se,setTempRet0:ye,getTempRet0:ge,setThrew:be,stackAlloc:ve,stackSave:pe,stackRestore:Ae,establishStackSpace:Se,setThrew:be,setTempRet0:ye,getTempRet0:ge,dynCall_iiiiiiii:Xr,dynCall_iiii:qr,dynCall_vi:Zr,dynCall_ii:Qr,dynCall_viiiiiii:$r,dynCall_v:ei,dynCall_iiiiiiiii:ri,dynCall_iii:ii}}(Module.asmGlobalArg,Module.asmLibraryArg,buffer),_malloc=Module._malloc=asm._malloc,getTempRet0=Module.getTempRet0=asm.getTempRet0,_fflush=Module._fflush=asm._fflush,_main=Module._main=asm._main,setTempRet0=Module.setTempRet0=asm.setTempRet0,_process_data=Module._process_data=asm._process_data,stackSave=Module.stackSave=asm.stackSave,_memset=Module._memset=asm._memset,_sbrk=Module._sbrk=asm._sbrk,establishStackSpace=Module.establishStackSpace=asm.establishStackSpace,_emscripten_get_global_libc=Module._emscripten_get_global_libc=asm._emscripten_get_global_libc,_memcpy=Module._memcpy=asm._memcpy,_setmode=Module._setmode=asm._setmode,stackAlloc=Module.stackAlloc=asm.stackAlloc,setThrew=Module.setThrew=asm.setThrew,_free=Module._free=asm._free,stackRestore=Module.stackRestore=asm.stackRestore,___errno_location=Module.___errno_location=asm.___errno_location,runPostSets=Module.runPostSets=asm.runPostSets,dynCall_iiiiiiii=Module.dynCall_iiiiiiii=asm.dynCall_iiiiiiii,dynCall_iiii=Module.dynCall_iiii=asm.dynCall_iiii,dynCall_vi=Module.dynCall_vi=asm.dynCall_vi,dynCall_ii=Module.dynCall_ii=asm.dynCall_ii,dynCall_viiiiiii=Module.dynCall_viiiiiii=asm.dynCall_viiiiiii,dynCall_v=Module.dynCall_v=asm.dynCall_v,dynCall_iiiiiiiii=Module.dynCall_iiiiiiiii=asm.dynCall_iiiiiiiii,dynCall_iii=Module.dynCall_iii=asm.dynCall_iii,initialStackTop;function ExitStatus(e){this.name="ExitStatus",this.message="Program terminated with exit("+e+")",this.status=e}Runtime.stackAlloc=Module.stackAlloc,Runtime.stackSave=Module.stackSave,Runtime.stackRestore=Module.stackRestore,Runtime.establishStackSpace=Module.establishStackSpace,Runtime.setTempRet0=Module.setTempRet0,Runtime.getTempRet0=Module.getTempRet0,Module.asm=asm,ExitStatus.prototype=new Error,ExitStatus.prototype.constructor=ExitStatus;var preloadStartTime=null,calledMain=!1;function run(e){function r(){Module.calledRun||(Module.calledRun=!0,ABORT||(ensureInitRuntime(),preMain(),Module.onRuntimeInitialized&&Module.onRuntimeInitialized(),Module._main&&shouldRunNow&&Module.callMain(e),postRun()))}e=e||Module.arguments,null===preloadStartTime&&(preloadStartTime=Date.now()),0 2 | 3 | 4 | 5 | SpeakToMe 6 | 7 | 15 | 16 | 17 | 18 |
19 |

SpeakToMe - Mozilla Cloud-based Speech Recognition API

20 | 21 |
22 | 23 |

24 | 25 | 26 | 28 |
29 | 30 |
31 |
32 |
33 |
34 |
35 | 36 | 37 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "speaktome-api", 3 | "version": "0.3.0", 4 | "description": "JavaScript modules for Mozilla's cloud speech recognition API", 5 | "scripts": { 6 | "format": "prettier 'src/*.js' --tab-width=2 --arrow-parens=always --trailing-comma=es5 --no-bracket-spacing --write", 7 | "lint": "eslint src", 8 | "bundle": "browserify src/stm.js src/stm_vad.js node_modules/webrtcvad_js/webrtc_vad.js --noparse=node_modules/webrtcvad_js/webrtc_vad.js -s SpeakToMe -o build/stm.js -p browserify-derequire", 9 | "uglify": "uglifyjs build/stm.js -cm > build/stm.min.js", 10 | "web": "uglifyjs src/stm.js src/stm_vad.js node_modules/webrtcvad_js/webrtc_vad.js -cm > build/stm_web.min.js", 11 | "build": "npm run bundle && npm run uglify && npm run web", 12 | "test": "echo \"Error: no test specified\" && exit 1" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "git+https://github.com/mozilla/speaktome-web.git" 17 | }, 18 | "keywords": [ 19 | "Mozilla", 20 | "speech", 21 | "speech recognition", 22 | "speak to me", 23 | "speaktome", 24 | "STT" 25 | ], 26 | "license": "MPL-2.0", 27 | "bugs": { 28 | "url": "https://github.com/mozilla/speaktome-web/issues" 29 | }, 30 | "homepage": "https://github.com/mozilla/speaktome-web#readme", 31 | "devDependencies": { 32 | "browserify": "^16.2.3", 33 | "browserify-derequire": "^0.9.6", 34 | "eslint": "^5.10.0", 35 | "eslint-plugin-mozilla": "^1.0.1", 36 | "eslint-plugin-no-unsanitized": "^3.0.2", 37 | "prettier": "^1.15.3", 38 | "uglify-js": "^3.4.9" 39 | }, 40 | "dependencies": { 41 | "webrtcvad_js": "^1.0.0" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/stm.js: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | TODO: 4 | 5 | * fix VAD re-use 6 | 7 | states/events 8 | 9 | * ready 10 | * listening 11 | * processing 12 | * sending 13 | * result 14 | * error 15 | 16 | 17 | */ 18 | 19 | var STT_SERVER_URL = "https://speaktome-2.services.mozilla.com/"; 20 | 21 | var RECORDING_TIMEOUT = 3000; 22 | 23 | var RECORDING_BITS_PER_SECOND = 16000; 24 | 25 | var RECORDING_MIME_TYPE = "audio/ogg"; 26 | if (!MediaRecorder.isTypeSupported(RECORDING_MIME_TYPE)) { 27 | RECORDING_MIME_TYPE = "audio/webm;codecs=opus"; 28 | } 29 | 30 | (function initCompat() { 31 | // Older browsers might not implement mediaDevices at all, so we set an empty 32 | // object first 33 | if (typeof navigator.mediaDevices === "undefined") { 34 | navigator.mediaDevices = {}; 35 | } 36 | 37 | // Some browsers partially implement mediaDevices. We can't just assign an 38 | // object with getUserMedia as it would overwrite existing properties. 39 | // Here, we will just add the getUserMedia property if it's missing. 40 | if (typeof navigator.mediaDevices.getUserMedia === "undefined") { 41 | navigator.mediaDevices.getUserMedia = function(constraints) { 42 | // First get ahold of the legacy getUserMedia, if present 43 | var getUserMedia = 44 | navigator.webkitGetUserMedia || navigator.mozGetUserMedia; 45 | 46 | // Some browsers just don't implement it - return a rejected promise with 47 | // an error to keep a consistent interface 48 | if (!getUserMedia) { 49 | return Promise.reject( 50 | new Error("getUserMedia is not implemented in this browser") 51 | ); 52 | } 53 | 54 | // Otherwise, wrap the call to the old navigator.getUserMedia with a 55 | // Promise 56 | return new Promise(function(resolve, reject) { 57 | getUserMedia.call(navigator, constraints, resolve, reject); 58 | }); 59 | }; 60 | } 61 | })(); 62 | 63 | function SpeakToMe(options) { 64 | // Default config 65 | var config = { 66 | vad: true, 67 | timeout: RECORDING_TIMEOUT, 68 | continuous: false, 69 | serverURL: STT_SERVER_URL, 70 | listener: null, 71 | language: "en-US", 72 | productTag: null, 73 | storeSample: false, 74 | storeTranscription: false, 75 | }; 76 | 77 | // Caller options 78 | if (typeof options === "object") { 79 | if (typeof options.vad === "boolean") { 80 | config.vad = options.vad; 81 | } 82 | if (options.timeout) { 83 | // TODO: validate 84 | config.timeout = options.timeout; 85 | } 86 | if (options.listener) { 87 | config.listener = options.listener; 88 | } 89 | if (options.language) { 90 | config.language = options.language; 91 | } 92 | if (options.productTag) { 93 | config.productTag = options.productTag; 94 | } 95 | if (typeof options.storeSample === "boolean") { 96 | config.storeSample = options.storeSample; 97 | } 98 | if (typeof options.storeTranscription === "boolean") { 99 | config.storeTranscription = options.storeTranscription; 100 | } 101 | } 102 | 103 | /* 104 | 105 | States: 106 | 107 | * ready: recorder inactive 108 | * listening: recorder active 109 | * sending: sending recording 110 | * waitingonserver: sent recording, waiting for response 111 | * result: received result 112 | 113 | */ 114 | var state = "ready"; 115 | 116 | // Lazy initialized in listen() 117 | var VAD = null; 118 | 119 | // Recording bits initialized in listen and destroyed in stop. 120 | var audioContext, 121 | sourceNode, 122 | analyzerNode, 123 | outputNode, 124 | scriptProcessor, 125 | mediaRecorder, 126 | mediaStream, 127 | vadReason; 128 | 129 | // Start recording 130 | function listen() { 131 | // Callers should only listen after receiving 132 | // the 'ready' state event, so we can ignore 133 | // their requests if we're not ready. 134 | if (state !== "ready") { 135 | console.warn("Listen() called when not ready"); 136 | return; 137 | } 138 | 139 | // Lazy init VAD on first-use 140 | // TODO: Fix VAD re-use. Fails for some reason on successive use. 141 | /* 142 | if (config.vad && !VAD) { 143 | function onVADComplete(reason) { 144 | console.log('onVADComplete', reason); 145 | vadReason = reason; 146 | stop(); 147 | } 148 | VAD = SpeakToMeVAD({ 149 | listener: onVADComplete 150 | }); 151 | } 152 | */ 153 | 154 | // Configure constraints 155 | var constraints = {audio: true}; 156 | 157 | // Start listening 158 | navigator.mediaDevices 159 | .getUserMedia(constraints) 160 | .then(onStream) 161 | .catch(function(err) { 162 | updateState({state: "error", error: err}); 163 | updateState({state: "ready"}); 164 | }); 165 | } 166 | 167 | function onStream(stream) { 168 | mediaStream = stream; 169 | updateState({state: "listening"}); 170 | 171 | // Build the WebAudio graph we'll be using 172 | audioContext = new AudioContext(); 173 | sourceNode = audioContext.createMediaStreamSource(stream); 174 | analyzerNode = audioContext.createAnalyser(); 175 | outputNode = audioContext.createMediaStreamDestination(); 176 | 177 | // make sure we're doing mono everywhere 178 | sourceNode.channelCount = 1; 179 | analyzerNode.channelCount = 1; 180 | outputNode.channelCount = 1; 181 | 182 | // connect the nodes together 183 | sourceNode.connect(analyzerNode); 184 | analyzerNode.connect(outputNode); 185 | 186 | if (config.vad) { 187 | // Initialize VAD 188 | // TODO: Re-use VAD instead of initializing on each use. 189 | function onVADComplete(reason) { 190 | // console.log('onVADComplete', reason); 191 | vadReason = reason; 192 | stop(); 193 | } 194 | VAD = SpeakToMeVAD({ 195 | listener: onVADComplete, 196 | }); 197 | 198 | // Reset last VAD reason 199 | vadReason = ""; 200 | 201 | var bufferSize = 2048; 202 | // create a javascript node 203 | scriptProcessor = audioContext.createScriptProcessor(bufferSize, 1, 1); 204 | scriptProcessor.connect(audioContext.destination); 205 | 206 | // Send audio events to VAD, which will call onVADComplete 207 | // when either voice input ends, none is detected, or neither (timeout). 208 | scriptProcessor.onaudioprocess = VAD.onAudioProcessingEvent; 209 | 210 | // connect stream to our recorder 211 | sourceNode.connect(scriptProcessor); 212 | } 213 | 214 | // Set up the recorder 215 | var options = { 216 | audioBitsPerSecond: RECORDING_BITS_PER_SECOND, 217 | mimeType: RECORDING_MIME_TYPE, 218 | }; 219 | 220 | // MediaRecorder initialization 221 | mediaRecorder = new MediaRecorder(outputNode.stream, options); 222 | 223 | mediaRecorder.start(); 224 | 225 | // If VAD is disabled, stop recording on a timeout 226 | if (!config.vad) { 227 | setTimeout(stop, config.timeout); 228 | } 229 | 230 | mediaRecorder.onstop = function(e) { 231 | // We stopped the recording, process the results 232 | updateState({state: "processing"}); 233 | 234 | // No voice detected from VAD 235 | if ( 236 | (config.vad && vadReason === "novoice") || 237 | // Or nothing recorded 238 | !chunks[0].size 239 | ) { 240 | updateState({state: "result", data: []}); 241 | updateState({state: "ready"}); 242 | } else { 243 | // Create blob from recording, for upload 244 | var blob = new Blob(chunks, { 245 | type: "audio/ogg; codecs=opus", 246 | }); 247 | 248 | // Send to server 249 | sendRecordingToServer(blob); 250 | } 251 | 252 | // Reset recording buffer 253 | chunks = []; 254 | 255 | // Clean up 256 | mediaRecorder = null; 257 | audioContext = null; 258 | sourceNode = null; 259 | analyzerNode = null; 260 | outputNode = null; 261 | stream = null; 262 | scriptProcessor = null; 263 | }; 264 | 265 | // Stored data from mediarecorder 266 | var chunks = []; 267 | 268 | mediaRecorder.ondataavailable = function(e) { 269 | chunks.push(e.data); 270 | }; 271 | } 272 | 273 | function sendRecordingToServer(blob) { 274 | updateState({state: "sending"}); 275 | 276 | var headers = { 277 | "Accept-Language-STT": config.language, 278 | "Store-Sample": config.storeSample ? "1" : "0", 279 | "Store-Transcription": config.storeTranscription ? "1" : "0", 280 | }; 281 | 282 | if (config.productTag) { 283 | headers["Product-Tag"] = config.productTag; 284 | } 285 | 286 | fetch(config.serverURL, { 287 | method: "POST", 288 | body: blob, 289 | headers: headers, 290 | }) 291 | .then(function(response) { 292 | return response.json(); 293 | }) 294 | .then(function(json) { 295 | if (json.status === "ok") { 296 | updateState({state: "result", data: json.data}); 297 | updateState({state: "ready"}); 298 | } else if (json.status) { 299 | throw new Error("Received bad status: " + json.status); 300 | } else if (json.error) { 301 | throw new Error("Received server error: " + json.error); 302 | } else { 303 | throw new Error("Received invalid result"); 304 | } 305 | }) 306 | .catch(function(error) { 307 | updateState({state: "error", error: error}); 308 | updateState({state: "ready"}); 309 | }); 310 | } 311 | 312 | function stop() { 313 | if (state !== "listening") { 314 | return; 315 | } 316 | 317 | mediaStream.getAudioTracks()[0].stop(); 318 | mediaRecorder.stop(); 319 | sourceNode.disconnect(scriptProcessor); 320 | sourceNode.disconnect(analyzerNode); 321 | analyzerNode.disconnect(outputNode); 322 | scriptProcessor.disconnect(audioContext.destination); 323 | audioContext.close(); 324 | } 325 | 326 | function updateState(msg) { 327 | state = msg.state; 328 | 329 | if (!config.listener) { 330 | console.warn( 331 | "SpeakToMe: You need to initialize SpeakToMe with an event listener!" 332 | ); 333 | return; 334 | } 335 | 336 | try { 337 | config.listener(msg); 338 | } catch (ex) { 339 | console.error("SpeakToMe: Listener error", ex); 340 | } 341 | } 342 | 343 | function getMediaStream() { 344 | return mediaStream; 345 | } 346 | 347 | // Public API 348 | return { 349 | listen: listen, 350 | stop: stop, 351 | setListener: function(l) { 352 | config.listener = l; 353 | }, 354 | getmediaStream: function() { 355 | console.log( 356 | "SpeakToMe.getmediaStream(): Deprecated API -", 357 | "use getMediaStream() instead" 358 | ); 359 | return getMediaStream(); 360 | }, 361 | getMediaStream: getMediaStream, 362 | }; 363 | } 364 | 365 | if (typeof module !== "undefined") { 366 | module.exports = SpeakToMe; 367 | } 368 | -------------------------------------------------------------------------------- /src/stm_vad.js: -------------------------------------------------------------------------------- 1 | // Webrtc_Vad integration 2 | // eslint-disable-next-line no-unused-vars 3 | function SpeakToMeVAD(options) { 4 | var config = { 5 | listener: function() { 6 | console.error("SpeakToMeVAD: No listener configured!"); 7 | }, 8 | maxSilence: 500, 9 | }; 10 | 11 | if (options) { 12 | if (typeof options.listener !== "undefined") { 13 | config.listener = options.listener; 14 | } 15 | if (typeof options.maxSilence !== "undefined") { 16 | console.log("MAXSILENCE", options.maxSilence); 17 | config.maxSilence = options.maxSilence; 18 | } 19 | } 20 | 21 | var webrtc_main = Module.cwrap("main"); 22 | webrtc_main(); 23 | 24 | var webrtc_setmode = Module.cwrap("setmode", "number", ["number"]); 25 | // set_mode defines the aggressiveness degree of the voice activity 26 | // detection algorithm. for more info see: 27 | // https://github.com/mozilla/gecko/blob/central/media/webrtc/trunk/webrtc/common_audio/vad/vad_core.h#L68 28 | webrtc_setmode(3); 29 | 30 | var webrtc_process_data = Module.cwrap("process_data", "number", [ 31 | "number", 32 | "number", 33 | "number", 34 | "number", 35 | "number", 36 | "number", 37 | ]); 38 | 39 | // frame length that should be passed to the vad engine. Depends on audio 40 | // sample rate. see: 41 | // https://github.com/mozilla/gecko/blob/central/media/webrtc/trunk/webrtc/common_audio/vad/vad_core.h#L106 42 | var sizeBufferVad = 480; 43 | // 44 | var buffer_vad = new Int16Array(sizeBufferVad); 45 | // 46 | var leftovers = 0; 47 | // 48 | var samplesvoice = 0; 49 | // 50 | var samplessilence = 0; 51 | // 52 | var touchedvoice = false; 53 | // 54 | var touchedsilence = false; 55 | // 56 | var dtantes = Date.now(); 57 | // 58 | var dtantesmili = Date.now(); 59 | // 60 | var done = false; 61 | // minimum of voice (in milliseconds) that should be captured to be considered 62 | // voice 63 | var minvoice = 250; 64 | // max amount of silence (in milliseconds) that should be captured to be 65 | // considered end-of-speech 66 | var maxsilence = config.maxSilence; 67 | // max amount of capturing time (in seconds) 68 | var maxtime = 6; 69 | 70 | function reset() { 71 | buffer_vad = new Int16Array(sizeBufferVad); 72 | leftovers = 0; 73 | samplesvoice = 0; 74 | samplessilence = 0; 75 | touchedvoice = false; 76 | touchedsilence = false; 77 | dtantes = Date.now(); 78 | dtantesmili = Date.now(); 79 | done = false; 80 | } 81 | 82 | // function that returns if the specified buffer has silence of speech 83 | function isSilence(buffer_pcm) { 84 | // Get data byte size, allocate memory on Emscripten heap, and get pointer 85 | var nDataBytes = buffer_pcm.length * buffer_pcm.BYTES_PER_ELEMENT; 86 | var dataPtr = Module._malloc(nDataBytes); 87 | // Copy data to Emscripten heap (directly accessed from Module.HEAPU8) 88 | var dataHeap = new Uint8Array(Module.HEAPU8.buffer, dataPtr, nDataBytes); 89 | dataHeap.set(new Uint8Array(buffer_pcm.buffer)); 90 | // Call function and get result 91 | var result = webrtc_process_data( 92 | dataHeap.byteOffset, 93 | buffer_pcm.length, 94 | 48000, 95 | buffer_pcm[0], 96 | buffer_pcm[100], 97 | buffer_pcm[2000] 98 | ); 99 | // Free memory 100 | Module._free(dataHeap.byteOffset); 101 | return result; 102 | } 103 | 104 | function floatTo16BitPCM(output, input) { 105 | for (var i = 0; i < input.length; i++) { 106 | var s = Math.max(-1, Math.min(1, input[i])); 107 | output[i] = s < 0 ? s * 0x8000 : s * 0x7fff; 108 | } 109 | } 110 | 111 | function onAudioProcessingEvent(e) { 112 | var buffer_pcm = new Int16Array(e.inputBuffer.getChannelData(0).length); 113 | floatTo16BitPCM(buffer_pcm, e.inputBuffer.getChannelData(0)); 114 | // algorithm used to determine if the user stopped speaking or not 115 | for ( 116 | var i = 0; 117 | i < Math.ceil(buffer_pcm.length / sizeBufferVad) && !done; 118 | i++ 119 | ) { 120 | var start = i * sizeBufferVad; 121 | var end = start + sizeBufferVad; 122 | if (start + sizeBufferVad > buffer_pcm.length) { 123 | // store to the next buffer 124 | buffer_vad.set(buffer_pcm.slice(start)); 125 | leftovers = buffer_pcm.length - start; 126 | } else { 127 | if (leftovers > 0) { 128 | // we have this.leftovers from previous array 129 | end = end - this.leftovers; 130 | buffer_vad.set(buffer_pcm.slice(start, end), leftovers); 131 | leftovers = 0; 132 | } else { 133 | // send to the vad 134 | buffer_vad.set(buffer_pcm.slice(start, end)); 135 | } 136 | var vad = isSilence(buffer_vad); 137 | 138 | // TODO: this doesn't seem necessary, we do it in reset() 139 | buffer_vad = new Int16Array(sizeBufferVad); 140 | 141 | var dtdepois = Date.now(); 142 | if (vad === 0) { 143 | if (touchedvoice) { 144 | samplessilence += dtdepois - dtantesmili; 145 | if (samplessilence > maxsilence) { 146 | touchedsilence = true; 147 | } 148 | } 149 | } else { 150 | samplesvoice += dtdepois - dtantesmili; 151 | if (samplesvoice > minvoice) { 152 | touchedvoice = true; 153 | } 154 | } 155 | dtantesmili = dtdepois; 156 | if (touchedvoice && touchedsilence) { 157 | done = true; 158 | onComplete("finishedvoice"); 159 | } else if ((dtdepois - dtantes) / 1000 > maxtime) { 160 | done = true; 161 | if (touchedvoice) { 162 | onComplete("timeout"); 163 | } else { 164 | onComplete("novoice"); 165 | } 166 | } 167 | // TODO: should be an else here, yah? 168 | } 169 | } 170 | } 171 | 172 | function onComplete(why) { 173 | try { 174 | config.listener(why); 175 | } catch (ex) { 176 | console.log("SpeakToMeVAD: onCompleteCallback exception:", ex); 177 | } 178 | 179 | // Auto-reset for next input 180 | reset(); 181 | } 182 | 183 | // TODO: something not initializing right - this shouldn't be necessary 184 | reset(); 185 | 186 | // Public 187 | return { 188 | reset: reset, 189 | onAudioProcessingEvent: onAudioProcessingEvent, 190 | }; 191 | } 192 | 193 | if (typeof module !== "undefined") { 194 | module.exports = SpeakToMe; 195 | } 196 | 197 | // TODO modularize and protect the emscripten stuff 198 | // because it seems to depend on window globals being exposed. 199 | // 200 | // Also, maybe just put this and webrtc_vad.js all in one file... 201 | 202 | // Creation of the configuration object 203 | // that will be pick by emscripten module 204 | var Module = { 205 | preRun: [], 206 | postRun: [], 207 | print: (function() { 208 | return function(text) { 209 | console.log("[webrtc_vad.js print]", text); 210 | }; 211 | })(), 212 | printErr: function(text) { 213 | console.error("[webrtc_vad.js error]", text); 214 | }, 215 | canvas: (function() {})(), 216 | setStatus: function(text) { 217 | console.log("[webrtc_vad.js status] ", text); 218 | }, 219 | totalDependencies: 0, 220 | monitorRunDependencies: function(left) { 221 | this.totalDependencies = Math.max(this.totalDependencies, left); 222 | Module.setStatus( 223 | left 224 | ? "Preparing... (" + 225 | (this.totalDependencies - left) + 226 | "/" + 227 | this.totalDependencies + 228 | ")" 229 | : "All downloads complete." 230 | ); 231 | }, 232 | }; 233 | 234 | Module.setStatus("Loading webrtc_vad..."); 235 | window.onerror = function(event) { 236 | // TODO: do not warn on ok events like simulating an infinite loop or 237 | // exitStatus 238 | Module.setStatus("Exception thrown, see JavaScript console"); 239 | Module.setStatus = function(text) { 240 | if (text) { 241 | Module.printErr("[post-exception status] " + text); 242 | } 243 | }; 244 | }; 245 | Module.noInitialRun = true; 246 | Module.onRuntimeInitialized = function() { 247 | Module.setStatus("Webrtc_vad and SpeakToMeVad loaded"); 248 | }; 249 | -------------------------------------------------------------------------------- /test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SpeakToMe Component - Basic 6 | 7 | 15 | 16 | 17 | 18 |
19 |

SpeakToMe - Speech Recognition API from Mozilla

20 | 21 |
22 | 23 | 24 |
25 | 26 |
27 |
28 |
29 |
30 |
31 | 32 | 33 | 34 | 35 | 38 | 230 | 231 | 232 | --------------------------------------------------------------------------------