-
Notifications
You must be signed in to change notification settings - Fork 5
/
dtm.js
13325 lines (11578 loc) · 433 KB
/
dtm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(function () {
var Module;if(!Module)Module=(typeof EM!=="undefined"?EM:null)||{};var moduleOverrides={};for(var key in Module){if(Module.hasOwnProperty(key)){moduleOverrides[key]=Module[key]}}var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=false;var ENVIRONMENT_IS_NODE=false;var ENVIRONMENT_IS_SHELL=false;if(Module["ENVIRONMENT"]){if(Module["ENVIRONMENT"]==="WEB"){ENVIRONMENT_IS_WEB=true}else if(Module["ENVIRONMENT"]==="WORKER"){ENVIRONMENT_IS_WORKER=true}else if(Module["ENVIRONMENT"]==="NODE"){ENVIRONMENT_IS_NODE=true}else if(Module["ENVIRONMENT"]==="SHELL"){ENVIRONMENT_IS_SHELL=true}else{throw new Error("The provided Module['ENVIRONMENT'] value is not valid. It must be one of: WEB|WORKER|NODE|SHELL.")}}else{ENVIRONMENT_IS_WEB=typeof window==="object";ENVIRONMENT_IS_WORKER=typeof importScripts==="function";ENVIRONMENT_IS_NODE=typeof process==="object"&&typeof require==="function"&&!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_WORKER;ENVIRONMENT_IS_SHELL=!ENVIRONMENT_IS_WEB&&!ENVIRONMENT_IS_NODE&&!ENVIRONMENT_IS_WORKER}if(ENVIRONMENT_IS_NODE){if(!Module["print"])Module["print"]=console.log;if(!Module["printErr"])Module["printErr"]=console.warn;var nodeFS;var nodePath;Module["read"]=function read(filename,binary){if(!nodeFS)nodeFS=require("fs");if(!nodePath)nodePath=require("path");filename=nodePath["normalize"](filename);var ret=nodeFS["readFileSync"](filename);return binary?ret:ret.toString()};Module["readBinary"]=function readBinary(filename){var ret=Module["read"](filename,true);if(!ret.buffer){ret=new Uint8Array(ret)}assert(ret.buffer);return ret};Module["load"]=function load(f){globalEval(read(f))};if(!Module["thisProgram"]){if(process["argv"].length>1){Module["thisProgram"]=process["argv"][1].replace(/\\/g,"/")}else{Module["thisProgram"]="unknown-program"}}Module["arguments"]=process["argv"].slice(2);if(typeof module!=="undefined"){module["exports"]=Module}process["on"]("uncaughtException",(function(ex){if(!(ex instanceof ExitStatus)){throw ex}}));Module["inspect"]=(function(){return"[Emscripten Module object]"})}else if(ENVIRONMENT_IS_SHELL){if(!Module["print"])Module["print"]=print;if(typeof printErr!="undefined")Module["printErr"]=printErr;if(typeof read!="undefined"){Module["read"]=read}else{Module["read"]=function read(){throw"no read() available (jsc?)"}}Module["readBinary"]=function readBinary(f){if(typeof readbuffer==="function"){return new Uint8Array(readbuffer(f))}var data=read(f,"binary");assert(typeof data==="object");return data};if(typeof scriptArgs!="undefined"){Module["arguments"]=scriptArgs}else if(typeof arguments!="undefined"){Module["arguments"]=arguments}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){Module["read"]=function read(url){var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.send(null);return xhr.responseText};Module["readAsync"]=function readAsync(url,onload,onerror){var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=function xhr_onload(){if(xhr.status==200||xhr.status==0&&xhr.response){onload(xhr.response)}else{onerror()}};xhr.onerror=onerror;xhr.send(null)};if(typeof arguments!="undefined"){Module["arguments"]=arguments}if(typeof console!=="undefined"){if(!Module["print"])Module["print"]=function print(x){console.log(x)};if(!Module["printErr"])Module["printErr"]=function printErr(x){console.warn(x)}}else{var TRY_USE_DUMP=false;if(!Module["print"])Module["print"]=TRY_USE_DUMP&&typeof dump!=="undefined"?(function(x){dump(x)}):(function(x){})}if(ENVIRONMENT_IS_WORKER){Module["load"]=importScripts}if(typeof Module["setWindowTitle"]==="undefined"){Module["setWindowTitle"]=(function(title){document.title=title})}}else{throw"Unknown runtime environment. Where are we?"}function globalEval(x){eval.call(null,x)}if(!Module["load"]&&Module["read"]){Module["load"]=function load(f){globalEval(Module["read"](f))}}if(!Module["print"]){Module["print"]=(function(){})}if(!Module["printErr"]){Module["printErr"]=Module["print"]}if(!Module["arguments"]){Module["arguments"]=[]}if(!Module["thisProgram"]){Module["thisProgram"]="./this.program"}Module.print=Module["print"];Module.printErr=Module["printErr"];Module["preRun"]=[];Module["postRun"]=[];for(var key in moduleOverrides){if(moduleOverrides.hasOwnProperty(key)){Module[key]=moduleOverrides[key]}}moduleOverrides=undefined;var Runtime={setTempRet0:(function(value){tempRet0=value}),getTempRet0:(function(){return tempRet0}),stackSave:(function(){return STACKTOP}),stackRestore:(function(stackTop){STACKTOP=stackTop}),getNativeTypeSize:(function(type){switch(type){case"i1":case"i8":return 1;case"i16":return 2;case"i32":return 4;case"i64":return 8;case"float":return 4;case"double":return 8;default:{if(type[type.length-1]==="*"){return Runtime.QUANTUM_SIZE}else if(type[0]==="i"){var bits=parseInt(type.substr(1));assert(bits%8===0);return bits/8}else{return 0}}}}),getNativeFieldSize:(function(type){return Math.max(Runtime.getNativeTypeSize(type),Runtime.QUANTUM_SIZE)}),STACK_ALIGN:16,prepVararg:(function(ptr,type){if(type==="double"||type==="i64"){if(ptr&7){assert((ptr&7)===4);ptr+=4}}else{assert((ptr&3)===0)}return ptr}),getAlignSize:(function(type,size,vararg){if(!vararg&&(type=="i64"||type=="double"))return 8;if(!type)return Math.min(size,8);return Math.min(size||(type?Runtime.getNativeFieldSize(type):0),Runtime.QUANTUM_SIZE)}),dynCall:(function(sig,ptr,args){if(args&&args.length){return Module["dynCall_"+sig].apply(null,[ptr].concat(args))}else{return Module["dynCall_"+sig].call(null,ptr)}}),functionPointers:[],addFunction:(function(func){for(var i=0;i<Runtime.functionPointers.length;i++){if(!Runtime.functionPointers[i]){Runtime.functionPointers[i]=func;return 2*(1+i)}}throw"Finished up all reserved function pointers. Use a higher value for RESERVED_FUNCTION_POINTERS."}),removeFunction:(function(index){Runtime.functionPointers[(index-2)/2]=null}),warnOnce:(function(text){if(!Runtime.warnOnce.shown)Runtime.warnOnce.shown={};if(!Runtime.warnOnce.shown[text]){Runtime.warnOnce.shown[text]=1;Module.printErr(text)}}),funcWrappers:{},getFuncWrapper:(function(func,sig){assert(sig);if(!Runtime.funcWrappers[sig]){Runtime.funcWrappers[sig]={}}var sigCache=Runtime.funcWrappers[sig];if(!sigCache[func]){if(sig.length===1){sigCache[func]=function dynCall_wrapper(){return Runtime.dynCall(sig,func)}}else if(sig.length===2){sigCache[func]=function dynCall_wrapper(arg){return Runtime.dynCall(sig,func,[arg])}}else{sigCache[func]=function dynCall_wrapper(){return Runtime.dynCall(sig,func,Array.prototype.slice.call(arguments))}}}return sigCache[func]}),getCompilerSetting:(function(name){throw"You must build with -s RETAIN_COMPILER_SETTINGS=1 for Runtime.getCompilerSetting or emscripten_get_compiler_setting to work"}),stackAlloc:(function(size){var ret=STACKTOP;STACKTOP=STACKTOP+size|0;STACKTOP=STACKTOP+15&-16;return ret}),staticAlloc:(function(size){var ret=STATICTOP;STATICTOP=STATICTOP+size|0;STATICTOP=STATICTOP+15&-16;return ret}),dynamicAlloc:(function(size){var ret=DYNAMICTOP;DYNAMICTOP=DYNAMICTOP+size|0;DYNAMICTOP=DYNAMICTOP+15&-16;if(DYNAMICTOP>=TOTAL_MEMORY){var success=enlargeMemory();if(!success){DYNAMICTOP=ret;return 0}}return ret}),alignMemory:(function(size,quantum){var ret=size=Math.ceil(size/(quantum?quantum:16))*(quantum?quantum:16);return ret}),makeBigInt:(function(low,high,unsigned){var ret=unsigned?+(low>>>0)+ +(high>>>0)*+4294967296:+(low>>>0)+ +(high|0)*+4294967296;return ret}),GLOBAL_BASE:8,QUANTUM_SIZE:4,__dummy__:0};Module["Runtime"]=Runtime;var ABORT=false;var EXITSTATUS=0;function assert(condition,text){if(!condition){abort("Assertion failed: "+text)}}function getCFunc(ident){var func=Module["_"+ident];if(!func){try{func=eval("_"+ident)}catch(e){}}assert(func,"Cannot call unknown function "+ident+" (perhaps LLVM optimizations or closure removed it?)");return func}var cwrap,ccall;((function(){var JSfuncs={"stackSave":(function(){Runtime.stackSave()}),"stackRestore":(function(){Runtime.stackRestore()}),"arrayToC":(function(arr){var ret=Runtime.stackAlloc(arr.length);writeArrayToMemory(arr,ret);return ret}),"stringToC":(function(str){var ret=0;if(str!==null&&str!==undefined&&str!==0){ret=Runtime.stackAlloc((str.length<<2)+1);writeStringToMemory(str,ret)}return ret})};var toC={"string":JSfuncs["stringToC"],"array":JSfuncs["arrayToC"]};ccall=function ccallFunc(ident,returnType,argTypes,args,opts){var func=getCFunc(ident);var cArgs=[];var stack=0;if(args){for(var i=0;i<args.length;i++){var converter=toC[argTypes[i]];if(converter){if(stack===0)stack=Runtime.stackSave();cArgs[i]=converter(args[i])}else{cArgs[i]=args[i]}}}var ret=func.apply(null,cArgs);if(returnType==="string")ret=Pointer_stringify(ret);if(stack!==0){if(opts&&opts.async){EmterpreterAsync.asyncFinalizers.push((function(){Runtime.stackRestore(stack)}));return}Runtime.stackRestore(stack)}return ret};var sourceRegex=/^function\s*[a-zA-Z$_0-9]*\s*\(([^)]*)\)\s*{\s*([^*]*?)[\s;]*(?:return\s*(.*?)[;\s]*)?}$/;function parseJSFunc(jsfunc){var parsed=jsfunc.toString().match(sourceRegex).slice(1);return{arguments:parsed[0],body:parsed[1],returnValue:parsed[2]}}var JSsource=null;function ensureJSsource(){if(!JSsource){JSsource={};for(var fun in JSfuncs){if(JSfuncs.hasOwnProperty(fun)){JSsource[fun]=parseJSFunc(JSfuncs[fun])}}}}cwrap=function cwrap(ident,returnType,argTypes){argTypes=argTypes||[];var cfunc=getCFunc(ident);var numericArgs=argTypes.every((function(type){return type==="number"}));var numericRet=returnType!=="string";if(numericRet&&numericArgs){return cfunc}var argNames=argTypes.map((function(x,i){return"$"+i}));var funcstr="(function("+argNames.join(",")+") {";var nargs=argTypes.length;if(!numericArgs){ensureJSsource();funcstr+="var stack = "+JSsource["stackSave"].body+";";for(var i=0;i<nargs;i++){var arg=argNames[i],type=argTypes[i];if(type==="number")continue;var convertCode=JSsource[type+"ToC"];funcstr+="var "+convertCode.arguments+" = "+arg+";";funcstr+=convertCode.body+";";funcstr+=arg+"=("+convertCode.returnValue+");"}}var cfuncname=parseJSFunc((function(){return cfunc})).returnValue;funcstr+="var ret = "+cfuncname+"("+argNames.join(",")+");";if(!numericRet){var strgfy=parseJSFunc((function(){return Pointer_stringify})).returnValue;funcstr+="ret = "+strgfy+"(ret);"}if(!numericArgs){ensureJSsource();funcstr+=JSsource["stackRestore"].body.replace("()","(stack)")+";"}funcstr+="return ret})";return eval(funcstr)}}))();Module["ccall"]=ccall;Module["cwrap"]=cwrap;function setValue(ptr,value,type,noSafe){type=type||"i8";if(type.charAt(type.length-1)==="*")type="i32";switch(type){case"i1":HEAP8[ptr>>0]=value;break;case"i8":HEAP8[ptr>>0]=value;break;case"i16":HEAP16[ptr>>1]=value;break;case"i32":HEAP32[ptr>>2]=value;break;case"i64":tempI64=[value>>>0,(tempDouble=value,+Math_abs(tempDouble)>=+1?tempDouble>+0?(Math_min(+Math_floor(tempDouble/+4294967296),+4294967295)|0)>>>0:~~+Math_ceil((tempDouble- +(~~tempDouble>>>0))/+4294967296)>>>0:0)],HEAP32[ptr>>2]=tempI64[0],HEAP32[ptr+4>>2]=tempI64[1];break;case"float":HEAPF32[ptr>>2]=value;break;case"double":HEAPF64[ptr>>3]=value;break;default:abort("invalid type for setValue: "+type)}}Module["setValue"]=setValue;function getValue(ptr,type,noSafe){type=type||"i8";if(type.charAt(type.length-1)==="*")type="i32";switch(type){case"i1":return HEAP8[ptr>>0];case"i8":return HEAP8[ptr>>0];case"i16":return HEAP16[ptr>>1];case"i32":return HEAP32[ptr>>2];case"i64":return HEAP32[ptr>>2];case"float":return HEAPF32[ptr>>2];case"double":return HEAPF64[ptr>>3];default:abort("invalid type for setValue: "+type)}return null}Module["getValue"]=getValue;var ALLOC_NORMAL=0;var ALLOC_STACK=1;var ALLOC_STATIC=2;var ALLOC_DYNAMIC=3;var ALLOC_NONE=4;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;function allocate(slab,types,allocator,ptr){var zeroinit,size;if(typeof slab==="number"){zeroinit=true;size=slab}else{zeroinit=false;size=slab.length}var singleType=typeof types==="string"?types:null;var ret;if(allocator==ALLOC_NONE){ret=ptr}else{ret=[typeof _malloc==="function"?_malloc:Runtime.staticAlloc,Runtime.stackAlloc,Runtime.staticAlloc,Runtime.dynamicAlloc][allocator===undefined?ALLOC_STATIC:allocator](Math.max(size,singleType?1:types.length))}if(zeroinit){var ptr=ret,stop;assert((ret&3)==0);stop=ret+(size&~3);for(;ptr<stop;ptr+=4){HEAP32[ptr>>2]=0}stop=ret+size;while(ptr<stop){HEAP8[ptr++>>0]=0}return ret}if(singleType==="i8"){if(slab.subarray||slab.slice){HEAPU8.set(slab,ret)}else{HEAPU8.set(new Uint8Array(slab),ret)}return ret}var i=0,type,typeSize,previousType;while(i<size){var curr=slab[i];if(typeof curr==="function"){curr=Runtime.getFunctionIndex(curr)}type=singleType||types[i];if(type===0){i++;continue}if(type=="i64")type="i32";setValue(ret+i,curr,type);if(previousType!==type){typeSize=Runtime.getNativeTypeSize(type);previousType=type}i+=typeSize}return ret}Module["allocate"]=allocate;function getMemory(size){if(!staticSealed)return Runtime.staticAlloc(size);if(typeof _sbrk!=="undefined"&&!_sbrk.called||!runtimeInitialized)return Runtime.dynamicAlloc(size);return _malloc(size)}Module["getMemory"]=getMemory;function Pointer_stringify(ptr,length){if(length===0||!ptr)return"";var hasUtf=0;var t;var i=0;while(1){t=HEAPU8[ptr+i>>0];hasUtf|=t;if(t==0&&!length)break;i++;if(length&&i==length)break}if(!length)length=i;var ret="";if(hasUtf<128){var MAX_CHUNK=1024;var curr;while(length>0){curr=String.fromCharCode.apply(String,HEAPU8.subarray(ptr,ptr+Math.min(length,MAX_CHUNK)));ret=ret?ret+curr:curr;ptr+=MAX_CHUNK;length-=MAX_CHUNK}return ret}return Module["UTF8ToString"](ptr)}Module["Pointer_stringify"]=Pointer_stringify;function AsciiToString(ptr){var str="";while(1){var ch=HEAP8[ptr++>>0];if(!ch)return str;str+=String.fromCharCode(ch)}}Module["AsciiToString"]=AsciiToString;function stringToAscii(str,outPtr){return writeAsciiToMemory(str,outPtr,false)}Module["stringToAscii"]=stringToAscii;function UTF8ArrayToString(u8Array,idx){var u0,u1,u2,u3,u4,u5;var str="";while(1){u0=u8Array[idx++];if(!u0)return str;if(!(u0&128)){str+=String.fromCharCode(u0);continue}u1=u8Array[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}u2=u8Array[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u3=u8Array[idx++]&63;if((u0&248)==240){u0=(u0&7)<<18|u1<<12|u2<<6|u3}else{u4=u8Array[idx++]&63;if((u0&252)==248){u0=(u0&3)<<24|u1<<18|u2<<12|u3<<6|u4}else{u5=u8Array[idx++]&63;u0=(u0&1)<<30|u1<<24|u2<<18|u3<<12|u4<<6|u5}}}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}}Module["UTF8ArrayToString"]=UTF8ArrayToString;function UTF8ToString(ptr){return UTF8ArrayToString(HEAPU8,ptr)}Module["UTF8ToString"]=UTF8ToString;function stringToUTF8Array(str,outU8Array,outIdx,maxBytesToWrite){if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343)u=65536+((u&1023)<<10)|str.charCodeAt(++i)&1023;if(u<=127){if(outIdx>=endIdx)break;outU8Array[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;outU8Array[outIdx++]=192|u>>6;outU8Array[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;outU8Array[outIdx++]=224|u>>12;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else if(u<=2097151){if(outIdx+3>=endIdx)break;outU8Array[outIdx++]=240|u>>18;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else if(u<=67108863){if(outIdx+4>=endIdx)break;outU8Array[outIdx++]=248|u>>24;outU8Array[outIdx++]=128|u>>18&63;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}else{if(outIdx+5>=endIdx)break;outU8Array[outIdx++]=252|u>>30;outU8Array[outIdx++]=128|u>>24&63;outU8Array[outIdx++]=128|u>>18&63;outU8Array[outIdx++]=128|u>>12&63;outU8Array[outIdx++]=128|u>>6&63;outU8Array[outIdx++]=128|u&63}}outU8Array[outIdx]=0;return outIdx-startIdx}Module["stringToUTF8Array"]=stringToUTF8Array;function stringToUTF8(str,outPtr,maxBytesToWrite){return stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite)}Module["stringToUTF8"]=stringToUTF8;function lengthBytesUTF8(str){var len=0;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343)u=65536+((u&1023)<<10)|str.charCodeAt(++i)&1023;if(u<=127){++len}else if(u<=2047){len+=2}else if(u<=65535){len+=3}else if(u<=2097151){len+=4}else if(u<=67108863){len+=5}else{len+=6}}return len}Module["lengthBytesUTF8"]=lengthBytesUTF8;function demangle(func){var hasLibcxxabi=!!Module["___cxa_demangle"];if(hasLibcxxabi){try{var buf=_malloc(func.length);writeStringToMemory(func.substr(1),buf);var status=_malloc(4);var ret=Module["___cxa_demangle"](buf,0,0,status);if(getValue(status,"i32")===0&&ret){return Pointer_stringify(ret)}}catch(e){}finally{if(buf)_free(buf);if(status)_free(status);if(ret)_free(ret)}return func}Runtime.warnOnce("warning: build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling");return func}function demangleAll(text){return text.replace(/__Z[\w\d_]+/g,(function(x){var y=demangle(x);return x===y?x:x+" ["+y+"]"}))}function jsStackTrace(){var err=new Error;if(!err.stack){try{throw new Error(0)}catch(e){err=e}if(!err.stack){return"(no stack trace available)"}}return err.stack.toString()}function stackTrace(){var js=jsStackTrace();if(Module["extraStackTrace"])js+="\n"+Module["extraStackTrace"]();return demangleAll(js)}Module["stackTrace"]=stackTrace;function alignMemoryPage(x){if(x%4096>0){x+=4096-x%4096}return x}var HEAP;var buffer;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateGlobalBufferViews(){Module["HEAP8"]=HEAP8=new Int8Array(buffer);Module["HEAP16"]=HEAP16=new Int16Array(buffer);Module["HEAP32"]=HEAP32=new Int32Array(buffer);Module["HEAPU8"]=HEAPU8=new Uint8Array(buffer);Module["HEAPU16"]=HEAPU16=new Uint16Array(buffer);Module["HEAPU32"]=HEAPU32=new Uint32Array(buffer);Module["HEAPF32"]=HEAPF32=new Float32Array(buffer);Module["HEAPF64"]=HEAPF64=new Float64Array(buffer)}var STATIC_BASE=0,STATICTOP=0,staticSealed=false;var STACK_BASE=0,STACKTOP=0,STACK_MAX=0;var DYNAMIC_BASE=0,DYNAMICTOP=0;function abortOnCannotGrowMemory(){abort("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value "+TOTAL_MEMORY+", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which adjusts the size at runtime but prevents some optimizations, (3) set Module.TOTAL_MEMORY to a higher value before the program runs, or if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ")}function enlargeMemory(){abortOnCannotGrowMemory()}var TOTAL_STACK=Module["TOTAL_STACK"]||5242880;var TOTAL_MEMORY=Module["TOTAL_MEMORY"]||16777216;var totalMemory=64*1024;while(totalMemory<TOTAL_MEMORY||totalMemory<2*TOTAL_STACK){if(totalMemory<16*1024*1024){totalMemory*=2}else{totalMemory+=16*1024*1024}}if(totalMemory!==TOTAL_MEMORY){TOTAL_MEMORY=totalMemory}if(Module["buffer"]){buffer=Module["buffer"]}else{buffer=new ArrayBuffer(TOTAL_MEMORY)}updateGlobalBufferViews();HEAP32[0]=255;if(HEAPU8[0]!==255||HEAPU8[3]!==0)throw"Typed arrays 2 must be run on a little-endian system";Module["HEAP"]=HEAP;Module["buffer"]=buffer;Module["HEAP8"]=HEAP8;Module["HEAP16"]=HEAP16;Module["HEAP32"]=HEAP32;Module["HEAPU8"]=HEAPU8;Module["HEAPU16"]=HEAPU16;Module["HEAPU32"]=HEAPU32;Module["HEAPF32"]=HEAPF32;Module["HEAPF64"]=HEAPF64;function callRuntimeCallbacks(callbacks){while(callbacks.length>0){var callback=callbacks.shift();if(typeof callback=="function"){callback();continue}var func=callback.func;if(typeof func==="number"){if(callback.arg===undefined){Runtime.dynCall("v",func)}else{Runtime.dynCall("vi",func,[callback.arg])}}else{func(callback.arg===undefined?null:callback.arg)}}}var __ATPRERUN__=[];var __ATINIT__=[];var __ATMAIN__=[];var __ATEXIT__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;var runtimeExited=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function ensureInitRuntime(){if(runtimeInitialized)return;runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function preMain(){callRuntimeCallbacks(__ATMAIN__)}function exitRuntime(){callRuntimeCallbacks(__ATEXIT__);runtimeExited=true}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}Module["addOnPreRun"]=addOnPreRun;function addOnInit(cb){__ATINIT__.unshift(cb)}Module["addOnInit"]=addOnInit;function addOnPreMain(cb){__ATMAIN__.unshift(cb)}Module["addOnPreMain"]=addOnPreMain;function addOnExit(cb){__ATEXIT__.unshift(cb)}Module["addOnExit"]=addOnExit;function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}Module["addOnPostRun"]=addOnPostRun;function intArrayFromString(stringy,dontAddNull,length){var len=length>0?length:lengthBytesUTF8(stringy)+1;var u8array=new Array(len);var numBytesWritten=stringToUTF8Array(stringy,u8array,0,u8array.length);if(dontAddNull)u8array.length=numBytesWritten;return u8array}Module["intArrayFromString"]=intArrayFromString;function intArrayToString(array){var ret=[];for(var i=0;i<array.length;i++){var chr=array[i];if(chr>255){chr&=255}ret.push(String.fromCharCode(chr))}return ret.join("")}Module["intArrayToString"]=intArrayToString;function writeStringToMemory(string,buffer,dontAddNull){var array=intArrayFromString(string,dontAddNull);var i=0;while(i<array.length){var chr=array[i];HEAP8[buffer+i>>0]=chr;i=i+1}}Module["writeStringToMemory"]=writeStringToMemory;function writeArrayToMemory(array,buffer){for(var i=0;i<array.length;i++){HEAP8[buffer++>>0]=array[i]}}Module["writeArrayToMemory"]=writeArrayToMemory;function writeAsciiToMemory(str,buffer,dontAddNull){for(var i=0;i<str.length;++i){HEAP8[buffer++>>0]=str.charCodeAt(i)}if(!dontAddNull)HEAP8[buffer>>0]=0}Module["writeAsciiToMemory"]=writeAsciiToMemory;if(!Math["imul"]||Math["imul"](4294967295,5)!==-5)Math["imul"]=function imul(a,b){var ah=a>>>16;var al=a&65535;var bh=b>>>16;var bl=b&65535;return al*bl+(ah*bl+al*bh<<16)|0};Math.imul=Math["imul"];if(!Math["clz32"])Math["clz32"]=(function(x){x=x>>>0;for(var i=0;i<32;i++){if(x&1<<31-i)return i}return 32});Math.clz32=Math["clz32"];if(!Math["trunc"])Math["trunc"]=(function(x){return x<0?Math.ceil(x):Math.floor(x)});Math.trunc=Math["trunc"];var Math_abs=Math.abs;var Math_cos=Math.cos;var Math_sin=Math.sin;var Math_tan=Math.tan;var Math_acos=Math.acos;var Math_asin=Math.asin;var Math_atan=Math.atan;var Math_atan2=Math.atan2;var Math_exp=Math.exp;var Math_log=Math.log;var Math_sqrt=Math.sqrt;var Math_ceil=Math.ceil;var Math_floor=Math.floor;var Math_pow=Math.pow;var Math_imul=Math.imul;var Math_fround=Math.fround;var Math_min=Math.min;var Math_clz32=Math.clz32;var Math_trunc=Math.trunc;var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}}Module["addRunDependency"]=addRunDependency;function removeRunDependency(id){runDependencies--;if(Module["monitorRunDependencies"]){Module["monitorRunDependencies"](runDependencies)}if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}Module["removeRunDependency"]=removeRunDependency;Module["preloadedImages"]={};Module["preloadedAudios"]={};var ASM_CONSTS=[];STATIC_BASE=8;STATICTOP=STATIC_BASE+1712;__ATINIT__.push();allocate([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,164,2,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,8,0,0,0],"i8",ALLOC_NONE,Runtime.GLOBAL_BASE);var tempDoublePtr=STATICTOP;STATICTOP+=16;function _sbrk(bytes){var self=_sbrk;if(!self.called){DYNAMICTOP=alignMemoryPage(DYNAMICTOP);self.called=true;assert(Runtime.dynamicAlloc);self.alloc=Runtime.dynamicAlloc;Runtime.dynamicAlloc=(function(){abort("cannot dynamically allocate, sbrk now has control")})}var ret=DYNAMICTOP;if(bytes!=0){var success=self.alloc(bytes);if(!success)return-1>>>0}return ret}Module["_memset"]=_memset;function _pthread_cleanup_push(routine,arg){__ATEXIT__.push((function(){Runtime.dynCall("vi",routine,[arg])}));_pthread_cleanup_push.level=__ATEXIT__.length}function ___lock(){}function _emscripten_memcpy_big(dest,src,num){HEAPU8.set(HEAPU8.subarray(src,src+num),dest);return dest}Module["_memcpy"]=_memcpy;function _pthread_cleanup_pop(){assert(_pthread_cleanup_push.level==__ATEXIT__.length,"cannot pop if something else added meanwhile!");__ATEXIT__.pop();_pthread_cleanup_push.level=__ATEXIT__.length}function _abort(){Module["abort"]()}Module["_pthread_self"]=_pthread_self;var SYSCALLS={varargs:0,get:(function(varargs){SYSCALLS.varargs+=4;var ret=HEAP32[SYSCALLS.varargs-4>>2];return ret}),getStr:(function(){var ret=Pointer_stringify(SYSCALLS.get());return ret}),get64:(function(){var low=SYSCALLS.get(),high=SYSCALLS.get();if(low>=0)assert(high===0);else assert(high===-1);return low}),getZero:(function(){assert(SYSCALLS.get()===0)})};function ___syscall140(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD(),offset_high=SYSCALLS.get(),offset_low=SYSCALLS.get(),result=SYSCALLS.get(),whence=SYSCALLS.get();var offset=offset_low;assert(offset_high===0);FS.llseek(stream,offset,whence);HEAP32[result>>2]=stream.position;if(stream.getdents&&offset===0&&whence===0)stream.getdents=null;return 0}catch(e){if(typeof FS==="undefined"||!(e instanceof FS.ErrnoError))abort(e);return-e.errno}}function ___syscall146(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.get(),iov=SYSCALLS.get(),iovcnt=SYSCALLS.get();var ret=0;if(!___syscall146.buffer){___syscall146.buffers=[null,[],[]];___syscall146.printChar=(function(stream,curr){var buffer=___syscall146.buffers[stream];assert(buffer);if(curr===0||curr===10){(stream===1?Module["print"]:Module["printErr"])(UTF8ArrayToString(buffer,0));buffer.length=0}else{buffer.push(curr)}})}for(var i=0;i<iovcnt;i++){var ptr=HEAP32[iov+i*8>>2];var len=HEAP32[iov+(i*8+4)>>2];for(var j=0;j<len;j++){___syscall146.printChar(stream,HEAPU8[ptr+j])}ret+=len}return ret}catch(e){if(typeof FS==="undefined"||!(e instanceof FS.ErrnoError))abort(e);return-e.errno}}function ___syscall54(which,varargs){SYSCALLS.varargs=varargs;try{return 0}catch(e){if(typeof FS==="undefined"||!(e instanceof FS.ErrnoError))abort(e);return-e.errno}}function ___unlock(){}function ___syscall6(which,varargs){SYSCALLS.varargs=varargs;try{var stream=SYSCALLS.getStreamFromFD();FS.close(stream);return 0}catch(e){if(typeof FS==="undefined"||!(e instanceof FS.ErrnoError))abort(e);return-e.errno}}__ATEXIT__.push((function(){var fflush=Module["_fflush"];if(fflush)fflush(0);var printChar=___syscall146.printChar;if(!printChar)return;var buffers=___syscall146.buffers;if(buffers[1].length)printChar(1,10);if(buffers[2].length)printChar(2,10)}));STACK_BASE=STACKTOP=Runtime.alignMemory(STATICTOP);staticSealed=true;STACK_MAX=STACK_BASE+TOTAL_STACK;DYNAMIC_BASE=DYNAMICTOP=Runtime.alignMemory(STACK_MAX);function invoke_ii(index,a1){try{return Module["dynCall_ii"](index,a1)}catch(e){if(typeof e!=="number"&&e!=="longjmp")throw e;asm["setThrew"](1,0)}}function invoke_iiii(index,a1,a2,a3){try{return Module["dynCall_iiii"](index,a1,a2,a3)}catch(e){if(typeof e!=="number"&&e!=="longjmp")throw e;asm["setThrew"](1,0)}}function invoke_vi(index,a1){try{Module["dynCall_vi"](index,a1)}catch(e){if(typeof e!=="number"&&e!=="longjmp")throw e;asm["setThrew"](1,0)}}Module.asmGlobalArg={"Math":Math,"Int8Array":Int8Array,"Int16Array":Int16Array,"Int32Array":Int32Array,"Uint8Array":Uint8Array,"Uint16Array":Uint16Array,"Uint32Array":Uint32Array,"Float32Array":Float32Array,"Float64Array":Float64Array,"NaN":NaN,"Infinity":Infinity};Module.asmLibraryArg={"abort":abort,"assert":assert,"invoke_ii":invoke_ii,"invoke_iiii":invoke_iiii,"invoke_vi":invoke_vi,"_pthread_cleanup_pop":_pthread_cleanup_pop,"___lock":___lock,"_abort":_abort,"_pthread_cleanup_push":_pthread_cleanup_push,"___syscall6":___syscall6,"_sbrk":_sbrk,"___syscall140":___syscall140,"_emscripten_memcpy_big":_emscripten_memcpy_big,"___syscall54":___syscall54,"___unlock":___unlock,"___syscall146":___syscall146,"STACKTOP":STACKTOP,"STACK_MAX":STACK_MAX,"tempDoublePtr":tempDoublePtr,"ABORT":ABORT};// EMSCRIPTEN_START_ASM
var asm=(function(global,env,buffer) {
"use asm";var a=new global.Int8Array(buffer);var b=new global.Int16Array(buffer);var c=new global.Int32Array(buffer);var d=new global.Uint8Array(buffer);var e=new global.Uint16Array(buffer);var f=new global.Uint32Array(buffer);var g=new global.Float32Array(buffer);var h=new global.Float64Array(buffer);var i=env.STACKTOP|0;var j=env.STACK_MAX|0;var k=env.tempDoublePtr|0;var l=env.ABORT|0;var m=0;var n=0;var o=0;var p=0;var q=global.NaN,r=global.Infinity;var s=0,t=0,u=0,v=0,w=0.0,x=0,y=0,z=0,A=0.0;var B=0;var C=global.Math.floor;var D=global.Math.abs;var E=global.Math.sqrt;var F=global.Math.pow;var G=global.Math.cos;var H=global.Math.sin;var I=global.Math.tan;var J=global.Math.acos;var K=global.Math.asin;var L=global.Math.atan;var M=global.Math.atan2;var N=global.Math.exp;var O=global.Math.log;var P=global.Math.ceil;var Q=global.Math.imul;var R=global.Math.min;var S=global.Math.clz32;var T=env.abort;var U=env.assert;var V=env.invoke_ii;var W=env.invoke_iiii;var X=env.invoke_vi;var Y=env._pthread_cleanup_pop;var Z=env.___lock;var _=env._abort;var $=env._pthread_cleanup_push;var aa=env.___syscall6;var ba=env._sbrk;var ca=env.___syscall140;var da=env._emscripten_memcpy_big;var ea=env.___syscall54;var fa=env.___unlock;var ga=env.___syscall146;var ha=0.0;
// EMSCRIPTEN_START_FUNCS
function la(a){a=a|0;var b=0;b=i;i=i+a|0;i=i+15&-16;return b|0}function ma(){return i|0}function na(a){a=a|0;i=a}function oa(a,b){a=a|0;b=b|0;i=a;j=b}function pa(a,b){a=a|0;b=b|0;if(!m){m=a;n=b}}function qa(a){a=a|0;B=a}function ra(){return B|0}function sa(a,b,c,d){a=a|0;b=b|0;c=+c;d=+d;var e=0,f=0.0,h=0;if(d==c)if(!(c>0.0&c<=1.0))if(c>1.0){f=c+-1.0;d=1.0}else{f=c;d=1.0}else{f=0.0;d=1.0}else{f=c;d=d-c}if((b|0)>0)e=0;else return;do{h=a+(e<<2)|0;g[h>>2]=(+g[h>>2]-f)/d;e=e+1|0}while((e|0)!=(b|0));return}function ta(a,b){a=a|0;b=b|0;var d=0,e=0,f=0,h=0,j=0,k=0,l=0,m=0.0,n=0.0;l=i;h=xa(b,0,0,0)|0;j=xa(b,1,0,0)|0;d=i;i=i+((1*(b<<3)|0)+15&-16)|0;k=i;i=i+((1*(b<<3)|0)+15&-16)|0;e=(b|0)>0;if(e)f=0;else{za(h,d,k);Ma(h);Ma(j);i=l;return}do{c[d+(f<<3)>>2]=c[a+(f<<2)>>2];g[d+(f<<3)+4>>2]=0.0;f=f+1|0}while((f|0)!=(b|0));za(h,d,k);if(e)d=0;else{Ma(h);Ma(j);i=l;return}do{n=+g[k+(d<<3)>>2];m=+g[k+(d<<3)+4>>2];g[a+(d<<2)>>2]=+E(+(n*n+m*m));d=d+1|0}while((d|0)!=(b|0));Ma(h);Ma(j);i=l;return}function ua(a,b,d){a=a|0;b=b|0;d=d|0;var e=0.0,f=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0;p=i;m=xa(d,0,0,0)|0;n=xa(d,1,0,0)|0;f=i;i=i+((1*(d<<3)|0)+15&-16)|0;j=i;i=i+((1*(d<<3)|0)+15&-16)|0;k=i;i=i+((1*(d<<3)|0)+15&-16)|0;o=i;i=i+((1*(d<<3)|0)+15&-16)|0;l=(d|0)>0;if(l){h=0;do{c[f+(h<<3)>>2]=c[a+(h<<2)>>2];g[f+(h<<3)+4>>2]=0.0;h=h+1|0}while((h|0)!=(d|0));za(m,f,j);if(l){f=0;do{g[k+(f<<3)>>2]=+g[j+(f<<3)>>2]*+g[b+(f<<2)>>2];g[k+(f<<3)+4>>2]=0.0;f=f+1|0}while((f|0)!=(d|0));za(n,k,o);if(!l){Ma(m);Ma(n);i=p;return}e=+(d|0);f=0;do{g[a+(f<<2)>>2]=+g[o+(f<<3)>>2]/e;f=f+1|0}while((f|0)!=(d|0));Ma(m);Ma(n);i=p;return}}else za(m,f,j);za(n,k,o);Ma(m);Ma(n);i=p;return}function va(a,b,d){a=a|0;b=b|0;d=d|0;var e=0.0,f=0.0,h=0,j=0,k=0,l=0,m=0,n=0,o=0.0;n=i;k=(b|0)/2|0;m=xa(b,0,0,0)|0;h=i;i=i+((1*(b<<3)|0)+15&-16)|0;l=i;i=i+((1*(b<<3)|0)+15&-16)|0;if((b|0)>0){j=0;do{c[h+(j<<3)>>2]=c[a+(j<<2)>>2];g[h+(j<<3)+4>>2]=0.0;j=j+1|0}while((j|0)!=(b|0));za(m,h,l);if((b|0)>1){h=0;f=0.0;e=0.0;do{o=+g[l+(h<<3)>>2];o=o*o;f=f+o;e=e+ +(h|0)*o;h=h+1|0}while((h|0)<(k|0))}else{f=0.0;e=0.0}}else{za(m,h,l);f=0.0;e=0.0}Ma(m);i=n;return +(+(d|0)*(e/f)/+(b|0))}function wa(a,b,d){a=a|0;b=b|0;d=d|0;var e=0,f=0,h=0,j=0.0,k=0.0,l=0.0,m=0,n=0,o=0.0,p=0,q=0,r=0,s=0;s=i;p=b+-1|0;e=d+-1|0;q=Q(e,p)|0;r=i;i=i+((1*(q+1<<2)|0)+15&-16)|0;do if((b|0)>1){o=+(e|0);if((d|0)<=1){c[r>>2]=c[a+(p<<2)>>2];e=0;break}b=(Q(e,b+-2|0)|0)+d|0;k=+g[a>>2];f=0;n=0;while(1){n=n+1|0;l=k;k=+g[a+(n<<2)>>2];j=k-l;h=f;m=0;while(1){g[r+(h<<2)>>2]=l+ +(m|0)/o*j;m=m+1|0;if((m|0)==(e|0))break;else h=h+1|0}if((n|0)==(p|0))break;else f=e+f|0}b=b+-1|0;f=p;h=9}else{b=0;f=0;h=9}while(0);if((h|0)==9){c[r+(b<<2)>>2]=c[a+(f<<2)>>2];if((d|0)>1){b=0;do{c[a+(b<<2)>>2]=c[r+((Q(b,p)|0)<<2)>>2];b=b+1|0}while((b|0)!=(e|0))}else e=0}c[a+(e<<2)>>2]=c[r+(q<<2)>>2];i=s;return}function xa(a,b,d,e){a=a|0;b=b|0;d=d|0;e=e|0;var f=0,h=0.0,i=0,j=0.0;f=(a<<3)+264|0;if(!e)i=La(f)|0;else{if(!d)d=0;else d=(c[e>>2]|0)>>>0<f>>>0?0:d;c[e>>2]=f;i=d}if(!i)return i|0;c[i>>2]=a;e=i+4|0;c[e>>2]=b;h=+(a|0);a:do if((a|0)>0){f=b;d=0;while(1){j=+(d|0)*-6.283185307179586/h;j=(f|0)==0?j:-j;g[i+264+(d<<3)>>2]=+G(+j);g[i+264+(d<<3)+4>>2]=+H(+j);d=d+1|0;if((d|0)==(a|0))break a;f=c[e>>2]|0}}while(0);h=+C(+(+E(+h)));f=a;e=i+8|0;d=4;while(1){b:do if((f|0)%(d|0)|0)while(1){switch(d|0){case 4:{d=2;break}case 2:{d=3;break}default:d=d+2|0}d=+(d|0)>h?f:d;if(!((f|0)%(d|0)|0))break b}while(0);f=(f|0)/(d|0)|0;c[e>>2]=d;c[e+4>>2]=f;if((f|0)<=1)break;else e=e+8|0}return i|0}function ya(a,b,d,e,f,h){a=a|0;b=b|0;d=d|0;e=e|0;f=f|0;h=h|0;var i=0,j=0,l=0,m=0,n=0.0,o=0.0,p=0.0,q=0.0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0.0,z=0.0,A=0.0,B=0.0,C=0,D=0.0,E=0.0,F=0.0,G=0.0,H=0.0,I=0.0,J=0.0,K=0.0,L=0.0,M=0.0;w=c[f>>2]|0;m=f+8|0;x=c[f+4>>2]|0;r=a+((Q(x,w)|0)<<3)|0;if((x|0)==1){j=Q(e,d)|0;i=a;f=b;while(1){t=f;u=c[t+4>>2]|0;v=i;c[v>>2]=c[t>>2];c[v+4>>2]=u;i=i+8|0;if((i|0)==(r|0))break;else f=f+(j<<3)|0}}else{j=Q(w,d)|0;l=Q(e,d)|0;i=a;f=b;while(1){ya(i,f,j,e,m,h);i=i+(x<<3)|0;if((i|0)==(r|0))break;else f=f+(l<<3)|0}}switch(w|0){case 2:{j=a;l=x;i=a+(x<<3)|0;f=h+264|0;while(1){o=+g[i>>2];y=+g[f>>2];a=i+4|0;n=+g[a>>2];q=+g[f+4>>2];p=o*y-n*q;q=y*n+o*q;g[i>>2]=+g[j>>2]-p;x=j+4|0;g[a>>2]=+g[x>>2]-q;g[j>>2]=p+ +g[j>>2];g[x>>2]=q+ +g[x>>2];l=l+-1|0;if(!l)break;else{j=j+8|0;i=i+8|0;f=f+(d<<3)|0}}return}case 3:{e=x<<1;n=+g[h+264+((Q(x,d)|0)<<3)+4>>2];l=h+264|0;m=d<<1;f=a;i=x;j=l;while(1){h=f+(x<<3)|0;o=+g[h>>2];p=+g[j>>2];a=f+(x<<3)+4|0;B=+g[a>>2];z=+g[j+4>>2];A=o*p-B*z;z=p*B+o*z;v=f+(e<<3)|0;o=+g[v>>2];B=+g[l>>2];w=f+(e<<3)+4|0;p=+g[w>>2];q=+g[l+4>>2];y=o*B-p*q;q=B*p+o*q;o=A+y;p=z+q;g[h>>2]=+g[f>>2]-o*.5;u=f+4|0;g[a>>2]=+g[u>>2]-p*.5;y=n*(A-y);q=n*(z-q);g[f>>2]=o+ +g[f>>2];g[u>>2]=p+ +g[u>>2];g[v>>2]=q+ +g[h>>2];g[w>>2]=+g[a>>2]-y;g[h>>2]=+g[h>>2]-q;g[a>>2]=y+ +g[a>>2];i=i+-1|0;if(!i)break;else{f=f+8|0;j=j+(d<<3)|0;l=l+(m<<3)|0}}return}case 4:{e=x<<1;b=x*3|0;f=h+264|0;r=d<<1;s=d*3|0;if(!(c[h+4>>2]|0)){i=a;j=x;l=f;m=f;while(1){v=i+(x<<3)|0;n=+g[v>>2];o=+g[l>>2];w=i+(x<<3)+4|0;y=+g[w>>2];D=+g[l+4>>2];E=n*o-y*D;D=o*y+n*D;C=i+(e<<3)|0;n=+g[C>>2];y=+g[m>>2];t=i+(e<<3)+4|0;o=+g[t>>2];p=+g[m+4>>2];q=n*y-o*p;p=y*o+n*p;h=i+(b<<3)|0;n=+g[h>>2];o=+g[f>>2];a=i+(b<<3)+4|0;y=+g[a>>2];z=+g[f+4>>2];B=n*o-y*z;z=o*y+n*z;n=+g[i>>2];y=n-q;u=i+4|0;o=+g[u>>2];A=o-p;n=q+n;g[i>>2]=n;o=p+o;g[u>>2]=o;p=E+B;q=D+z;B=E-B;z=D-z;g[C>>2]=n-p;g[t>>2]=o-q;g[i>>2]=p+ +g[i>>2];g[u>>2]=q+ +g[u>>2];g[v>>2]=y+z;g[w>>2]=A-B;g[h>>2]=y-z;g[a>>2]=A+B;j=j+-1|0;if(!j)break;else{i=i+8|0;l=l+(d<<3)|0;m=m+(r<<3)|0;f=f+(s<<3)|0}}return}else{i=a;j=x;l=f;m=f;while(1){w=i+(x<<3)|0;p=+g[w>>2];q=+g[l>>2];h=i+(x<<3)+4|0;A=+g[h>>2];o=+g[l+4>>2];n=p*q-A*o;o=q*A+p*o;t=i+(e<<3)|0;p=+g[t>>2];A=+g[m>>2];u=i+(e<<3)+4|0;q=+g[u>>2];y=+g[m+4>>2];z=p*A-q*y;y=A*q+p*y;a=i+(b<<3)|0;p=+g[a>>2];q=+g[f>>2];C=i+(b<<3)+4|0;A=+g[C>>2];B=+g[f+4>>2];E=p*q-A*B;B=q*A+p*B;p=+g[i>>2];A=p-z;v=i+4|0;q=+g[v>>2];D=q-y;p=z+p;g[i>>2]=p;q=y+q;g[v>>2]=q;y=n+E;z=o+B;E=n-E;B=o-B;g[t>>2]=p-y;g[u>>2]=q-z;g[i>>2]=y+ +g[i>>2];g[v>>2]=z+ +g[v>>2];g[w>>2]=A-B;g[h>>2]=D+E;g[a>>2]=A+B;g[C>>2]=D-E;j=j+-1|0;if(!j)break;else{i=i+8|0;l=l+(d<<3)|0;m=m+(r<<3)|0;f=f+(s<<3)|0}}return}}case 5:{C=Q(x,d)|0;n=+g[h+264+(C<<3)>>2];o=+g[h+264+(C<<3)+4>>2];C=Q(x,d<<1)|0;p=+g[h+264+(C<<3)>>2];q=+g[h+264+(C<<3)+4>>2];if((x|0)<=0)return;j=d*3|0;l=a;m=a+(x<<3)|0;e=a+(x<<1<<3)|0;b=a+(x*3<<3)|0;f=a+(x<<2<<3)|0;i=0;while(1){H=+g[l>>2];u=l+4|0;F=+g[u>>2];A=+g[m>>2];t=Q(i,d)|0;D=+g[h+264+(t<<3)>>2];v=m+4|0;M=+g[v>>2];I=+g[h+264+(t<<3)+4>>2];G=A*D-M*I;I=D*M+A*I;A=+g[e>>2];t=Q(i<<1,d)|0;M=+g[h+264+(t<<3)>>2];a=e+4|0;D=+g[a>>2];L=+g[h+264+(t<<3)+4>>2];J=A*M-D*L;L=M*D+A*L;A=+g[b>>2];t=Q(j,i)|0;D=+g[h+264+(t<<3)>>2];C=b+4|0;M=+g[C>>2];y=+g[h+264+(t<<3)+4>>2];E=A*D-M*y;y=D*M+A*y;A=+g[f>>2];t=Q(i<<2,d)|0;M=+g[h+264+(t<<3)>>2];w=f+4|0;D=+g[w>>2];B=+g[h+264+(t<<3)+4>>2];z=A*M-D*B;B=M*D+A*B;A=G+z;D=I+B;z=G-z;B=I-B;I=J+E;G=L+y;E=J-E;y=L-y;g[l>>2]=H+(I+A);g[u>>2]=F+(G+D);L=p*I+(H+n*A);J=p*G+(F+n*D);M=q*y+o*B;K=-(o*z)-q*E;g[m>>2]=L-M;g[v>>2]=J-K;g[f>>2]=M+L;g[w>>2]=K+J;A=n*I+(H+p*A);D=n*G+(F+p*D);B=o*y-q*B;E=q*z-o*E;g[e>>2]=B+A;g[a>>2]=E+D;g[b>>2]=A-B;g[C>>2]=D-E;i=i+1|0;if((i|0)==(x|0))break;else{l=l+8|0;m=m+8|0;e=e+8|0;b=b+8|0;f=f+8|0}}return}default:{t=c[h>>2]|0;v=La(w<<3)|0;a:do if((x|0)>0?(w|0)>0:0){if((w|0)>1)u=0;else{m=0;while(1){f=m;i=0;while(1){h=a+(f<<3)|0;d=c[h+4>>2]|0;C=v+(i<<3)|0;c[C>>2]=c[h>>2];c[C+4>>2]=d;i=i+1|0;if((i|0)==(w|0))break;else f=f+x|0}i=v;f=c[i>>2]|0;i=c[i+4>>2]|0;j=m;l=0;while(1){C=a+(j<<3)|0;c[C>>2]=f;c[C+4>>2]=i;l=l+1|0;if((l|0)==(w|0))break;else j=j+x|0}m=m+1|0;if((m|0)==(x|0))break a}}do{f=u;i=0;while(1){r=a+(f<<3)|0;s=c[r+4>>2]|0;C=v+(i<<3)|0;c[C>>2]=c[r>>2];c[C+4>>2]=s;i=i+1|0;if((i|0)==(w|0))break;else f=f+x|0}i=v;f=c[i>>2]|0;i=c[i+4>>2]|0;n=(c[k>>2]=f,+g[k>>2]);e=u;r=0;while(1){j=a+(e<<3)|0;l=j;c[l>>2]=f;c[l+4>>2]=i;l=Q(e,d)|0;m=a+(e<<3)+4|0;o=n;p=+g[m>>2];b=1;s=0;do{C=s+l|0;s=C-((C|0)<(t|0)?0:t)|0;L=+g[v+(b<<3)>>2];J=+g[h+264+(s<<3)>>2];K=+g[v+(b<<3)+4>>2];M=+g[h+264+(s<<3)+4>>2];o=o+(L*J-K*M);g[j>>2]=o;p=p+(J*K+L*M);g[m>>2]=p;b=b+1|0}while((b|0)!=(w|0));r=r+1|0;if((r|0)==(w|0))break;else e=e+x|0}u=u+1|0}while((u|0)!=(x|0))}while(0);Ma(v);return}}}function za(a,b,d){a=a|0;b=b|0;d=d|0;if((b|0)==(d|0)){d=La(c[a>>2]<<3)|0;ya(d,b,1,1,a+8|0,a);Pa(b|0,d|0,c[a>>2]<<3|0)|0;Ma(d);return}else{ya(d,b,1,1,a+8|0,a);return}}function Aa(a){a=a|0;var b=0,d=0;b=i;i=i+16|0;d=b;c[d>>2]=c[a+60>>2];a=Ba(aa(6,d|0)|0)|0;i=b;return a|0}function Ba(a){a=a|0;if(a>>>0>4294963200){c[(Ca()|0)>>2]=0-a;a=-1}return a|0}function Ca(){var a=0;if(!(c[31]|0))a=168;else a=c[(Qa()|0)+64>>2]|0;return a|0}function Da(a,b,d){a=a|0;b=b|0;d=d|0;var e=0,f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;q=i;i=i+48|0;n=q+16|0;m=q;e=q+32|0;o=a+28|0;f=c[o>>2]|0;c[e>>2]=f;p=a+20|0;f=(c[p>>2]|0)-f|0;c[e+4>>2]=f;c[e+8>>2]=b;c[e+12>>2]=d;k=a+60|0;l=a+44|0;b=2;f=f+d|0;while(1){if(!(c[31]|0)){c[n>>2]=c[k>>2];c[n+4>>2]=e;c[n+8>>2]=b;h=Ba(ga(146,n|0)|0)|0}else{$(1,a|0);c[m>>2]=c[k>>2];c[m+4>>2]=e;c[m+8>>2]=b;h=Ba(ga(146,m|0)|0)|0;Y(0)}if((f|0)==(h|0)){f=6;break}if((h|0)<0){f=8;break}f=f-h|0;g=c[e+4>>2]|0;if(h>>>0<=g>>>0)if((b|0)==2){c[o>>2]=(c[o>>2]|0)+h;j=g;b=2}else j=g;else{j=c[l>>2]|0;c[o>>2]=j;c[p>>2]=j;j=c[e+12>>2]|0;h=h-g|0;e=e+8|0;b=b+-1|0}c[e>>2]=(c[e>>2]|0)+h;c[e+4>>2]=j-h}if((f|0)==6){n=c[l>>2]|0;c[a+16>>2]=n+(c[a+48>>2]|0);a=n;c[o>>2]=a;c[p>>2]=a}else if((f|0)==8){c[a+16>>2]=0;c[o>>2]=0;c[p>>2]=0;c[a>>2]=c[a>>2]|32;if((b|0)==2)d=0;else d=d-(c[e+4>>2]|0)|0}i=q;return d|0}function Ea(a){a=a|0;if(!(c[a+68>>2]|0))Fa(a);return}function Fa(a){a=a|0;return}function Ga(a,b,d){a=a|0;b=b|0;d=d|0;var e=0,f=0,g=0;f=i;i=i+32|0;g=f;e=f+20|0;c[g>>2]=c[a+60>>2];c[g+4>>2]=0;c[g+8>>2]=b;c[g+12>>2]=e;c[g+16>>2]=d;if((Ba(ca(140,g|0)|0)|0)<0){c[e>>2]=-1;a=-1}else a=c[e>>2]|0;i=f;return a|0}function Ha(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0;g=i;i=i+80|0;f=g;c[b+36>>2]=3;if((c[b>>2]&64|0)==0?(c[f>>2]=c[b+60>>2],c[f+4>>2]=21505,c[f+8>>2]=g+12,ea(54,f|0)|0):0)a[b+75>>0]=-1;f=Da(b,d,e)|0;i=g;return f|0}function Ia(a){a=a|0;return 0}function Ja(a){a=a|0;var b=0,d=0;do if(a){if((c[a+76>>2]|0)<=-1){b=Ka(a)|0;break}d=(Ia(a)|0)==0;b=Ka(a)|0;if(!d)Fa(a)}else{if(!(c[30]|0))b=0;else b=Ja(c[30]|0)|0;Z(152);a=c[37]|0;if(a)do{if((c[a+76>>2]|0)>-1)d=Ia(a)|0;else d=0;if((c[a+20>>2]|0)>>>0>(c[a+28>>2]|0)>>>0)b=Ka(a)|0|b;if(d|0)Fa(a);a=c[a+56>>2]|0}while((a|0)!=0);fa(152)}while(0);return b|0}function Ka(a){a=a|0;var b=0,d=0,e=0,f=0,g=0,h=0;b=a+20|0;g=a+28|0;if((c[b>>2]|0)>>>0>(c[g>>2]|0)>>>0?(ja[c[a+36>>2]&3](a,0,0)|0,(c[b>>2]|0)==0):0)b=-1;else{h=a+4|0;d=c[h>>2]|0;e=a+8|0;f=c[e>>2]|0;if(d>>>0<f>>>0)ja[c[a+40>>2]&3](a,d-f|0,1)|0;c[a+16>>2]=0;c[g>>2]=0;c[b>>2]=0;c[e>>2]=0;c[h>>2]=0;b=0}return b|0}function La(a){a=a|0;var b=0,d=0,e=0,f=0,g=0,h=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0,r=0,s=0,t=0,u=0,v=0,w=0,x=0,y=0,z=0,A=0,B=0,C=0,D=0,E=0,F=0,G=0,H=0,I=0,J=0,K=0,L=0,M=0,N=0,O=0;O=i;i=i+16|0;p=O;do if(a>>>0<245){q=a>>>0<11?16:a+11&-8;a=q>>>3;k=c[43]|0;b=k>>>a;if(b&3|0){b=(b&1^1)+a|0;d=212+(b<<1<<2)|0;e=d+8|0;f=c[e>>2]|0;g=f+8|0;h=c[g>>2]|0;do if((d|0)!=(h|0)){if(h>>>0<(c[47]|0)>>>0)_();a=h+12|0;if((c[a>>2]|0)==(f|0)){c[a>>2]=d;c[e>>2]=h;break}else _()}else c[43]=k&~(1<<b);while(0);N=b<<3;c[f+4>>2]=N|3;N=f+N+4|0;c[N>>2]=c[N>>2]|1;N=g;i=O;return N|0}h=c[45]|0;if(q>>>0>h>>>0){if(b|0){d=2<<a;d=b<<a&(d|0-d);d=(d&0-d)+-1|0;j=d>>>12&16;d=d>>>j;f=d>>>5&8;d=d>>>f;g=d>>>2&4;d=d>>>g;e=d>>>1&2;d=d>>>e;b=d>>>1&1;b=(f|j|g|e|b)+(d>>>b)|0;d=212+(b<<1<<2)|0;e=d+8|0;g=c[e>>2]|0;j=g+8|0;f=c[j>>2]|0;do if((d|0)!=(f|0)){if(f>>>0<(c[47]|0)>>>0)_();a=f+12|0;if((c[a>>2]|0)==(g|0)){c[a>>2]=d;c[e>>2]=f;l=c[45]|0;break}else _()}else{c[43]=k&~(1<<b);l=h}while(0);h=(b<<3)-q|0;c[g+4>>2]=q|3;e=g+q|0;c[e+4>>2]=h|1;c[e+h>>2]=h;if(l|0){f=c[48]|0;b=l>>>3;d=212+(b<<1<<2)|0;a=c[43]|0;b=1<<b;if(a&b){a=d+8|0;b=c[a>>2]|0;if(b>>>0<(c[47]|0)>>>0)_();else{m=a;n=b}}else{c[43]=a|b;m=d+8|0;n=d}c[m>>2]=f;c[n+12>>2]=f;c[f+8>>2]=n;c[f+12>>2]=d}c[45]=h;c[48]=e;N=j;i=O;return N|0}a=c[44]|0;if(a){d=(a&0-a)+-1|0;M=d>>>12&16;d=d>>>M;L=d>>>5&8;d=d>>>L;N=d>>>2&4;d=d>>>N;b=d>>>1&2;d=d>>>b;e=d>>>1&1;e=c[476+((L|M|N|b|e)+(d>>>e)<<2)>>2]|0;d=(c[e+4>>2]&-8)-q|0;b=e;while(1){a=c[b+16>>2]|0;if(!a){a=c[b+20>>2]|0;if(!a){k=e;break}}b=(c[a+4>>2]&-8)-q|0;N=b>>>0<d>>>0;d=N?b:d;b=a;e=N?a:e}g=c[47]|0;if(k>>>0<g>>>0)_();j=k+q|0;if(k>>>0>=j>>>0)_();h=c[k+24>>2]|0;e=c[k+12>>2]|0;do if((e|0)==(k|0)){b=k+20|0;a=c[b>>2]|0;if(!a){b=k+16|0;a=c[b>>2]|0;if(!a){o=0;break}}while(1){e=a+20|0;f=c[e>>2]|0;if(f|0){a=f;b=e;continue}e=a+16|0;f=c[e>>2]|0;if(!f)break;else{a=f;b=e}}if(b>>>0<g>>>0)_();else{c[b>>2]=0;o=a;break}}else{f=c[k+8>>2]|0;if(f>>>0<g>>>0)_();a=f+12|0;if((c[a>>2]|0)!=(k|0))_();b=e+8|0;if((c[b>>2]|0)==(k|0)){c[a>>2]=e;c[b>>2]=f;o=e;break}else _()}while(0);do if(h|0){a=c[k+28>>2]|0;b=476+(a<<2)|0;if((k|0)==(c[b>>2]|0)){c[b>>2]=o;if(!o){c[44]=c[44]&~(1<<a);break}}else{if(h>>>0<(c[47]|0)>>>0)_();a=h+16|0;if((c[a>>2]|0)==(k|0))c[a>>2]=o;else c[h+20>>2]=o;if(!o)break}b=c[47]|0;if(o>>>0<b>>>0)_();c[o+24>>2]=h;a=c[k+16>>2]|0;do if(a|0)if(a>>>0<b>>>0)_();else{c[o+16>>2]=a;c[a+24>>2]=o;break}while(0);a=c[k+20>>2]|0;if(a|0)if(a>>>0<(c[47]|0)>>>0)_();else{c[o+20>>2]=a;c[a+24>>2]=o;break}}while(0);if(d>>>0<16){N=d+q|0;c[k+4>>2]=N|3;N=k+N+4|0;c[N>>2]=c[N>>2]|1}else{c[k+4>>2]=q|3;c[j+4>>2]=d|1;c[j+d>>2]=d;a=c[45]|0;if(a|0){f=c[48]|0;b=a>>>3;e=212+(b<<1<<2)|0;a=c[43]|0;b=1<<b;if(a&b){a=e+8|0;b=c[a>>2]|0;if(b>>>0<(c[47]|0)>>>0)_();else{r=a;s=b}}else{c[43]=a|b;r=e+8|0;s=e}c[r>>2]=f;c[s+12>>2]=f;c[f+8>>2]=s;c[f+12>>2]=e}c[45]=d;c[48]=j}N=k+8|0;i=O;return N|0}}}else if(a>>>0<=4294967231){a=a+11|0;q=a&-8;k=c[44]|0;if(k){d=0-q|0;a=a>>>8;if(a)if(q>>>0>16777215)j=31;else{s=(a+1048320|0)>>>16&8;G=a<<s;r=(G+520192|0)>>>16&4;G=G<<r;j=(G+245760|0)>>>16&2;j=14-(r|s|j)+(G<<j>>>15)|0;j=q>>>(j+7|0)&1|j<<1}else j=0;b=c[476+(j<<2)>>2]|0;a:do if(!b){a=0;b=0;G=86}else{f=d;a=0;g=q<<((j|0)==31?0:25-(j>>>1)|0);h=b;b=0;while(1){e=c[h+4>>2]&-8;d=e-q|0;if(d>>>0<f>>>0)if((e|0)==(q|0)){a=h;b=h;G=90;break a}else b=h;else d=f;e=c[h+20>>2]|0;h=c[h+16+(g>>>31<<2)>>2]|0;a=(e|0)==0|(e|0)==(h|0)?a:e;e=(h|0)==0;if(e){G=86;break}else{f=d;g=g<<(e&1^1)}}}while(0);if((G|0)==86){if((a|0)==0&(b|0)==0){a=2<<j;a=k&(a|0-a);if(!a)break;s=(a&0-a)+-1|0;n=s>>>12&16;s=s>>>n;m=s>>>5&8;s=s>>>m;o=s>>>2&4;s=s>>>o;r=s>>>1&2;s=s>>>r;a=s>>>1&1;a=c[476+((m|n|o|r|a)+(s>>>a)<<2)>>2]|0}if(!a){j=d;k=b}else G=90}if((G|0)==90)while(1){G=0;s=(c[a+4>>2]&-8)-q|0;e=s>>>0<d>>>0;d=e?s:d;b=e?a:b;e=c[a+16>>2]|0;if(e|0){a=e;G=90;continue}a=c[a+20>>2]|0;if(!a){j=d;k=b;break}else G=90}if((k|0)!=0?j>>>0<((c[45]|0)-q|0)>>>0:0){f=c[47]|0;if(k>>>0<f>>>0)_();h=k+q|0;if(k>>>0>=h>>>0)_();g=c[k+24>>2]|0;d=c[k+12>>2]|0;do if((d|0)==(k|0)){b=k+20|0;a=c[b>>2]|0;if(!a){b=k+16|0;a=c[b>>2]|0;if(!a){u=0;break}}while(1){d=a+20|0;e=c[d>>2]|0;if(e|0){a=e;b=d;continue}d=a+16|0;e=c[d>>2]|0;if(!e)break;else{a=e;b=d}}if(b>>>0<f>>>0)_();else{c[b>>2]=0;u=a;break}}else{e=c[k+8>>2]|0;if(e>>>0<f>>>0)_();a=e+12|0;if((c[a>>2]|0)!=(k|0))_();b=d+8|0;if((c[b>>2]|0)==(k|0)){c[a>>2]=d;c[b>>2]=e;u=d;break}else _()}while(0);do if(g|0){a=c[k+28>>2]|0;b=476+(a<<2)|0;if((k|0)==(c[b>>2]|0)){c[b>>2]=u;if(!u){c[44]=c[44]&~(1<<a);break}}else{if(g>>>0<(c[47]|0)>>>0)_();a=g+16|0;if((c[a>>2]|0)==(k|0))c[a>>2]=u;else c[g+20>>2]=u;if(!u)break}b=c[47]|0;if(u>>>0<b>>>0)_();c[u+24>>2]=g;a=c[k+16>>2]|0;do if(a|0)if(a>>>0<b>>>0)_();else{c[u+16>>2]=a;c[a+24>>2]=u;break}while(0);a=c[k+20>>2]|0;if(a|0)if(a>>>0<(c[47]|0)>>>0)_();else{c[u+20>>2]=a;c[a+24>>2]=u;break}}while(0);do if(j>>>0>=16){c[k+4>>2]=q|3;c[h+4>>2]=j|1;c[h+j>>2]=j;a=j>>>3;if(j>>>0<256){d=212+(a<<1<<2)|0;b=c[43]|0;a=1<<a;if(b&a){a=d+8|0;b=c[a>>2]|0;if(b>>>0<(c[47]|0)>>>0)_();else{w=a;x=b}}else{c[43]=b|a;w=d+8|0;x=d}c[w>>2]=h;c[x+12>>2]=h;c[h+8>>2]=x;c[h+12>>2]=d;break}a=j>>>8;if(a)if(j>>>0>16777215)d=31;else{M=(a+1048320|0)>>>16&8;N=a<<M;L=(N+520192|0)>>>16&4;N=N<<L;d=(N+245760|0)>>>16&2;d=14-(L|M|d)+(N<<d>>>15)|0;d=j>>>(d+7|0)&1|d<<1}else d=0;e=476+(d<<2)|0;c[h+28>>2]=d;a=h+16|0;c[a+4>>2]=0;c[a>>2]=0;a=c[44]|0;b=1<<d;if(!(a&b)){c[44]=a|b;c[e>>2]=h;c[h+24>>2]=e;c[h+12>>2]=h;c[h+8>>2]=h;break}f=j<<((d|0)==31?0:25-(d>>>1)|0);a=c[e>>2]|0;while(1){if((c[a+4>>2]&-8|0)==(j|0)){d=a;G=148;break}b=a+16+(f>>>31<<2)|0;d=c[b>>2]|0;if(!d){G=145;break}else{f=f<<1;a=d}}if((G|0)==145)if(b>>>0<(c[47]|0)>>>0)_();else{c[b>>2]=h;c[h+24>>2]=a;c[h+12>>2]=h;c[h+8>>2]=h;break}else if((G|0)==148){a=d+8|0;b=c[a>>2]|0;N=c[47]|0;if(b>>>0>=N>>>0&d>>>0>=N>>>0){c[b+12>>2]=h;c[a>>2]=h;c[h+8>>2]=b;c[h+12>>2]=d;c[h+24>>2]=0;break}else _()}}else{N=j+q|0;c[k+4>>2]=N|3;N=k+N+4|0;c[N>>2]=c[N>>2]|1}while(0);N=k+8|0;i=O;return N|0}}}else q=-1;while(0);d=c[45]|0;if(d>>>0>=q>>>0){a=d-q|0;b=c[48]|0;if(a>>>0>15){N=b+q|0;c[48]=N;c[45]=a;c[N+4>>2]=a|1;c[N+a>>2]=a;c[b+4>>2]=q|3}else{c[45]=0;c[48]=0;c[b+4>>2]=d|3;N=b+d+4|0;c[N>>2]=c[N>>2]|1}N=b+8|0;i=O;return N|0}a=c[46]|0;if(a>>>0>q>>>0){L=a-q|0;c[46]=L;N=c[49]|0;M=N+q|0;c[49]=M;c[M+4>>2]=L|1;c[N+4>>2]=q|3;N=N+8|0;i=O;return N|0}if(!(c[161]|0)){c[163]=4096;c[162]=4096;c[164]=-1;c[165]=-1;c[166]=0;c[154]=0;x=p&-16^1431655768;c[p>>2]=x;c[161]=x}h=q+48|0;g=c[163]|0;j=q+47|0;f=g+j|0;g=0-g|0;k=f&g;if(k>>>0<=q>>>0){N=0;i=O;return N|0}a=c[153]|0;if(a|0?(w=c[151]|0,x=w+k|0,x>>>0<=w>>>0|x>>>0>a>>>0):0){N=0;i=O;return N|0}b:do if(!(c[154]&4)){a=c[49]|0;c:do if(a){d=620;while(1){b=c[d>>2]|0;if(b>>>0<=a>>>0?(t=d+4|0,(b+(c[t>>2]|0)|0)>>>0>a>>>0):0){e=d;d=t;break}d=c[d+8>>2]|0;if(!d){G=171;break c}}a=f-(c[46]|0)&g;if(a>>>0<2147483647){b=ba(a|0)|0;if((b|0)==((c[e>>2]|0)+(c[d>>2]|0)|0)){if((b|0)!=(-1|0)){h=b;f=a;G=191;break b}}else G=181}}else G=171;while(0);do if((G|0)==171?(v=ba(0)|0,(v|0)!=(-1|0)):0){a=v;b=c[162]|0;d=b+-1|0;if(!(d&a))a=k;else a=k-a+(d+a&0-b)|0;b=c[151]|0;d=b+a|0;if(a>>>0>q>>>0&a>>>0<2147483647){x=c[153]|0;if(x|0?d>>>0<=b>>>0|d>>>0>x>>>0:0)break;b=ba(a|0)|0;if((b|0)==(v|0)){h=v;f=a;G=191;break b}else G=181}}while(0);d:do if((G|0)==181){d=0-a|0;do if(h>>>0>a>>>0&(a>>>0<2147483647&(b|0)!=(-1|0))?(y=c[163]|0,y=j-a+y&0-y,y>>>0<2147483647):0)if((ba(y|0)|0)==(-1|0)){ba(d|0)|0;break d}else{a=y+a|0;break}while(0);if((b|0)!=(-1|0)){h=b;f=a;G=191;break b}}while(0);c[154]=c[154]|4;G=188}else G=188;while(0);if((((G|0)==188?k>>>0<2147483647:0)?(z=ba(k|0)|0,A=ba(0)|0,z>>>0<A>>>0&((z|0)!=(-1|0)&(A|0)!=(-1|0))):0)?(B=A-z|0,B>>>0>(q+40|0)>>>0):0){h=z;f=B;G=191}if((G|0)==191){a=(c[151]|0)+f|0;c[151]=a;if(a>>>0>(c[152]|0)>>>0)c[152]=a;j=c[49]|0;do if(j){e=620;do{a=c[e>>2]|0;b=e+4|0;d=c[b>>2]|0;if((h|0)==(a+d|0)){C=a;D=b;E=d;F=e;G=201;break}e=c[e+8>>2]|0}while((e|0)!=0);if(((G|0)==201?(c[F+12>>2]&8|0)==0:0)?j>>>0<h>>>0&j>>>0>=C>>>0:0){c[D>>2]=E+f;N=j+8|0;N=(N&7|0)==0?0:0-N&7;M=j+N|0;N=f-N+(c[46]|0)|0;c[49]=M;c[46]=N;c[M+4>>2]=N|1;c[M+N+4>>2]=40;c[50]=c[165];break}a=c[47]|0;if(h>>>0<a>>>0){c[47]=h;k=h}else k=a;d=h+f|0;a=620;while(1){if((c[a>>2]|0)==(d|0)){b=a;G=209;break}a=c[a+8>>2]|0;if(!a){b=620;break}}if((G|0)==209)if(!(c[a+12>>2]&8)){c[b>>2]=h;m=a+4|0;c[m>>2]=(c[m>>2]|0)+f;m=h+8|0;m=h+((m&7|0)==0?0:0-m&7)|0;a=d+8|0;a=d+((a&7|0)==0?0:0-a&7)|0;l=m+q|0;g=a-m-q|0;c[m+4>>2]=q|3;do if((a|0)!=(j|0)){if((a|0)==(c[48]|0)){N=(c[45]|0)+g|0;c[45]=N;c[48]=l;c[l+4>>2]=N|1;c[l+N>>2]=N;break}b=c[a+4>>2]|0;if((b&3|0)==1){j=b&-8;f=b>>>3;e:do if(b>>>0>=256){h=c[a+24>>2]|0;e=c[a+12>>2]|0;do if((e|0)==(a|0)){d=a+16|0;e=d+4|0;b=c[e>>2]|0;if(!b){b=c[d>>2]|0;if(!b){L=0;break}}else d=e;while(1){e=b+20|0;f=c[e>>2]|0;if(f|0){b=f;d=e;continue}e=b+16|0;f=c[e>>2]|0;if(!f)break;else{b=f;d=e}}if(d>>>0<k>>>0)_();else{c[d>>2]=0;L=b;break}}else{f=c[a+8>>2]|0;if(f>>>0<k>>>0)_();b=f+12|0;if((c[b>>2]|0)!=(a|0))_();d=e+8|0;if((c[d>>2]|0)==(a|0)){c[b>>2]=e;c[d>>2]=f;L=e;break}else _()}while(0);if(!h)break;b=c[a+28>>2]|0;d=476+(b<<2)|0;do if((a|0)!=(c[d>>2]|0)){if(h>>>0<(c[47]|0)>>>0)_();b=h+16|0;if((c[b>>2]|0)==(a|0))c[b>>2]=L;else c[h+20>>2]=L;if(!L)break e}else{c[d>>2]=L;if(L|0)break;c[44]=c[44]&~(1<<b);break e}while(0);e=c[47]|0;if(L>>>0<e>>>0)_();c[L+24>>2]=h;b=a+16|0;d=c[b>>2]|0;do if(d|0)if(d>>>0<e>>>0)_();else{c[L+16>>2]=d;c[d+24>>2]=L;break}while(0);b=c[b+4>>2]|0;if(!b)break;if(b>>>0<(c[47]|0)>>>0)_();else{c[L+20>>2]=b;c[b+24>>2]=L;break}}else{d=c[a+8>>2]|0;e=c[a+12>>2]|0;b=212+(f<<1<<2)|0;do if((d|0)!=(b|0)){if(d>>>0<k>>>0)_();if((c[d+12>>2]|0)==(a|0))break;_()}while(0);if((e|0)==(d|0)){c[43]=c[43]&~(1<<f);break}do if((e|0)==(b|0))I=e+8|0;else{if(e>>>0<k>>>0)_();b=e+8|0;if((c[b>>2]|0)==(a|0)){I=b;break}_()}while(0);c[d+12>>2]=e;c[I>>2]=d}while(0);a=a+j|0;g=j+g|0}a=a+4|0;c[a>>2]=c[a>>2]&-2;c[l+4>>2]=g|1;c[l+g>>2]=g;a=g>>>3;if(g>>>0<256){d=212+(a<<1<<2)|0;b=c[43]|0;a=1<<a;do if(!(b&a)){c[43]=b|a;M=d+8|0;N=d}else{a=d+8|0;b=c[a>>2]|0;if(b>>>0>=(c[47]|0)>>>0){M=a;N=b;break}_()}while(0);c[M>>2]=l;c[N+12>>2]=l;c[l+8>>2]=N;c[l+12>>2]=d;break}a=g>>>8;do if(!a)d=0;else{if(g>>>0>16777215){d=31;break}M=(a+1048320|0)>>>16&8;N=a<<M;L=(N+520192|0)>>>16&4;N=N<<L;d=(N+245760|0)>>>16&2;d=14-(L|M|d)+(N<<d>>>15)|0;d=g>>>(d+7|0)&1|d<<1}while(0);e=476+(d<<2)|0;c[l+28>>2]=d;a=l+16|0;c[a+4>>2]=0;c[a>>2]=0;a=c[44]|0;b=1<<d;if(!(a&b)){c[44]=a|b;c[e>>2]=l;c[l+24>>2]=e;c[l+12>>2]=l;c[l+8>>2]=l;break}f=g<<((d|0)==31?0:25-(d>>>1)|0);a=c[e>>2]|0;while(1){if((c[a+4>>2]&-8|0)==(g|0)){d=a;G=279;break}b=a+16+(f>>>31<<2)|0;d=c[b>>2]|0;if(!d){G=276;break}else{f=f<<1;a=d}}if((G|0)==276)if(b>>>0<(c[47]|0)>>>0)_();else{c[b>>2]=l;c[l+24>>2]=a;c[l+12>>2]=l;c[l+8>>2]=l;break}else if((G|0)==279){a=d+8|0;b=c[a>>2]|0;N=c[47]|0;if(b>>>0>=N>>>0&d>>>0>=N>>>0){c[b+12>>2]=l;c[a>>2]=l;c[l+8>>2]=b;c[l+12>>2]=d;c[l+24>>2]=0;break}else _()}}else{N=(c[46]|0)+g|0;c[46]=N;c[49]=l;c[l+4>>2]=N|1}while(0);N=m+8|0;i=O;return N|0}else b=620;while(1){a=c[b>>2]|0;if(a>>>0<=j>>>0?(H=a+(c[b+4>>2]|0)|0,H>>>0>j>>>0):0){b=H;break}b=c[b+8>>2]|0}g=b+-47|0;d=g+8|0;d=g+((d&7|0)==0?0:0-d&7)|0;g=j+16|0;d=d>>>0<g>>>0?j:d;a=d+8|0;e=h+8|0;e=(e&7|0)==0?0:0-e&7;N=h+e|0;e=f+-40-e|0;c[49]=N;c[46]=e;c[N+4>>2]=e|1;c[N+e+4>>2]=40;c[50]=c[165];e=d+4|0;c[e>>2]=27;c[a>>2]=c[155];c[a+4>>2]=c[156];c[a+8>>2]=c[157];c[a+12>>2]=c[158];c[155]=h;c[156]=f;c[158]=0;c[157]=a;a=d+24|0;do{a=a+4|0;c[a>>2]=7}while((a+4|0)>>>0<b>>>0);if((d|0)!=(j|0)){h=d-j|0;c[e>>2]=c[e>>2]&-2;c[j+4>>2]=h|1;c[d>>2]=h;a=h>>>3;if(h>>>0<256){d=212+(a<<1<<2)|0;b=c[43]|0;a=1<<a;if(b&a){a=d+8|0;b=c[a>>2]|0;if(b>>>0<(c[47]|0)>>>0)_();else{J=a;K=b}}else{c[43]=b|a;J=d+8|0;K=d}c[J>>2]=j;c[K+12>>2]=j;c[j+8>>2]=K;c[j+12>>2]=d;break}a=h>>>8;if(a)if(h>>>0>16777215)d=31;else{M=(a+1048320|0)>>>16&8;N=a<<M;L=(N+520192|0)>>>16&4;N=N<<L;d=(N+245760|0)>>>16&2;d=14-(L|M|d)+(N<<d>>>15)|0;d=h>>>(d+7|0)&1|d<<1}else d=0;f=476+(d<<2)|0;c[j+28>>2]=d;c[j+20>>2]=0;c[g>>2]=0;a=c[44]|0;b=1<<d;if(!(a&b)){c[44]=a|b;c[f>>2]=j;c[j+24>>2]=f;c[j+12>>2]=j;c[j+8>>2]=j;break}e=h<<((d|0)==31?0:25-(d>>>1)|0);a=c[f>>2]|0;while(1){if((c[a+4>>2]&-8|0)==(h|0)){d=a;G=305;break}b=a+16+(e>>>31<<2)|0;d=c[b>>2]|0;if(!d){G=302;break}else{e=e<<1;a=d}}if((G|0)==302)if(b>>>0<(c[47]|0)>>>0)_();else{c[b>>2]=j;c[j+24>>2]=a;c[j+12>>2]=j;c[j+8>>2]=j;break}else if((G|0)==305){a=d+8|0;b=c[a>>2]|0;N=c[47]|0;if(b>>>0>=N>>>0&d>>>0>=N>>>0){c[b+12>>2]=j;c[a>>2]=j;c[j+8>>2]=b;c[j+12>>2]=d;c[j+24>>2]=0;break}else _()}}}else{N=c[47]|0;if((N|0)==0|h>>>0<N>>>0)c[47]=h;c[155]=h;c[156]=f;c[158]=0;c[52]=c[161];c[51]=-1;a=0;do{N=212+(a<<1<<2)|0;c[N+12>>2]=N;c[N+8>>2]=N;a=a+1|0}while((a|0)!=32);N=h+8|0;N=(N&7|0)==0?0:0-N&7;M=h+N|0;N=f+-40-N|0;c[49]=M;c[46]=N;c[M+4>>2]=N|1;c[M+N+4>>2]=40;c[50]=c[165]}while(0);a=c[46]|0;if(a>>>0>q>>>0){L=a-q|0;c[46]=L;N=c[49]|0;M=N+q|0;c[49]=M;c[M+4>>2]=L|1;c[N+4>>2]=q|3;N=N+8|0;i=O;return N|0}}c[(Ca()|0)>>2]=12;N=0;i=O;return N|0}function Ma(a){a=a|0;var b=0,d=0,e=0,f=0,g=0,h=0,i=0,j=0,k=0,l=0,m=0,n=0,o=0,p=0,q=0;if(!a)return;d=a+-8|0;h=c[47]|0;if(d>>>0<h>>>0)_();a=c[a+-4>>2]|0;b=a&3;if((b|0)==1)_();e=a&-8;m=d+e|0;do if(!(a&1)){a=c[d>>2]|0;if(!b)return;k=d+(0-a)|0;j=a+e|0;if(k>>>0<h>>>0)_();if((k|0)==(c[48]|0)){a=m+4|0;b=c[a>>2]|0;if((b&3|0)!=3){q=k;g=j;break}c[45]=j;c[a>>2]=b&-2;c[k+4>>2]=j|1;c[k+j>>2]=j;return}e=a>>>3;if(a>>>0<256){b=c[k+8>>2]|0;d=c[k+12>>2]|0;a=212+(e<<1<<2)|0;if((b|0)!=(a|0)){if(b>>>0<h>>>0)_();if((c[b+12>>2]|0)!=(k|0))_()}if((d|0)==(b|0)){c[43]=c[43]&~(1<<e);q=k;g=j;break}if((d|0)!=(a|0)){if(d>>>0<h>>>0)_();a=d+8|0;if((c[a>>2]|0)==(k|0))f=a;else _()}else f=d+8|0;c[b+12>>2]=d;c[f>>2]=b;q=k;g=j;break}f=c[k+24>>2]|0;d=c[k+12>>2]|0;do if((d|0)==(k|0)){b=k+16|0;d=b+4|0;a=c[d>>2]|0;if(!a){a=c[b>>2]|0;if(!a){i=0;break}}else b=d;while(1){d=a+20|0;e=c[d>>2]|0;if(e|0){a=e;b=d;continue}d=a+16|0;e=c[d>>2]|0;if(!e)break;else{a=e;b=d}}if(b>>>0<h>>>0)_();else{c[b>>2]=0;i=a;break}}else{e=c[k+8>>2]|0;if(e>>>0<h>>>0)_();a=e+12|0;if((c[a>>2]|0)!=(k|0))_();b=d+8|0;if((c[b>>2]|0)==(k|0)){c[a>>2]=d;c[b>>2]=e;i=d;break}else _()}while(0);if(f){a=c[k+28>>2]|0;b=476+(a<<2)|0;if((k|0)==(c[b>>2]|0)){c[b>>2]=i;if(!i){c[44]=c[44]&~(1<<a);q=k;g=j;break}}else{if(f>>>0<(c[47]|0)>>>0)_();a=f+16|0;if((c[a>>2]|0)==(k|0))c[a>>2]=i;else c[f+20>>2]=i;if(!i){q=k;g=j;break}}d=c[47]|0;if(i>>>0<d>>>0)_();c[i+24>>2]=f;a=k+16|0;b=c[a>>2]|0;do if(b|0)if(b>>>0<d>>>0)_();else{c[i+16>>2]=b;c[b+24>>2]=i;break}while(0);a=c[a+4>>2]|0;if(a)if(a>>>0<(c[47]|0)>>>0)_();else{c[i+20>>2]=a;c[a+24>>2]=i;q=k;g=j;break}else{q=k;g=j}}else{q=k;g=j}}else{q=d;g=e}while(0);if(q>>>0>=m>>>0)_();a=m+4|0;b=c[a>>2]|0;if(!(b&1))_();if(!(b&2)){if((m|0)==(c[49]|0)){p=(c[46]|0)+g|0;c[46]=p;c[49]=q;c[q+4>>2]=p|1;if((q|0)!=(c[48]|0))return;c[48]=0;c[45]=0;return}if((m|0)==(c[48]|0)){p=(c[45]|0)+g|0;c[45]=p;c[48]=q;c[q+4>>2]=p|1;c[q+p>>2]=p;return}g=(b&-8)+g|0;e=b>>>3;do if(b>>>0>=256){f=c[m+24>>2]|0;a=c[m+12>>2]|0;do if((a|0)==(m|0)){b=m+16|0;d=b+4|0;a=c[d>>2]|0;if(!a){a=c[b>>2]|0;if(!a){n=0;break}}else b=d;while(1){d=a+20|0;e=c[d>>2]|0;if(e|0){a=e;b=d;continue}d=a+16|0;e=c[d>>2]|0;if(!e)break;else{a=e;b=d}}if(b>>>0<(c[47]|0)>>>0)_();else{c[b>>2]=0;n=a;break}}else{b=c[m+8>>2]|0;if(b>>>0<(c[47]|0)>>>0)_();d=b+12|0;if((c[d>>2]|0)!=(m|0))_();e=a+8|0;if((c[e>>2]|0)==(m|0)){c[d>>2]=a;c[e>>2]=b;n=a;break}else _()}while(0);if(f|0){a=c[m+28>>2]|0;b=476+(a<<2)|0;if((m|0)==(c[b>>2]|0)){c[b>>2]=n;if(!n){c[44]=c[44]&~(1<<a);break}}else{if(f>>>0<(c[47]|0)>>>0)_();a=f+16|0;if((c[a>>2]|0)==(m|0))c[a>>2]=n;else c[f+20>>2]=n;if(!n)break}d=c[47]|0;if(n>>>0<d>>>0)_();c[n+24>>2]=f;a=m+16|0;b=c[a>>2]|0;do if(b|0)if(b>>>0<d>>>0)_();else{c[n+16>>2]=b;c[b+24>>2]=n;break}while(0);a=c[a+4>>2]|0;if(a|0)if(a>>>0<(c[47]|0)>>>0)_();else{c[n+20>>2]=a;c[a+24>>2]=n;break}}}else{b=c[m+8>>2]|0;d=c[m+12>>2]|0;a=212+(e<<1<<2)|0;if((b|0)!=(a|0)){if(b>>>0<(c[47]|0)>>>0)_();if((c[b+12>>2]|0)!=(m|0))_()}if((d|0)==(b|0)){c[43]=c[43]&~(1<<e);break}if((d|0)!=(a|0)){if(d>>>0<(c[47]|0)>>>0)_();a=d+8|0;if((c[a>>2]|0)==(m|0))l=a;else _()}else l=d+8|0;c[b+12>>2]=d;c[l>>2]=b}while(0);c[q+4>>2]=g|1;c[q+g>>2]=g;if((q|0)==(c[48]|0)){c[45]=g;return}}else{c[a>>2]=b&-2;c[q+4>>2]=g|1;c[q+g>>2]=g}a=g>>>3;if(g>>>0<256){d=212+(a<<1<<2)|0;b=c[43]|0;a=1<<a;if(b&a){a=d+8|0;b=c[a>>2]|0;if(b>>>0<(c[47]|0)>>>0)_();else{o=a;p=b}}else{c[43]=b|a;o=d+8|0;p=d}c[o>>2]=q;c[p+12>>2]=q;c[q+8>>2]=p;c[q+12>>2]=d;return}a=g>>>8;if(a)if(g>>>0>16777215)d=31;else{o=(a+1048320|0)>>>16&8;p=a<<o;n=(p+520192|0)>>>16&4;p=p<<n;d=(p+245760|0)>>>16&2;d=14-(n|o|d)+(p<<d>>>15)|0;d=g>>>(d+7|0)&1|d<<1}else d=0;e=476+(d<<2)|0;c[q+28>>2]=d;c[q+20>>2]=0;c[q+16>>2]=0;a=c[44]|0;b=1<<d;do if(a&b){f=g<<((d|0)==31?0:25-(d>>>1)|0);a=c[e>>2]|0;while(1){if((c[a+4>>2]&-8|0)==(g|0)){d=a;e=130;break}b=a+16+(f>>>31<<2)|0;d=c[b>>2]|0;if(!d){e=127;break}else{f=f<<1;a=d}}if((e|0)==127)if(b>>>0<(c[47]|0)>>>0)_();else{c[b>>2]=q;c[q+24>>2]=a;c[q+12>>2]=q;c[q+8>>2]=q;break}else if((e|0)==130){a=d+8|0;b=c[a>>2]|0;p=c[47]|0;if(b>>>0>=p>>>0&d>>>0>=p>>>0){c[b+12>>2]=q;c[a>>2]=q;c[q+8>>2]=b;c[q+12>>2]=d;c[q+24>>2]=0;break}else _()}}else{c[44]=a|b;c[e>>2]=q;c[q+24>>2]=e;c[q+12>>2]=q;c[q+8>>2]=q}while(0);q=(c[51]|0)+-1|0;c[51]=q;if(!q)a=628;else return;while(1){a=c[a>>2]|0;if(!a)break;else a=a+8|0}c[51]=-1;return}function Na(){}function Oa(b,d,e){b=b|0;d=d|0;e=e|0;var f=0,g=0,h=0,i=0;f=b+e|0;if((e|0)>=20){d=d&255;h=b&3;i=d|d<<8|d<<16|d<<24;g=f&~3;if(h){h=b+4-h|0;while((b|0)<(h|0)){a[b>>0]=d;b=b+1|0}}while((b|0)<(g|0)){c[b>>2]=i;b=b+4|0}}while((b|0)<(f|0)){a[b>>0]=d;b=b+1|0}return b-e|0}function Pa(b,d,e){b=b|0;d=d|0;e=e|0;var f=0;if((e|0)>=4096)return da(b|0,d|0,e|0)|0;f=b|0;if((b&3)==(d&3)){while(b&3){if(!e)return f|0;a[b>>0]=a[d>>0]|0;b=b+1|0;d=d+1|0;e=e-1|0}while((e|0)>=4){c[b>>2]=c[d>>2];b=b+4|0;d=d+4|0;e=e-4|0}}while((e|0)>0){a[b>>0]=a[d>>0]|0;b=b+1|0;d=d+1|0;e=e-1|0}return f|0}function Qa(){return 0}function Ra(a,b){a=a|0;b=b|0;return ia[a&1](b|0)|0}function Sa(a,b,c,d){a=a|0;b=b|0;c=c|0;d=d|0;return ja[a&3](b|0,c|0,d|0)|0}function Ta(a,b){a=a|0;b=b|0;ka[a&1](b|0)}function Ua(a){a=a|0;T(0);return 0}function Va(a,b,c){a=a|0;b=b|0;c=c|0;T(1);return 0}function Wa(a){a=a|0;T(2)}
// EMSCRIPTEN_END_FUNCS
var ia=[Ua,Aa];var ja=[Va,Ha,Ga,Da];var ka=[Wa,Ea];return{_spectralCentroid:va,_fflush:Ja,_fftFilter:ua,_pthread_self:Qa,_memset:Oa,_linearInterp:wa,_malloc:La,_memcpy:Pa,_fft:ta,_normalize:sa,_free:Ma,___errno_location:Ca,runPostSets:Na,stackAlloc:la,stackSave:ma,stackRestore:na,establishStackSpace:oa,setThrew:pa,setTempRet0:qa,getTempRet0:ra,dynCall_ii:Ra,dynCall_iiii:Sa,dynCall_vi:Ta}})
// EMSCRIPTEN_END_ASM
(Module.asmGlobalArg,Module.asmLibraryArg,buffer);var _spectralCentroid=Module["_spectralCentroid"]=asm["_spectralCentroid"];var _fflush=Module["_fflush"]=asm["_fflush"];var _fftFilter=Module["_fftFilter"]=asm["_fftFilter"];var _pthread_self=Module["_pthread_self"]=asm["_pthread_self"];var _memset=Module["_memset"]=asm["_memset"];var _linearInterp=Module["_linearInterp"]=asm["_linearInterp"];var _malloc=Module["_malloc"]=asm["_malloc"];var _memcpy=Module["_memcpy"]=asm["_memcpy"];var _fft=Module["_fft"]=asm["_fft"];var _normalize=Module["_normalize"]=asm["_normalize"];var _free=Module["_free"]=asm["_free"];var ___errno_location=Module["___errno_location"]=asm["___errno_location"];var runPostSets=Module["runPostSets"]=asm["runPostSets"];var dynCall_ii=Module["dynCall_ii"]=asm["dynCall_ii"];var dynCall_iiii=Module["dynCall_iiii"]=asm["dynCall_iiii"];var dynCall_vi=Module["dynCall_vi"]=asm["dynCall_vi"];Runtime.stackAlloc=asm["stackAlloc"];Runtime.stackSave=asm["stackSave"];Runtime.stackRestore=asm["stackRestore"];Runtime.establishStackSpace=asm["establishStackSpace"];Runtime.setTempRet0=asm["setTempRet0"];Runtime.getTempRet0=asm["getTempRet0"];function ExitStatus(status){this.name="ExitStatus";this.message="Program terminated with exit("+status+")";this.status=status}ExitStatus.prototype=new Error;ExitStatus.prototype.constructor=ExitStatus;var initialStackTop;var preloadStartTime=null;var calledMain=false;dependenciesFulfilled=function runCaller(){if(!Module["calledRun"])run();if(!Module["calledRun"])dependenciesFulfilled=runCaller};Module["callMain"]=Module.callMain=function callMain(args){args=args||[];ensureInitRuntime();var argc=args.length+1;function pad(){for(var i=0;i<4-1;i++){argv.push(0)}}var argv=[allocate(intArrayFromString(Module["thisProgram"]),"i8",ALLOC_NORMAL)];pad();for(var i=0;i<argc-1;i=i+1){argv.push(allocate(intArrayFromString(args[i]),"i8",ALLOC_NORMAL));pad()}argv.push(0);argv=allocate(argv,"i32",ALLOC_NORMAL);try{var ret=Module["_main"](argc,argv,0);exit(ret,true)}catch(e){if(e instanceof ExitStatus){return}else if(e=="SimulateInfiniteLoop"){Module["noExitRuntime"]=true;return}else{if(e&&typeof e==="object"&&e.stack)Module.printErr("exception thrown: "+[e,e.stack]);throw e}}finally{calledMain=true}};function run(args){args=args||Module["arguments"];if(preloadStartTime===null)preloadStartTime=Date.now();if(runDependencies>0){return}preRun();if(runDependencies>0)return;if(Module["calledRun"])return;function doRun(){if(Module["calledRun"])return;Module["calledRun"]=true;if(ABORT)return;ensureInitRuntime();preMain();if(Module["onRuntimeInitialized"])Module["onRuntimeInitialized"]();if(Module["_main"]&&shouldRunNow)Module["callMain"](args);postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout((function(){setTimeout((function(){Module["setStatus"]("")}),1);doRun()}),1)}else{doRun()}}Module["run"]=Module.run=run;function exit(status,implicit){if(implicit&&Module["noExitRuntime"]){return}if(Module["noExitRuntime"]){}else{ABORT=true;EXITSTATUS=status;STACKTOP=initialStackTop;exitRuntime();if(Module["onExit"])Module["onExit"](status)}if(ENVIRONMENT_IS_NODE){process["exit"](status)}else if(ENVIRONMENT_IS_SHELL&&typeof quit==="function"){quit(status)}throw new ExitStatus(status)}Module["exit"]=Module.exit=exit;var abortDecorators=[];function abort(what){if(what!==undefined){Module.print(what);Module.printErr(what);what=JSON.stringify(what)}else{what=""}ABORT=true;EXITSTATUS=1;var extra="\nIf this abort() is unexpected, build with -s ASSERTIONS=1 which can give more information.";var output="abort("+what+") at "+stackTrace()+extra;if(abortDecorators){abortDecorators.forEach((function(decorator){output=decorator(output,what)}))}throw output}Module["abort"]=Module.abort=abort;if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}var shouldRunNow=true;if(Module["noInitialRun"]){shouldRunNow=false}run()
// Production steps of ECMA-262, Edition 5, 15.4.4.18
// Reference: http://es5.github.io/#x15.4.4.18
if (!Float32Array.prototype.forEach) {
Float32Array.prototype.forEach = function(callback, thisArg) {
var T, k;
if (this == null) {
throw new TypeError(' this is null or not defined');
}
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
var O = Object(this);
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If IsCallable(callback) is false, throw a TypeError exception.
// See: http://es5.github.com/#x9.11
if (typeof callback !== "function") {
throw new TypeError(callback + ' is not a function');
}
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 1) {
T = thisArg;
}
// 6. Let k be 0
k = 0;
// 7. Repeat, while k < len
while (k < len) {
var kValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
if (k in O) {
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
kValue = O[k];
// ii. Call the Call internal method of callback with T as the this value and
// argument list containing kValue, k, and O.
callback.call(T, kValue, k, O);
}
// d. Increase k by 1.
k++;
}
// 8. return undefined
};
}
// Production steps of ECMA-262, Edition 5, 15.4.4.17
// Reference: http://es5.github.io/#x15.4.4.17
if (!Float32Array.prototype.some) {
Float32Array.prototype.some = function(fun/*, thisArg*/) {
'use strict';
if (this == null) {
throw new TypeError('Array.prototype.some called on null or undefined');
}
if (typeof fun !== 'function') {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
for (var i = 0; i < len; i++) {
if (i in t && fun.call(thisArg, t[i], i, t)) {
return true;
}
}
return false;
};
}
// Production steps of ECMA-262, Edition 5, 15.4.4.19
// Reference: http://es5.github.io/#x15.4.4.19
if (!Float32Array.prototype.map) {
Float32Array.prototype.map = function(callback, thisArg) {
var T, A, k;
if (this == null) {
throw new TypeError(' this is null or not defined');
}
// 1. Let O be the result of calling ToObject passing the |this|
// value as the argument.
var O = Object(this);
// 2. Let lenValue be the result of calling the Get internal
// method of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If IsCallable(callback) is false, throw a TypeError exception.
// See: http://es5.github.com/#x9.11
if (typeof callback !== 'function') {
throw new TypeError(callback + ' is not a function');
}
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 1) {
T = thisArg;
}
// 6. Let A be a new array created as if by the expression new Array(len)
// where Array is the standard built-in constructor with that name and
// len is the value of len.
A = new Array(len);
// 7. Let k be 0
k = 0;
// 8. Repeat, while k < len
while (k < len) {
var kValue, mappedValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the HasProperty internal
// method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
if (k in O) {
// i. Let kValue be the result of calling the Get internal
// method of O with argument Pk.
kValue = O[k];
// ii. Let mappedValue be the result of calling the Call internal
// method of callback with T as the this value and argument
// list containing kValue, k, and O.
mappedValue = callback.call(T, kValue, k, O);
// iii. Call the DefineOwnProperty internal method of A with arguments
// Pk, Property Descriptor
// { Value: mappedValue,
// Writable: true,
// Enumerable: true,
// Configurable: true },
// and false.
// In browsers that support Object.defineProperty, use the following:
// Object.defineProperty(A, k, {
// value: mappedValue,
// writable: true,
// enumerable: true,
// configurable: true
// });
// For best browser support, use the following:
A[k] = mappedValue;
}
// d. Increase k by 1.
k++;
}
// 9. return A
return A;
};
}
if (!Float32Array.prototype.every) {
Float32Array.prototype.every = function(callbackfn, thisArg) {
'use strict';
var T, k;
if (this == null) {
throw new TypeError('this is null or not defined');
}
// 1. Let O be the result of calling ToObject passing the this
// value as the argument.
var O = Object(this);
// 2. Let lenValue be the result of calling the Get internal method
// of O with the argument "length".
// 3. Let len be ToUint32(lenValue).
var len = O.length >>> 0;
// 4. If IsCallable(callbackfn) is false, throw a TypeError exception.
if (typeof callbackfn !== 'function') {
throw new TypeError();
}
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 1) {
T = thisArg;
}
// 6. Let k be 0.
k = 0;
// 7. Repeat, while k < len
while (k < len) {
var kValue;
// a. Let Pk be ToString(k).
// This is implicit for LHS operands of the in operator
// b. Let kPresent be the result of calling the HasProperty internal
// method of O with argument Pk.
// This step can be combined with c
// c. If kPresent is true, then
if (k in O) {
// i. Let kValue be the result of calling the Get internal method
// of O with argument Pk.
kValue = O[k];
// ii. Let testResult be the result of calling the Call internal method
// of callbackfn with T as the this value and argument list
// containing kValue, k, and O.
var testResult = callbackfn.call(T, kValue, k, O);
// iii. If ToBoolean(testResult) is false, return false.
if (!testResult) {
return false;
}
}
k++;
}
return true;
};
}
/**
* @fileOverview
* @module core
*/
// TODO: put this in the master
var params = {
isLogging: false
};
/**
* A namespace / the singleton dtm object.
* @name module:core#dtm
* @type {object}
*/
var dtm = {
version: '0.8',
log: function (arg) {
if (params.isLogging) {
if (arguments.callee.caller.name) {
console.log(arguments.callee.caller.name + ': ' + arg);
} else {
console.log(arg);
}
}
},
// TODO: put these in dtm.master
modelColl: [],
modelCallers: {},
clocks: [],
params: {
plotter: null,
printer: null,
stream: false,
traced: []
},
// TODO: a function to list currently loaded objects, such as data, arrays, models... - for console livecoding situation
get: function (param) {
switch (param) {
case 'models':
return dtm.modelColl;
case 'modelNames':
var res = [];
dtm.modelColl.forEach(function (m) {
res.push(m.get('name'));
});
return res;
default:
return null;
}
},
wa: {
isOn: true,
useOfflineContext: false
},
startWebAudio: function () {
dtm.wa.isOn = true;
dtm.wa.actx = new (window.AudioContext || window.webkitAudioContext)();
dtm.wa.now = function () {
return dtm.wa.actx.currentTime;
};
dtm.wa.out = function () {
return dtm.wa.actx.destination;
};
dtm.wa.clMult = 0.01;
dtm.wa.clockBuf = dtm.wa.actx.createBuffer(1, Math.round(dtm.wa.actx.sampleRate * dtm.wa.clMult), dtm.wa.actx.sampleRate);
},
startWebMidi: function () {
if (isEmpty(MIDI.prototype.out)) {
if (navigator.requestMIDIAccess) {
navigator.requestMIDIAccess({
sysex: false
}).then(function (webMidi) {
var devices = [];
var iter = webMidi.outputs.values();
for (var i = iter.next(); i && !i.done; i = iter.next()) {
devices.push(i.value);
}
MIDI.prototype.devices = devices;
MIDI.prototype.out = devices[0];
var inputs = Array.from(webMidi.inputs.values());
inputs.forEach(function (device) {
device.onmidimessage = MIDI.prototype.oninput;
});
}, null);
} else {
console.log("Web MIDI is not supported in this browser!");
}
}
},
oscParams: {
isOpen: false,
port: null
},
startOsc: function () {
dtm.osc.isOn = true;
dtm.osc.start();
},
export: function () {
objForEach(dtm, function (v, k) {
if (isEmpty(window[k])) {
window[k] = v;
}
});
},
setPlotter: function (fn) {
dtm.params.plotter = fn;
},
setPrinter: function (fn) {
dtm.params.printer = fn;
},
cache: {
audioStream: []
}
};
this.dtm = dtm;
console.log('Loading DTM version ' + dtm.version);
/**
* @fileOverview These utility functions are mainly used within DTM API for development. However, you can call them like: `dtm.util.name()`.
* @module utils
*/
/* TYPE CHECKING */
function isNaNfast(value) {
return value !== value;
}
/**
* Returns true for undefined, null, and NaN values
* @param value
* @returns {boolean}
*/
function isEmpty(value) {
if (typeof(value) === 'undefined') {
return true;
} else if (value === null) {
return true;
} else return (typeof(value) === 'number' && isNaNfast(value));
}
/**
* Returns true if the value is a number and is not NaN
* @param value
* @returns {boolean}
*/
function isNumber(value) {
return (typeof(value) === 'number' && !isNaNfast(value));
}
/**
* Checks if the value is a number and is an integer value
* @param value
* @returns {boolean}
*/
function isInteger(value) {
if (isNumber(value)) {
return Number.isInteger(value);
} else {
return false;
}
}
/**
* Checks if the value is a string
* @param value
* @returns {boolean}
*/
function isString(value) {
return typeof(value) === 'string';
}
function toString(value) {
if (isNumber(value)) {
return value.toString();
} else {
return value;
}
}
/**
* Checks if the value is a boolean value
* @param value
* @returns {boolean}
*/
function isBoolean(value) {
return typeof(value) === 'boolean';
}
/**
* Checks if the value is a function
* @param value
* @returns {boolean}
*/
function isFunction(value) {
return typeof(value) === 'function' && !value.hasOwnProperty('meta');
}
/**
* Checks if the value is an instance of Promise
* @param obj
* @returns {boolean}
*/
function isPromise(obj) {
if (isObject(obj)) {
if (obj.constructor === Promise) {
return true;
}
} else {
return false;
}
}
/**
* Checks if the value is an object and not null object
* @param val
* @returns {boolean}
*/
function isObject(val) {
return (typeof(val) === 'object' && val !== null);
}
function isFile(obj) {
return (obj.constructor.name === 'File');
}
function isURL(val, extension) {
if (isString(extension)) {
return val.endsWith(extension);
} else {
return val.startsWith('http');
}
}
function isDataURL(val) {
return val.startsWith('data:');
}
/**
* Checks if the value is primitive single value
* @param val
* @returns {boolean}
*/
function isSingleVal(val) {
return (!isArray(val) && !isDtmObj(val) && !isFunction(val) && !isEmpty(val));
}
/**
* Checks if a value is any kind of array
* @private
* @param val
* @returns {boolean}
*/
function isArray(val) {
return Array.isArray(val) || isFloat32Array(val);
// return !isEmpty(val) && val.constructor === Array || isFloat32Array(val);
}
/**
* Checks if the value is a Float32Array
* @param val
* @returns {boolean}
*/
function isFloat32Array(val) {
var res = false;
if (!isEmpty(val)) {
// if (val.constructor.name === 'Float32Array' && val.length > 0) {
if (val.constructor === Float32Array && val.length > 0) {
res = true;
}
}
return res;
}
/**
* Checks if the value is a regular number array
* @param val
* @returns {boolean}
*/
function isNumArray(val) {
var res = false;
if (isArray(val) && !isFloat32Array(val) && val.length > 0) {
res = val.every(function (v) {
return isNumber(v);
});
}
return res;
}
/**
* Checks if the object is a string array with values like ['1', '2', '3.45']
* @param val
* @returns {boolean}
*/
function isParsableNumArray(val) {
var res = false;
if (isStringArray(val)) {
res = val.every(function (val) {
return !isNaNfast(parseFloat(val));
})
}
return res;
}
/**
* Checks if the array consists of the generic object type (i.e., {}) items
* @param val
* @returns {boolean}
*/
function isObjArray(val) {
var res = false;
if (isArray(val) && val.length > 0) {
res = val.every(function (v) {
return isObject(v) && !isDtmObj(v);
});
}
return res;
}
/**
* Checks if the value is either a regular or typed number array
* @param val
* @returns {boolean}
*/
function isNumOrFloat32Array(val) {
return isFloat32Array(val) || isNumArray(val);
}
/**
* Checks if the value is an array with mixed value types (e.g., numbers and strings mixed)
* @param val
* @returns {boolean}
*/
function isMixedArray(val) {
return isArray(val) && !isStringArray(val) && !isBoolArray(val) && !isNumOrFloat32Array(val) && !isNestedArray(val) && !isNestedWithDtmArray(val);
}
/**
* Checks if the value is a multi-dimensional array
* @param val
* @returns {boolean}
*/
function isNestedArray(val) {
var res = false;
if (isArray(val)) {
// res = val.some(function (v) {
// return isArray(v);
// });
for (var i = 0, l = val.length; i < l; i++) {
if (isArray(val[i])) {
return true;
}
}
}
return res;
}
/**
* Checks if the value is a nested (regular) array consist of the dtm.array instances
* @param val
* @returns {boolean}
*/
function isNestedWithDtmArray(val) {
var res = false;
if (isArray(val)) {
res = val.some(function (v) {
return isDtmArray(v);
});
}
return res;
}
function getMaxArrayDepth(val) {
if (isArray(val)) {
var depth = 1;
var list = [];
for (var i = 0, l = val.length; i < l; i++) {
if (isArray(val[i])) {
list.push(getMaxArrayDepth(val[i]));
} else if (isDtmArray(val[i])) {
list.push(getMaxDtmArrayDepth(val[i]));
}
}
if (list.length > 0) {
depth += Math.max.apply(this, list);
}
return depth;
} else {
return 0;
}
}
function getMaxDtmArrayDepth(val) {
if (isDtmArray(val)) {
var depth = 1;
var list = [];
if (isNestedDtmArray(val)) {
val.each(function (v) {
if (isDtmArray(v)) {
list.push(getMaxDtmArrayDepth(v));
}
});
}
if (list.length > 0) {
depth += Math.max.apply(this, list);
}
return depth;
} else {
return 0;
}
}
function getMaxDepth(arr) {
var depth, list, i, l;
if (isArray(arr)) {
depth = 1;
list = [];
for (i = 0, l = arr.length; i < l; i++) {
if (isArray(arr[i]) || isDtmArray(arr[i])) {
list.push(getMaxDepth(arr[i]));
}
}
if (list.length > 0) {
depth += Math.max.apply(this, list);
}
return depth;
} else if (isDtmArray(arr)) {
// depth = 1;
// list = [];
//
// for (i = 0, l = arr.val.length; i < l; i++) {
// if (isArray(arr.val[i]) || isDtmArray(arr.val[i])) {
// list.push(getMaxDepth(arr.val[i]));
// }
// }
//
// if (list.length > 0) {
// depth += Math.max.apply(this, list);
// }
//
// return depth;
return arr.params.depth;
} else {
return 0;
}
}
/**
* Checks if the value is an instance of DTM object
* @param val
* @returns {boolean}
*/
function isDtmObj(val) {
if (isObject(val) || typeof(val) === 'function') {
return val.hasOwnProperty('meta');
} else {
return false;
}
}
function isDtmSynth(val) {
if (isObject(val) || typeof(val) === 'function') {
if (val.hasOwnProperty('meta')) {
return val.meta.type === 'dtm.synth' || val.meta.type === 'dtm.music';
} else {
return false;
}
} else {
return false;
}
}
function isDtmData(val) {
if (isObject(val) || typeof(val) === 'function') {
if (val.hasOwnProperty('meta')) {
return (val.meta.type === 'dtm.data' || val.meta.type === 'dtm.generator');
} else {
return false;
}
} else {
return false;
}
}
function isNestedDtmData(val) {
if (isDtmData(val)) {
return val.every(function (v) {
return isDtmData(v);
});
} else {
return false;
}
}
function isNumDtmData(obj) {
return isDtmData(obj) && isNumOrFloat32Array(obj.get());
}
function isNestedNumDtmData(obj) {
return isNestedDtmData(obj) && obj.get().every(function (a) { return isNumDtmData(a)});
}
/**
* Checks if the value is an instance of dtm.array
* @param val
* @returns {boolean}
*/
function isDtmArray(val) {
if (isObject(val) || typeof(val) === 'function') {
if (val.hasOwnProperty('meta')) {
return ['dtm.array', 'dtm.data', 'dtm.generator'].indexOf(val.meta.type) !== -1;
} else {
return false;
}
} else {
return false;
}
}
/**
* Checks if the value is an instance of dtm.array with children dtm.arrays
* @param val
* @returns {boolean}
*/
function isNestedDtmArray(val) {
if (isDtmArray(val)) {
return val.params.nested;
// return val.every(function (v) {
// return isDtmArray(v);
// });
} else {
return false;
}
}
function isNumDtmArray(obj) {
return isDtmArray(obj) && isNumOrFloat32Array(obj.get());
}
function isNestedNumDtmArray(obj) {
return isNestedDtmArray(obj) && obj.get().every(function (a) { return isNumDtmArray(a)});
}
/**
* Checks if the value is a string array
* @param val
* @returns {boolean}
*/
function isStringArray(val) {
var res = false;
if (isArray(val)) {
res = val.every(function (v) {
return isString(v);
});
}
return res;
}
/**
* Checks if the value is a boolean array
* @param val
* @returns {boolean}
*/
function isBoolArray(val) {
var res = false;
if (isArray(val)) {
res = val.every(function (v) {
return isBoolean(v);
});
}
return res;
}
/**
* Checks if the given array has any "empty" values
* @param array
* @returns {boolean}
*/
function hasMissingValues(array) {
// assuming the input is an array with length > 0
return array.some(function (v) {
return isEmpty(v);
});
}
// TODO: implement
function arrayCompare(first, second) {
}
function objCompare(first, second) {
var res = false;
if (isFunction(first) && isFunction(second)) {
return first.toString() === second.toString();
} else if (isObject(first) && isObject(second)) {
return JSON.stringify(first) === JSON.stringify(second);
}
return res;
}
/**
* Converts the arguments object into a regular array
* @param args {object} The arguments object of the caller function
* @returns {Array}
*/
function argsToArray(args) {
var res = [];
for (var i = 0; i < args.length; i++) {
res[i] = args[i];
}
return res;
}
/**
* Iterates over the arguments object of the caller function
* @param args {object} The arguments object
* @param fn {function} A callback function with same arguments of Array.forEach
*/
function argsForEach(args, fn) {
for (var i = 0, l = args.length; i < l; i++) {
fn.apply(this, args[i]);
}
}
/**
* Checks if the arguments object consist of a single array item
* @param args {object} The arguments object
* @returns {boolean}
*/
function argIsSingleArray(args) {
return (args.length === 1 && isArray(args[0]));
}
function argsAreSingleVals(args) {
var res = false;
if (!argIsSingleArray(args) && args.length > 0) {
var argsArr = argsToArray(args);
res = argsArr.every(function (a) {
return isSingleVal(a);
});
}
return res;
}
/**
* Converts various number or array types into a Float32Array. Returns null if not convertible.
* @param src
* @returns {Float32Array|null}
*/
function toFloat32Array(src) {
if (isNumber(src)) {
return new Float32Array([src]);
} else if (isDtmObj(src)) {
if (isDtmArray(src)) {
if (isNumArray(src.get())) {
return new Float32Array(src.get());
} else if (isFloat32Array(src.get())) {
return src.get();
} else if (isNestedWithDtmArray(src.get())) {
return toFloat32Array(src.get('next')); // TODO: may not be ideal
}
} else if (src.meta.type === 'dtm.model') {
return new Float32Array(src.get());
}
} else if (isNumOrFloat32Array(src)) {
if (isFloat32Array(src)) {
return src;
} else {
// var typedArray = new Float32Array(src.length);
// for (var i = 0, l = src.length; i < l; i++) {
// typedArray[i] = src[i];
// }
// return typedArray;
return new Float32Array(src);
}
} else {
return null;
}
}
// TODO: test
function fromFloat32Array(src) {
return Array.prototype.slice.call(src);
}
function Float32Concat(first, second) {
var firstLen = first.length;
var res = new Float32Array(firstLen + second.length);
res.set(first);
res.set(second, firstLen);
return res;
}
// TODO: other concat types (e.g., string array + typed array)
function concat(first, second) {
if (isFloat32Array(first) || isFloat32Array(second)) {
if (isNumber(first)) {
first = new Float32Array([first]);
}
if (isNumber(second)) {
second = new Float32Array([second]);
}
return Float32Concat(first, second);
} else {
return first.concat(second);
}
}
function flatten(nestedArray) {
var res = [];
for (var i = 0, l = nestedArray.length; i < l; i++) {
if (isArray(nestedArray[i])) {
res = concat(res, flatten(nestedArray[i]));
} else {
res = concat(res, nestedArray[i]);
}